8 using System.Collections.Generic;
10 using UnityEngine.EventSystems;
56 [SerializeField]
private double m_Min;
57 [SerializeField]
private double m_Max;
58 [SerializeField]
private string m_Label;
59 [SerializeField]
private Color32 m_Color;
64 public double min {
get {
return m_Min; }
set { m_Min = value; } }
68 public double max {
get {
return m_Max; }
set { m_Max = value; } }
72 public string label {
get {
return m_Label; }
set { m_Label = value; } }
76 public Color32
color {
get {
return m_Color; }
set { m_Color = value; } }
78 public bool Contains(
double value,
double minMaxRange)
80 var cmin = System.Math.Abs(m_Min) < 1 ? minMaxRange * m_Min : m_Min;
81 var cmax = System.Math.Abs(m_Max) < 1 ? minMaxRange * m_Max : m_Max;
82 return value >= cmin && value < cmax;
86 [SerializeField]
private bool m_Enable =
false;
87 [SerializeField]
private bool m_Show =
true;
88 [SerializeField]
private Type m_Type =
Type.Continuous;
90 [SerializeField]
private double m_Min = 0;
91 [SerializeField]
private double m_Max = 100;
93 [SerializeField]
private double[] m_Range =
new double[2] { 0, 100 };
94 [SerializeField]
private string[] m_Text =
new string[2] {
"",
"" };
95 [SerializeField]
private float[] m_TextGap =
new float[2] { 10f, 10f };
96 [SerializeField]
private int m_SplitNumber = 5;
97 [SerializeField]
private bool m_Calculable =
false;
98 [SerializeField]
private bool m_Realtime =
true;
99 [SerializeField]
private float m_ItemWidth = 20f;
100 [SerializeField]
private float m_ItemHeight = 140f;
101 [SerializeField]
private float m_ItemGap = 10f;
102 [SerializeField]
private float m_BorderWidth = 0;
103 [SerializeField]
private int m_Dimension = -1;
104 [SerializeField]
private bool m_HoverLink =
true;
105 [SerializeField]
private bool m_AutoMinMax =
true;
106 [SerializeField]
private Orient m_Orient =
Orient.Horizonal;
107 [SerializeField]
private Location m_Location = Location.defaultLeft;
108 [SerializeField]
private List<Color32> m_InRange =
new List<Color32>();
109 [SerializeField]
private List<Color32> m_OutOfRange =
new List<Color32>() { Color.gray };
110 [SerializeField]
private List<Pieces> m_Pieces =
new List<Pieces>();
121 get {
return m_Enable; }
122 set {
if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
133 get {
return m_Show; }
134 set {
if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
142 get {
return m_Type; }
143 set {
if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
151 get {
return m_SelectedMode; }
152 set {
if (PropertyUtil.SetStruct(ref m_SelectedMode, value)) SetVerticesDirty(); }
161 get {
return m_Min; }
162 set {
if (PropertyUtil.SetStruct(ref m_Min, value)) SetVerticesDirty(); }
171 get {
return m_Max; }
172 set { m_Max = (value <
min ?
min + 1 : value); SetVerticesDirty(); }
179 public double[]
range {
get {
return m_Range; } }
184 public string[]
text {
get {
return m_Text; } }
189 public float[]
textGap {
get {
return m_TextGap; } }
199 get {
return m_SplitNumber; }
200 set {
if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetVerticesDirty(); }
209 get {
return m_Calculable; }
210 set {
if (PropertyUtil.SetStruct(ref m_Calculable, value)) SetVerticesDirty(); }
219 get {
return m_Realtime; }
220 set {
if (PropertyUtil.SetStruct(ref m_Realtime, value)) SetVerticesDirty(); }
229 get {
return m_ItemWidth; }
230 set {
if (PropertyUtil.SetStruct(ref m_ItemWidth, value)) SetVerticesDirty(); }
239 get {
return m_ItemHeight; }
240 set {
if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetVerticesDirty(); }
247 get {
return m_ItemGap; }
248 set {
if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetVerticesDirty(); }
257 get {
return m_BorderWidth; }
258 set {
if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
268 get {
return m_Dimension; }
269 set {
if (PropertyUtil.SetStruct(ref m_Dimension, value)) SetVerticesDirty(); }
283 get {
return m_HoverLink; }
284 set {
if (PropertyUtil.SetStruct(ref m_HoverLink, value)) SetVerticesDirty(); }
292 get {
return m_AutoMinMax; }
293 set {
if (PropertyUtil.SetStruct(ref m_AutoMinMax, value)) SetVerticesDirty(); }
302 get {
return m_Orient; }
303 set {
if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
311 get {
return m_Location; }
312 set {
if (PropertyUtil.SetClass(ref m_Location, value)) SetVerticesDirty(); }
320 get {
return m_InRange; }
321 set {
if (value !=
null) { m_InRange = value; SetVerticesDirty(); } }
329 get {
return m_OutOfRange; }
330 set {
if (value !=
null) { m_OutOfRange = value; SetVerticesDirty(); } }
335 public List<Pieces>
pieces
337 get {
return m_Pieces; }
338 set {
if (value !=
null) { m_Pieces = value; SetVerticesDirty(); } }
341 public override bool vertsDirty {
get {
return m_VertsDirty ||
location.
anyDirty; } }
342 public override void ClearVerticesDirty()
344 base.ClearVerticesDirty();
348 public override void ClearComponentDirty()
350 base.ClearComponentDirty();
359 public double runtimeSelectedValue {
get;
set; }
365 public bool runtimeIsVertical {
get {
return orient ==
Orient.Vertical; } }
366 public double rangeMin
370 if (m_Range[0] <
min || m_Range[0] >
max)
return min;
371 else return m_Range[0];
375 if (value >=
min && value <= m_Range[1]) m_Range[0] = value;
379 public double rangeMax
383 if (m_Range[1] >= m_Range[0] && m_Range[1] <
max)
return m_Range[1];
388 if (value >= m_Range[0] && value <=
max) m_Range[1] = value;
392 public int runtimeSplitNumber
397 else return m_InRange.Count;
401 public float runtimeRangeMinHeight {
get {
return (
float)((rangeMin -
min) / (
max -
min) *
itemHeight); } }
402 public float runtimeRangeMaxHeight {
get {
return (
float)((rangeMax -
min) / (
max -
min) *
itemHeight); } }
403 public bool runtimeMinDrag {
get;
internal set; }
404 public bool runtimeMaxDrag {
get;
internal set; }
406 private List<Color32> m_RtInRange =
new List<Color32>();
407 public List<Color32> runtimeInRange
417 if (m_RtInRange.Count != runtimeSplitNumber)
421 var diff1 = total / (m_InRange.Count - 1);
432 if (rtValue > inValue + diff1)
439 m_RtInRange.Add(m_InRange[m_InRange.Count - 1]);
443 var rate = (float)((rtValue - inValue) / diff1);
444 m_RtInRange.Add(Color32.Lerp(m_InRange[inCount], m_InRange[inCount + 1], rate));
453 public Color32 GetColor(
double value)
457 case Type.Continuous:
458 return GetContinuousColor(value);
460 return GetPiecesColor(value);
462 return ColorUtil.clearColor32;
466 private Color32 GetPiecesColor(
double value)
468 foreach (var piece
in m_Pieces)
470 if (piece.Contains(value,
max -
min))
475 if (m_OutOfRange.Count > 0)
return m_OutOfRange[0];
476 else return ChartConst.clearColor32;
479 private Color32 GetContinuousColor(
double value)
481 if (value < m_Min || value > m_Max)
483 if (m_OutOfRange.Count > 0)
return m_OutOfRange[0];
484 else return ChartConst.clearColor32;
487 if (
splitNumber <= 0)
return ChartConst.clearColor32;
488 var index = GetIndex(value);
489 if (m_Type == VisualMap.Type.Piecewise)
491 if (index >= 0 && index < runtimeInRange.Count)
492 return runtimeInRange[index];
493 else return ChartConst.clearColor32;
498 var nowMin = m_Min + index * diff;
499 var rate = (value - nowMin) / diff;
500 if (index ==
splitNumber - 1)
return runtimeInRange[index];
501 else return Color32.Lerp(runtimeInRange[index], runtimeInRange[index + 1], (
float)rate);
505 public int GetIndex(
double value)
509 value = MathUtil.Clamp(value, m_Min, m_Max);
515 if (value <= m_Min + (i + 1) * diff)
524 public bool IsPiecewise()
526 return m_Type == VisualMap.Type.Piecewise;
529 public bool IsInSelectedValue(
double value)
538 public double GetValue(Vector3 pos, Rect chartRect)
540 var centerPos =
new Vector3(chartRect.x, chartRect.y) +
location.
GetPosition(chartRect.width, chartRect.height);
541 var pos1 = centerPos + (runtimeIsVertical ? Vector3.down : Vector3.left) *
itemHeight / 2;
542 var pos2 = centerPos + (runtimeIsVertical ? Vector3.up : Vector3.right) *
itemHeight / 2;
543 if (runtimeIsVertical)
545 if (pos.y < pos1.y)
return min;
546 else if (pos.y > pos2.y)
return max;
547 else return min + (pos.y - pos1.y) / (pos2.y - pos1.y) * (
max -
min);
551 if (pos.x < pos1.x)
return min;
552 else if (pos.x > pos2.x)
return max;
553 else return min + (pos.x - pos1.x) / (pos2.x - pos1.x) * (
max -
min);
557 public bool IsInRect(Vector3 local, Rect chartRect,
float triangleLen = 20)
559 var centerPos =
new Vector3(chartRect.x, chartRect.y) +
location.
GetPosition(chartRect.width, chartRect.height);
561 if (local.x >= centerPos.x -
itemWidth / 2 - diff && local.x <= centerPos.x +
itemWidth / 2 + diff &&
562 local.y >= centerPos.y -
itemHeight / 2 - diff && local.y <= centerPos.y +
itemHeight / 2 + diff)
572 public bool IsInRangeRect(Vector3 local, Rect chartRect)
574 var centerPos =
new Vector3(chartRect.x, chartRect.y) +
location.
GetPosition(chartRect.width, chartRect.height);
577 var pos1 = centerPos + Vector3.down *
itemHeight / 2;
578 return local.x >= centerPos.x -
itemWidth / 2 && local.x <= centerPos.x +
itemWidth / 2 &&
579 local.y >= pos1.y + runtimeRangeMinHeight && local.y <= pos1.y + runtimeRangeMaxHeight;
583 var pos1 = centerPos + Vector3.left *
itemHeight / 2;
584 return local.x >= pos1.x + runtimeRangeMinHeight && local.x <= pos1.x + runtimeRangeMaxHeight &&
589 public bool IsInRangeMinRect(Vector3 local, Rect chartRect,
float triangleLen)
591 var centerPos =
new Vector3(chartRect.x, chartRect.y) +
location.
GetPosition(chartRect.width, chartRect.height);
594 var radius = triangleLen / 2;
595 var pos1 = centerPos + Vector3.down *
itemHeight / 2;
596 var cpos =
new Vector3(pos1.x +
itemWidth / 2 + radius, pos1.y + runtimeRangeMinHeight - radius);
598 return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
599 local.y >= cpos.y - radius && local.y <= cpos.y + radius;
603 var radius = triangleLen / 2;
604 var pos1 = centerPos + Vector3.left *
itemHeight / 2;
605 var cpos =
new Vector3(pos1.x + runtimeRangeMinHeight, pos1.y +
itemWidth / 2 + radius);
606 return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
607 local.y >= cpos.y - radius && local.y <= cpos.y + radius;
611 public bool IsInRangeMaxRect(Vector3 local, Rect chartRect,
float triangleLen)
613 var centerPos =
new Vector3(chartRect.x, chartRect.y) +
location.
GetPosition(chartRect.width, chartRect.height);
616 var radius = triangleLen / 2;
617 var pos1 = centerPos + Vector3.down *
itemHeight / 2;
618 var cpos =
new Vector3(pos1.x +
itemWidth / 2 + radius, pos1.y + runtimeRangeMaxHeight + radius);
620 return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
621 local.y >= cpos.y - radius && local.y <= cpos.y + radius;
625 var radius = triangleLen / 2;
626 var pos1 = centerPos + Vector3.left *
itemHeight / 2;
627 var cpos =
new Vector3(pos1.x + runtimeRangeMaxHeight + radius, pos1.y +
itemWidth / 2 + radius);
628 return local.x >= cpos.x - radius && local.x <= cpos.x + radius &&
629 local.y >= cpos.y - radius && local.y <= cpos.y + radius;
634 internal class VisualMapHandler : IComponentHandler
636 public BaseChart chart;
638 public VisualMapHandler(BaseChart chart)
643 public void Init() { }
644 public void OnBeginDrag(PointerEventData eventData)
646 foreach (var visualMap
in chart.visualMaps)
648 OnDragVisualMapStart(visualMap);
651 public void OnDrag(PointerEventData eventData)
653 foreach (var visualMap
in chart.visualMaps)
655 OnDragVisualMap(visualMap);
659 public void OnEndDrag(PointerEventData eventData)
661 foreach (var visualMap
in chart.visualMaps)
663 OnDragVisualMapEnd(visualMap);
666 public void OnPointerDown(PointerEventData eventData) { }
667 public void OnScroll(PointerEventData eventData) { }
671 foreach (var visualMap
in chart.visualMaps)
673 CheckVisualMap(visualMap);
677 public void DrawBase(VertexHelper vh)
679 foreach (var visualMap
in chart.visualMaps)
681 if (!visualMap.enable || !visualMap.show)
continue;
682 switch (visualMap.type)
684 case VisualMap.Type.Continuous:
685 DrawContinuousVisualMap(vh, visualMap);
687 case VisualMap.Type.Piecewise:
694 public void DrawTop(VertexHelper vh)
698 private void CheckVisualMap(VisualMap visualMap)
700 if (visualMap ==
null || !visualMap.enable || !visualMap.show)
return;
702 if (chart.canvas ==
null)
return;
704 if (!chart.ScreenPointToChartPoint(Input.mousePosition, out local))
706 if (visualMap.runtimeSelectedIndex >= 0)
708 visualMap.runtimeSelectedIndex = -1;
709 chart.RefreshChart();
713 if (local.x < chart.chartX || local.x > chart.chartX + chart.chartWidth ||
714 local.y < chart.chartY || local.y > chart.chartY + chart.chartHeight ||
715 !visualMap.IsInRangeRect(local, chart.chartRect))
717 if (visualMap.runtimeSelectedIndex >= 0)
719 visualMap.runtimeSelectedIndex = -1;
720 chart.RefreshChart();
724 var pos1 = Vector3.zero;
725 var pos2 = Vector3.zero;
726 var halfHig = visualMap.itemHeight / 2;
727 var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight);
728 var selectedIndex = -1;
730 switch (visualMap.orient)
733 pos1 = centerPos + Vector3.left * halfHig;
734 pos2 = centerPos + Vector3.right * halfHig;
735 value = visualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (visualMap.max - visualMap.min);
736 selectedIndex = visualMap.GetIndex(value);
739 pos1 = centerPos + Vector3.down * halfHig;
740 pos2 = centerPos + Vector3.up * halfHig;
741 value = visualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (visualMap.max - visualMap.min);
742 selectedIndex = visualMap.GetIndex(value);
745 visualMap.runtimeSelectedValue = value;
746 visualMap.runtimeSelectedIndex = selectedIndex;
747 chart.RefreshChart();
750 private void DrawContinuousVisualMap(VertexHelper vh, VisualMap visualMap)
752 var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight);
753 var pos1 = Vector3.zero;
754 var pos2 = Vector3.zero;
755 var dir = Vector3.zero;
756 var halfWid = visualMap.itemWidth / 2;
757 var halfHig = visualMap.itemHeight / 2;
760 var splitNum = visualMap.runtimeInRange.Count;
761 var splitWid = visualMap.itemHeight / (splitNum - 1);
762 var isVertical =
false;
763 var colors = visualMap.runtimeInRange;
764 var triangeLen = chart.theme.visualMap.triangeLen;
765 switch (visualMap.orient)
768 pos1 = centerPos + Vector3.left * halfHig;
769 pos2 = centerPos + Vector3.right * halfHig;
771 xRadius = splitWid / 2;
774 if (visualMap.calculable)
776 var p0 = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight;
777 var p1 = p0 + Vector3.up * halfWid;
778 var p2 = p0 + Vector3.up * (halfWid + triangeLen);
779 var p3 = p2 + Vector3.left * triangeLen;
780 var color = visualMap.GetColor(visualMap.rangeMin);
781 UGL.DrawTriangle(vh, p1, p2, p3, color);
782 p0 = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight;
783 p1 = p0 + Vector3.up * halfWid;
784 p2 = p0 + Vector3.up * (halfWid + triangeLen);
785 p3 = p2 + Vector3.right * triangeLen;
786 color = visualMap.GetColor(visualMap.rangeMax);
787 UGL.DrawTriangle(vh, p1, p2, p3, color);
791 pos1 = centerPos + Vector3.down * halfHig;
792 pos2 = centerPos + Vector3.up * halfHig;
795 yRadius = splitWid / 2;
797 if (visualMap.calculable)
799 var p0 = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight;
800 var p1 = p0 + Vector3.right * halfWid;
801 var p2 = p0 + Vector3.right * (halfWid + triangeLen);
802 var p3 = p2 + Vector3.down * triangeLen;
803 var color = visualMap.GetColor(visualMap.rangeMin);
804 UGL.DrawTriangle(vh, p1, p2, p3, color);
805 p0 = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight;
806 p1 = p0 + Vector3.right * halfWid;
807 p2 = p0 + Vector3.right * (halfWid + triangeLen);
808 p3 = p2 + Vector3.up * triangeLen;
809 color = visualMap.GetColor(visualMap.rangeMax);
810 UGL.DrawTriangle(vh, p1, p2, p3, color);
814 if (visualMap.calculable && (visualMap.rangeMin > visualMap.min
815 || visualMap.rangeMax < visualMap.max))
817 var rangeMin = visualMap.rangeMin;
818 var rangeMax = visualMap.rangeMax;
819 var diff = (visualMap.max - visualMap.min) / (splitNum - 1);
820 for (
int i = 1; i < splitNum; i++)
822 var splitMin = visualMap.min + (i - 1) * diff;
823 var splitMax = splitMin + diff;
824 if (rangeMin > splitMax || rangeMax < splitMin)
828 else if (rangeMin <= splitMin && rangeMax >= splitMax)
830 var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
831 var startColor = colors[i - 1];
832 var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
833 UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
835 else if (rangeMin > splitMin && rangeMax >= splitMax)
837 var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
838 var splitMaxPos = pos1 + dir * i * splitWid;
839 var splitPos = p0 + (splitMaxPos - p0) / 2;
840 var startColor = visualMap.GetColor(visualMap.rangeMin);
841 var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
842 var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2;
843 if (visualMap.orient ==
Orient.Vertical)
844 UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
846 UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
848 else if (rangeMax < splitMax && rangeMin <= splitMin)
850 var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
851 var splitMinPos = pos1 + dir * (i - 1) * splitWid;
852 var splitPos = splitMinPos + (p0 - splitMinPos) / 2;
853 var startColor = colors[i - 1];
854 var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax);
855 var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2;
856 if (visualMap.orient ==
Orient.Vertical)
857 UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
859 UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
863 var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
864 var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
865 var splitPos = (p0 + p1) / 2;
866 var startColor = visualMap.GetColor(visualMap.rangeMin);
867 var toColor = visualMap.GetColor(visualMap.rangeMax);
868 var yRadius1 = Vector3.Distance(p0, p1) / 2;
869 if (visualMap.orient ==
Orient.Vertical)
870 UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
872 UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
878 for (
int i = 1; i < splitNum; i++)
880 var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
881 var startColor = colors[i - 1];
882 var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
883 UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
887 if (visualMap.rangeMin > visualMap.min)
889 var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
890 UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor);
892 if (visualMap.rangeMax < visualMap.max)
894 var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
895 UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor);
898 if (visualMap.hoverLink)
900 if (visualMap.runtimeSelectedIndex >= 0)
902 var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
903 var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
904 var pointerPos = chart.pointerPos;
905 if (visualMap.orient ==
Orient.Vertical)
907 var p2 =
new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
908 var p3 =
new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
909 var p4 =
new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
910 UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]);
914 var p2 =
new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
915 var p3 =
new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
916 var p4 =
new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
917 UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]);
922 private void DrawPiecewiseVisualMap(VertexHelper vh, VisualMap visualMap)
924 var centerPos = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight);
925 var pos1 = Vector3.zero;
926 var pos2 = Vector3.zero;
927 var dir = Vector3.zero;
928 var halfWid = visualMap.itemWidth / 2;
929 var halfHig = visualMap.itemHeight / 2;
930 var splitNum = visualMap.runtimeInRange.Count;
931 var colors = visualMap.runtimeInRange;
932 switch (visualMap.orient)
935 for (
int i = 0; i < visualMap.pieces.Count; i++)
937 var piece = visualMap.pieces[i];
942 var each = visualMap.itemHeight + visualMap.itemGap;
943 for (
int i = 0; i < visualMap.pieces.Count; i++)
945 var piece = visualMap.pieces[i];
946 var pos =
new Vector3(centerPos.x, centerPos.y - each * i);
947 UGL.DrawRectangle(vh, pos, halfWid, halfHig, piece.color);
953 protected void OnDragVisualMapStart(VisualMap visualMap)
955 if (!visualMap.enable || !visualMap.show || !visualMap.calculable)
return;
956 var inMinRect = visualMap.IsInRangeMinRect(chart.pointerPos, chart.chartRect, chart.theme.visualMap.triangeLen);
957 var inMaxRect = visualMap.IsInRangeMaxRect(chart.pointerPos, chart.chartRect, chart.theme.visualMap.triangeLen);
958 if (inMinRect || inMaxRect)
962 visualMap.runtimeMinDrag =
true;
966 visualMap.runtimeMaxDrag =
true;
971 protected void OnDragVisualMap(VisualMap visualMap)
973 if (!visualMap.enable || !visualMap.show || !visualMap.calculable)
return;
974 if (!visualMap.runtimeMinDrag && !visualMap.runtimeMaxDrag)
return;
976 var value = visualMap.GetValue(chart.pointerPos, chart.chartRect);
977 if (visualMap.runtimeMinDrag)
979 visualMap.rangeMin = value;
983 visualMap.rangeMax = value;
985 chart.RefreshChart();
988 protected void OnDragVisualMapEnd(VisualMap visualMap)
990 if (!visualMap.enable || !visualMap.show || !visualMap.calculable)
return;
991 if (visualMap.runtimeMinDrag || visualMap.runtimeMaxDrag)
993 chart.RefreshChart();
994 visualMap.runtimeMinDrag =
false;
995 visualMap.runtimeMaxDrag =
false;