internal static void DrawAxisLine(VertexHelper vh, Axis axis, AxisTheme theme, Orient orient, float startX, float startY, float axisLength) { var inverse = axis.IsValue() && axis.inverse; var offset = AxisHelper.GetAxisLineArrowOffset(axis); var lineWidth = axis.axisLine.GetWidth(theme.lineWidth); var lineType = axis.axisLine.GetType(theme.lineType); var lineColor = axis.axisLine.GetColor(theme.lineColor); if (orient == Orient.Horizonal) { var left = new Vector3(startX - lineWidth - (inverse ? offset : 0), startY); var right = new Vector3(startX + axisLength + lineWidth + (!inverse ? offset : 0), startY); ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, left, right, lineColor); } else { var bottom = new Vector3(startX, startY - lineWidth - (inverse ? offset : 0)); var top = new Vector3(startX, startY + axisLength + lineWidth + (!inverse ? offset : 0)); ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, bottom, top, lineColor); } }
protected void DrawAxisSplit(VertexHelper vh, AxisTheme theme, DataZoom dataZoom, Orient orient, float startX, float startY, float axisLength, float splitLength, Axis relativedAxis = null) { Axis axis = component; var lineColor = axis.splitLine.GetColor(theme.splitLineColor); var lineWidth = axis.splitLine.GetWidth(theme.lineWidth); var lineType = axis.splitLine.GetType(theme.splitLineType); var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); if (axis.IsTime()) { size += 1; if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue)) { size += 1; } } var current = orient == Orient.Horizonal ? startX : startY; for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom); if (axis.boundaryGap && axis.axisTick.alignWithLabel) { current -= scaleWidth / 2; } if (axis.splitArea.show && i <= size - 1) { if (orient == Orient.Horizonal) { UGL.DrawQuadrilateral(vh, new Vector2(current, startY), new Vector2(current, startY + splitLength), new Vector2(current + scaleWidth, startY + splitLength), new Vector2(current + scaleWidth, startY), axis.splitArea.GetColor(i, theme)); } else { UGL.DrawQuadrilateral(vh, new Vector2(startX, current), new Vector2(startX + splitLength, current), new Vector2(startX + splitLength, current + scaleWidth), new Vector2(startX, current + scaleWidth), axis.splitArea.GetColor(i, theme)); } } if (axis.splitLine.show) { if (axis.splitLine.NeedShow(i)) { if (orient == Orient.Horizonal) { if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY())) { ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(current, startY), new Vector3(current, startY + splitLength), lineColor); } } else { if (relativedAxis == null || !MathUtil.Approximately(current, GetAxisLineXOrY())) { ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, new Vector3(startX, current), new Vector3(startX + splitLength, current), lineColor); } } } } current += scaleWidth; } }
internal static void DrawAxisTick(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom, Orient orient, float startX, float startY, float axisLength) { var lineWidth = axis.axisLine.GetWidth(theme.lineWidth); var tickLength = axis.axisTick.GetLength(theme.tickLength); if (AxisHelper.NeedShowSplit(axis)) { var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom); var current = orient == Orient.Horizonal ? startX : startY; for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom); if (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel)) { current += scaleWidth; continue; } if (i == size - 1 && !axis.axisTick.showEndTick) { current += scaleWidth; continue; } if (axis.axisTick.show) { if (orient == Orient.Horizonal) { float pX = axis.IsTime() ? (startX + axis.GetDistance(axis.GetLabelValue(i), axisLength)) : current; if (axis.boundaryGap && axis.axisTick.alignWithLabel) { pX -= scaleWidth / 2; } var sY = 0f; var eY = 0f; if ((axis.axisTick.inside && axis.IsBottom()) || (!axis.axisTick.inside && axis.IsTop())) { sY = startY + lineWidth; eY = sY + tickLength; } else { sY = startY - lineWidth; eY = sY - tickLength; } UGL.DrawLine(vh, new Vector3(pX, sY), new Vector3(pX, eY), axis.axisTick.GetWidth(theme.tickWidth), axis.axisTick.GetColor(theme.tickColor)); } else { float pY = axis.IsTime() ? (startY + axis.GetDistance(axis.GetLabelValue(i), axisLength)) : current; if (axis.boundaryGap && axis.axisTick.alignWithLabel) { pY -= scaleWidth / 2; } var sX = 0f; var eX = 0f; if ((axis.axisTick.inside && axis.IsLeft()) || (!axis.axisTick.inside && axis.IsRight())) { sX = startX + lineWidth; eX = sX + tickLength; } else { sX = startX - lineWidth; eX = sX - tickLength; } UGL.DrawLine(vh, new Vector3(sX, pY), new Vector3(eX, pY), axis.axisTick.GetWidth(theme.tickWidth), axis.axisTick.GetColor(theme.tickColor)); } } current += scaleWidth; } } if (axis.show && axis.axisLine.show && axis.axisLine.showArrow) { var lineY = startY + axis.offset; var inverse = axis.IsValue() && axis.inverse; var axisArrow = axis.axisLine.arrow; if (orient == Orient.Horizonal) { if (inverse) { var startPos = new Vector3(startX + axisLength, lineY); var arrowPos = new Vector3(startX, lineY); UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, axisArrow.offset, axisArrow.dent, axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor))); } else { var arrowPosX = startX + axisLength + lineWidth; var startPos = new Vector3(startX, lineY); var arrowPos = new Vector3(arrowPosX, lineY); UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, axisArrow.offset, axisArrow.dent, axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor))); } } else { if (inverse) { var startPos = new Vector3(startX, startY + axisLength); var arrowPos = new Vector3(startX, startY); UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, axisArrow.offset, axisArrow.dent, axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor))); } else { var startPos = new Vector3(startX, startY); var arrowPos = new Vector3(startX, startY + axisLength + lineWidth); UGL.DrawArrow(vh, startPos, arrowPos, axisArrow.width, axisArrow.height, axisArrow.offset, axisArrow.dent, axisArrow.GetColor(axis.axisLine.GetColor(theme.lineColor))); } } } }
internal static Vector3 GetLabelPosition(int i, Orient orient, Axis axis, Axis relativedAxis, AxisTheme theme, float scaleWid, float axisStartX, float axisStartY, float axisLength, float relativedLength) { var inside = axis.axisLabel.inside; var fontSize = axis.axisLabel.textStyle.GetFontSize(theme); var current = axis.offset; if (axis.IsTime() || axis.IsValue()) { scaleWid = axis.context.minMaxRange != 0 ? axis.GetDistance(axis.GetLabelValue(i), axisLength) : 0; } if (orient == Orient.Horizonal) { if (axis.axisLabel.onZero && relativedAxis != null) { axisStartY += relativedAxis.context.offset; } if (axis.IsTop()) { axisStartY += relativedLength; } if ((inside && axis.IsBottom()) || (!inside && axis.IsTop())) { current += axisStartY + axis.axisLabel.distance + fontSize / 2; } else { current += axisStartY - axis.axisLabel.distance - fontSize / 2; } return(new Vector3(axisStartX + scaleWid, current) + axis.axisLabel.offset); } else { if (axis.axisLabel.onZero && relativedAxis != null) { axisStartX += relativedAxis.context.offset; } if (axis.IsRight()) { axisStartX += relativedLength; } if ((inside && axis.IsLeft()) || (!inside && axis.IsRight())) { current += axisStartX + axis.axisLabel.distance; } else { current += axisStartX - axis.axisLabel.distance; } return(new Vector3(current, axisStartY + scaleWid) + axis.axisLabel.offset); } }