[optimize] visualmap

This commit is contained in:
monitor1394
2022-04-09 21:30:28 +08:00
parent e2b0c935e0
commit be4ed41ca6
9 changed files with 76 additions and 19 deletions

View File

@@ -20,8 +20,8 @@ namespace XCharts.Editor
PropertyField("m_Max");
PropertyField("m_SplitNumber");
PropertyField("m_Dimension");
PropertyField("m_Show");
if (baseProperty.FindPropertyRelative("m_Show").boolValue)
PropertyField("m_ShowUI");
if (baseProperty.FindPropertyRelative("m_ShowUI").boolValue)
{
PropertyField("m_SelectedMode");
PropertyTwoFiled("m_Range");

View File

@@ -270,6 +270,7 @@ namespace XCharts.Example
var visualMap = chart.GetOrAddChartComponent<VisualMap>();
visualMap.show = true;
visualMap.showUI = true;
visualMap.orient = Orient.Vertical;
visualMap.calculable = true;
visualMap.min = 0;

View File

@@ -76,6 +76,7 @@ namespace XCharts.Runtime
}
[SerializeField] private bool m_Show = true;
[SerializeField] private bool m_ShowUI = false;
[SerializeField] private Type m_Type = Type.Continuous;
[SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple;
[SerializeField] private int m_SerieIndex = 0;
@@ -104,11 +105,8 @@ namespace XCharts.Runtime
public VisualMapContext context = new VisualMapContext();
/// <summary>
/// Whether to display components. If set to false, it will not show up, but the data mapping function still exists.
/// |
/// 是否显示组件。如果设置为 false不会显示但是数据映射的功能还存在。
///
/// [default: true]
/// Whether to enable components.
/// |组件是否生效。
/// </summary>
public bool show
{
@@ -116,6 +114,15 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to display components. If set to false, it will not show up, but the data mapping function still exists.
/// |是否显示组件。如果设置为 false不会显示但是数据映射的功能还存在。
/// </summary>
public bool showUI
{
get { return m_ShowUI; }
set { if (PropertyUtil.SetStruct(ref m_ShowUI, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of visualmap component.
/// |组件类型。
/// </summary>

View File

@@ -32,7 +32,7 @@ namespace XCharts.Runtime
public override void DrawBase(VertexHelper vh)
{
var visualMap = component;
if (!visualMap.show) return;
if (!visualMap.show || !visualMap.showUI) return;
switch (visualMap.type)
{
case VisualMap.Type.Continuous:
@@ -319,7 +319,7 @@ namespace XCharts.Runtime
private void OnDragVisualMapStart(VisualMap visualMap)
{
if (!visualMap.show || !visualMap.calculable)
if (!visualMap.show || !visualMap.showUI || !visualMap.calculable)
return;
var inMinRect = visualMap.IsInRangeMinRect(chart.pointerPos, chart.chartRect, chart.theme.visualMap.triangeLen);
@@ -340,7 +340,7 @@ namespace XCharts.Runtime
private void OnDragVisualMap(VisualMap visualMap)
{
if (!visualMap.show || !visualMap.calculable)
if (!visualMap.show || !visualMap.showUI || !visualMap.calculable)
return;
if (!visualMap.context.minDrag && !visualMap.context.maxDrag)
@@ -360,7 +360,7 @@ namespace XCharts.Runtime
private void OnDragVisualMapEnd(VisualMap visualMap)
{
if (!visualMap.show || !visualMap.calculable)
if (!visualMap.show || !visualMap.showUI || !visualMap.calculable)
return;
if (visualMap.context.minDrag || visualMap.context.maxDrag)

View File

@@ -147,6 +147,8 @@ namespace XCharts.Runtime
{
if (visualMap == null)
return false;
if (!visualMap.show)
return false;
if (visualMap.inRange.Count <= 0 && visualMap.pieces.Count <= 0)
return false;

View File

@@ -348,7 +348,7 @@ namespace XCharts.Runtime
serie.animation.InitProgress(serie.context.dataPoints, isY);
VisualMapHelper.AutoSetLineMinMax(visualMap, serie, isY, axis, relativedAxis);
LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, lineWidth, isY);
LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, visualMap, lineWidth, isY);
LineHelper.DrawSerieLineArea(vh, serie, lastSerie, chart.theme, isY, axis, relativedAxis, m_SerieGrid);
LineHelper.DrawSerieLine(vh, chart.theme, serie, visualMap, m_SerieGrid, axis, relativedAxis, lineWidth);

View File

@@ -358,9 +358,9 @@ namespace XCharts.Runtime
UGL.AddVertToVertexHelper(vh, tp, bp, ColorUtil.clearColor32, false);
}
internal static void UpdateSerieDrawPoints(Serie serie, Settings setting, ThemeStyle theme, float lineWidth, bool isY = false)
internal static void UpdateSerieDrawPoints(Serie serie, Settings setting, ThemeStyle theme, VisualMap visualMap,
float lineWidth, bool isY = false)
{
serie.context.drawPoints.Clear();
var last = Vector3.zero;
switch (serie.lineType)
@@ -374,14 +374,54 @@ namespace XCharts.Runtime
UpdateStepLineDrawPoints(serie, setting, theme, isY, lineWidth);
break;
default:
for (int i = 0; i < serie.context.dataPoints.Count; i++)
{
serie.context.drawPoints.Add(new PointInfo(serie.context.dataPoints[i], serie.context.dataIgnores[i]));
}
UpdateNormalLineDrawPoints(serie, setting, visualMap);
break;
}
}
private static void UpdateNormalLineDrawPoints(Serie serie, Settings setting, VisualMap visualMap)
{
var isVisualMapGradient = VisualMapHelper.IsNeedGradient(visualMap);
if (isVisualMapGradient)
{
var dataPoints = serie.context.dataPoints;
if (dataPoints.Count > 1)
{
var sp = dataPoints[0];
for (int i = 1; i < dataPoints.Count; i++)
{
var ep = dataPoints[i];
var ignore = serie.context.dataIgnores[i];
var dir = (ep - sp).normalized;
var dist = Vector3.Distance(sp, ep);
var segment = (int)(dist / setting.lineSegmentDistance);
serie.context.drawPoints.Add(new PointInfo(sp, ignore));
for (int j = 1; j < segment; j++)
{
var np = sp + dir * dist * j / segment;
serie.context.drawPoints.Add(new PointInfo(np, ignore));
}
sp = ep;
if (i == dataPoints.Count - 1)
{
serie.context.drawPoints.Add(new PointInfo(ep, ignore));
}
}
}
else
{
serie.context.drawPoints.Add(new PointInfo(dataPoints[0], serie.context.dataIgnores[0]));
}
}
else
{
for (int i = 0; i < serie.context.dataPoints.Count; i++)
{
serie.context.drawPoints.Add(new PointInfo(serie.context.dataPoints[i], serie.context.dataIgnores[i]));
}
}
}
private static void UpdateSmoothLineDrawPoints(Serie serie, Settings setting, bool isY)
{
var points = serie.context.dataPoints;

View File

@@ -238,7 +238,7 @@ namespace XCharts.Runtime
serie.animation.InitProgress(serie.context.dataPoints, isY);
LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, lineWidth, isY);
LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, null, lineWidth, isY);
LineHelper.DrawSerieLineArea(vh, serie, null, chart.theme, isY, axis, relativedAxis, m_SerieGrid);
LineHelper.DrawSerieLine(vh, chart.theme, serie, null, m_SerieGrid, axis, relativedAxis, lineWidth);

View File

@@ -306,6 +306,13 @@ namespace XUGL
clp = cp - dir2v;
crp = cp + dir2v;
if (Vector3.Cross(dir1, dir2) == Vector3.zero && np != cp)
{
itp = ntp;
ibp = nbp;
return;
}
var ldist = (Vector3.Distance(cp, lp) + 1) * dir1;
var rdist = (Vector3.Distance(cp, np) + 1) * dir2;