public static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor) { float value = 0; var min = 0f; var max = 0f; if (visualMap.dimension == 0) { min = axis.runtimeMinValue; max = axis.runtimeMaxValue; var grid = chart.GetAxisGridOrDefault(axis); if (axis.IsCategory() && axis.boundaryGap) { float startX = grid.runtimeX + axis.runtimeScaleWidth / 2; value = (int)(min + (pos.x - startX) / (grid.runtimeWidth - axis.runtimeScaleWidth) * (max - min)); } else { value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); } } else { Axis yAxis; if (axis is YAxis) { yAxis = chart.xAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } else { yAxis = chart.yAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } var grid = chart.GetAxisGridOrDefault(axis); if (yAxis.IsCategory() && yAxis.boundaryGap) { float startY = grid.runtimeY + yAxis.runtimeScaleWidth / 2; value = (int)(min + (pos.y - startY) / (grid.runtimeHeight - yAxis.runtimeScaleWidth) * (max - min)); } else { value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min); } } var color = visualMap.GetColor(value); if (ChartHelper.IsClearColor(color)) { return(defaultColor); } else { return(color); } }
internal static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor) { float value = 0; switch (visualMap.direction) { case VisualMap.Direction.Default: case VisualMap.Direction.X: var min = axis.runtimeMinValue; var max = axis.runtimeMaxValue; var grid = chart.GetAxisGridOrDefault(axis); value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min); break; case VisualMap.Direction.Y: if (axis is YAxis) { var yAxis = chart.xAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } else { var yAxis = chart.yAxes[axis.index]; min = yAxis.runtimeMinValue; max = yAxis.runtimeMaxValue; } grid = chart.GetAxisGridOrDefault(axis); value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min); break; } var color = visualMap.GetColor(value); if (ChartHelper.IsClearColor(color)) { return(defaultColor); } else { return(color); } }
public static void GetLineGradientColor(VisualMap visualMap, float xValue, float yValue, out Color32 startColor, out Color32 toColor) { startColor = ChartConst.clearColor32; toColor = ChartConst.clearColor32; if (visualMap.dimension == 0) { startColor = visualMap.IsPiecewise() ? visualMap.GetColor(xValue) : visualMap.GetColor(xValue - 1); toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(xValue); } else { startColor = visualMap.IsPiecewise() ? visualMap.GetColor(yValue) : visualMap.GetColor(yValue - 1); toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(yValue); } }
public static void GetLineGradientColor(VisualMap visualMap, float xValue, float yValue, out Color32 startColor, out Color32 toColor) { startColor = ChartConst.clearColor32; toColor = ChartConst.clearColor32; switch (visualMap.direction) { case VisualMap.Direction.Default: case VisualMap.Direction.X: startColor = visualMap.IsPiecewise() ? visualMap.GetColor(xValue) : visualMap.GetColor(xValue - 1); toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(xValue); break; case VisualMap.Direction.Y: startColor = visualMap.IsPiecewise() ? visualMap.GetColor(yValue) : visualMap.GetColor(yValue - 1); toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(yValue); break; } }
private void DrawContinuousVisualMap(VertexHelper vh, VisualMap visualMap) { var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight); var pos1 = Vector3.zero; var pos2 = Vector3.zero; var dir = Vector3.zero; var halfWid = visualMap.itemWidth / 2; var halfHig = visualMap.itemHeight / 2; var xRadius = 0f; var yRadius = 0f; var splitNum = visualMap.runtimeInRange.Count; var splitWid = visualMap.itemHeight / (splitNum - 1); var isVertical = false; var colors = visualMap.runtimeInRange; var triangeLen = chart.theme.visualMap.triangeLen; switch (visualMap.orient) { case Orient.Horizonal: pos1 = centerPos + Vector3.left * halfHig; pos2 = centerPos + Vector3.right * halfHig; dir = Vector3.right; xRadius = splitWid / 2; yRadius = halfWid; isVertical = false; if (visualMap.calculable) { var p0 = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.up * halfWid; var p2 = p0 + Vector3.up * (halfWid + triangeLen); var p3 = p2 + Vector3.left * triangeLen; var color = visualMap.GetColor(visualMap.rangeMin); UGL.DrawTriangle(vh, p1, p2, p3, color); p0 = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.up * halfWid; p2 = p0 + Vector3.up * (halfWid + triangeLen); p3 = p2 + Vector3.right * triangeLen; color = visualMap.GetColor(visualMap.rangeMax); UGL.DrawTriangle(vh, p1, p2, p3, color); } break; case Orient.Vertical: pos1 = centerPos + Vector3.down * halfHig; pos2 = centerPos + Vector3.up * halfHig; dir = Vector3.up; xRadius = halfWid; yRadius = splitWid / 2; isVertical = true; if (visualMap.calculable) { var p0 = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight; var p1 = p0 + Vector3.right * halfWid; var p2 = p0 + Vector3.right * (halfWid + triangeLen); var p3 = p2 + Vector3.down * triangeLen; var color = visualMap.GetColor(visualMap.rangeMin); UGL.DrawTriangle(vh, p1, p2, p3, color); p0 = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight; p1 = p0 + Vector3.right * halfWid; p2 = p0 + Vector3.right * (halfWid + triangeLen); p3 = p2 + Vector3.up * triangeLen; color = visualMap.GetColor(visualMap.rangeMax); UGL.DrawTriangle(vh, p1, p2, p3, color); } break; } if (visualMap.calculable && (visualMap.rangeMin > visualMap.min || visualMap.rangeMax < visualMap.max)) { var rangeMin = visualMap.rangeMin; var rangeMax = visualMap.rangeMax; var diff = (visualMap.max - visualMap.min) / (splitNum - 1); for (int i = 1; i < splitNum; i++) { var splitMin = visualMap.min + (i - 1) * diff; var splitMax = splitMin + diff; if (rangeMin > splitMax || rangeMax < splitMin) { continue; } else if (rangeMin <= splitMin && rangeMax >= splitMax) { var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid; var startColor = colors[i - 1]; var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } else if (rangeMin > splitMin && rangeMax >= splitMax) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var splitMaxPos = pos1 + dir * i * splitWid; var splitPos = p0 + (splitMaxPos - p0) / 2; var startColor = visualMap.GetColor(visualMap.rangeMin); var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } else if (rangeMax < splitMax && rangeMin <= splitMin) { var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitMinPos = pos1 + dir * (i - 1) * splitWid; var splitPos = splitMinPos + (p0 - splitMinPos) / 2; var startColor = colors[i - 1]; var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } else { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var splitPos = (p0 + p1) / 2; var startColor = visualMap.GetColor(visualMap.rangeMin); var toColor = visualMap.GetColor(visualMap.rangeMax); var yRadius1 = Vector3.Distance(p0, p1) / 2; if (visualMap.orient == Orient.Vertical) { UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical); } else { UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical); } } } } else { for (int i = 1; i < splitNum; i++) { var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid; var startColor = colors[i - 1]; var toColor = visualMap.IsPiecewise() ? startColor : colors[i]; UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical); } } if (visualMap.rangeMin > visualMap.min) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor); } if (visualMap.rangeMax < visualMap.max) { var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor); } if (visualMap.hoverLink) { if (visualMap.runtimeSelectedIndex >= 0) { var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight; var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight; var pointerPos = chart.pointerPos; if (visualMap.orient == Orient.Vertical) { var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y)); var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y)); var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y); UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]); } else { var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid); var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2); UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]); } } } }