mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
优化自定义绘制回调接口
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
## Latest
|
||||
|
||||
* (2021.03.29) Optimized the custom draw callback API
|
||||
* (2021.03.25) Added `Ganttchart`
|
||||
* (2021.03.22) Added `Theme` `Unbind` button to unbind theme when copying chart #118
|
||||
* (2021.03.18) Fixed an issue where the check box after `Foldout` in `Inspector` could not be checked
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
## Latest
|
||||
|
||||
* (2021.03.29) 优化自定义绘制回调接口,增加`onCustomDrawBeforeSerie`、`onCustomDrawAfterSerie`和`onCustomDrawTop`
|
||||
* (2021.03.25) 增加`GanttChart`甘特图
|
||||
* (2021.03.22) 增加`Theme`的`Unbind`按钮用于解绑复制图表时的主题 #118
|
||||
* (2021.03.18) 修复`Inspector`下`Foldout`后的勾选框无法选中的问题
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
* `BaseChart.chartWidth`:图表的宽。
|
||||
* `BaseChart.chartHeight`:图表的高。
|
||||
* `BaseChart.forceOpenRaycastTarget`:强制开启鼠标事件检测。一般不用手动设置,内部会自动判断是否需要检测。
|
||||
* `BaseChart.onCustomDraw`:自定义绘制回调。
|
||||
* `BaseChart.onCustomDraw`:自定义底部绘制回调。在绘制Serie前调用。
|
||||
* `BaseChart.onCustomDrawBeforeSerie`:自定义Serie绘制回调。在每个Serie绘制完前调用。
|
||||
* `BaseChart.onCustomDrawAfterSerie`:自定义Serie绘制回调。在每个Serie绘制完后调用。
|
||||
* `BaseChart.onCustomDrawTop`:自定义顶部绘制回调。在绘制Tooltip前调用。
|
||||
* `BaseChart.onPointerClick`:鼠标点击回调。
|
||||
* `BaseChart.onPointerDown`:鼠标按下回调。
|
||||
* `BaseChart.onPointerUp`:鼠标弹起回调。
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
* `BaseChart.chartWidth`:图表的宽。
|
||||
* `BaseChart.chartHeight`:图表的高。
|
||||
* `BaseChart.forceOpenRaycastTarget`:强制开启鼠标事件检测。一般不用手动设置,内部会自动判断是否需要检测。
|
||||
* `BaseChart.onCustomDraw`:自定义绘制回调。
|
||||
* `BaseChart.onCustomDraw`:自定义底部绘制回调。在绘制Serie前调用。
|
||||
* `BaseChart.onCustomDrawBeforeSerie`:自定义Serie绘制回调。在每个Serie绘制完前调用。
|
||||
* `BaseChart.onCustomDrawAfterSerie`:自定义Serie绘制回调。在每个Serie绘制完后调用。
|
||||
* `BaseChart.onCustomDrawTop`:自定义顶部绘制回调。在绘制Tooltip前调用。
|
||||
* `BaseChart.onPointerClick`:鼠标点击回调。
|
||||
* `BaseChart.onPointerDown`:鼠标按下回调。
|
||||
* `BaseChart.onPointerUp`:鼠标弹起回调。
|
||||
|
||||
@@ -24,7 +24,13 @@ namespace XCharts.Examples
|
||||
|
||||
chart.onCustomDraw = delegate (VertexHelper vh)
|
||||
{
|
||||
var dataPoints = chart.series.list[0].dataPoints;
|
||||
};
|
||||
|
||||
// or
|
||||
chart.onCustomDrawSerie = delegate (VertexHelper vh, Serie serie)
|
||||
{
|
||||
if (serie.index != 0) return;
|
||||
var dataPoints = serie.dataPoints;
|
||||
if (dataPoints.Count > 0)
|
||||
{
|
||||
var pos = dataPoints[3];
|
||||
@@ -35,6 +41,11 @@ namespace XCharts.Examples
|
||||
UGL.DrawCricle(vh, pos, 5, Color.blue);
|
||||
}
|
||||
};
|
||||
|
||||
// or
|
||||
chart.onCustomDrawTop = delegate (VertexHelper vh)
|
||||
{
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,11 +98,22 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
||||
public Rect chartRect { get { return m_ChartRect; } }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义绘制回调。
|
||||
/// 自定义绘制回调。在绘制Serie前调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper> onCustomDraw { set { m_OnCustomDrawCallback = value; } }
|
||||
public Action<VertexHelper> onCustomDraw { set { m_OnCustomDrawBaseCallback = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Serie绘制回调。在每个Serie绘制完前调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper, Serie> onCustomDrawBeforeSerie { set { m_OnCustomDrawSerieBeforeCallback = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Serie绘制回调。在每个Serie绘制完后调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper, Serie> onCustomDrawAfterSerie { set { m_OnCustomDrawSerieAfterCallback = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Top绘制回调。在绘制Tooltip前调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper> onCustomDrawTop { set { m_OnCustomDrawTopCallback = value; } }
|
||||
/// <summary>
|
||||
/// the callback function of click pie area.
|
||||
/// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex
|
||||
|
||||
@@ -69,7 +69,10 @@ namespace XCharts
|
||||
protected Vector2 m_ChartPivot;
|
||||
protected Vector2 m_ChartSizeDelta;
|
||||
protected Rect m_ChartRect = new Rect(0, 0, 0, 0);
|
||||
protected Action<VertexHelper> m_OnCustomDrawCallback;
|
||||
protected Action<VertexHelper> m_OnCustomDrawBaseCallback;
|
||||
protected Action<VertexHelper> m_OnCustomDrawTopCallback;
|
||||
protected Action<VertexHelper, Serie> m_OnCustomDrawSerieBeforeCallback;
|
||||
protected Action<VertexHelper, Serie> m_OnCustomDrawSerieAfterCallback;
|
||||
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
|
||||
|
||||
internal bool m_RefreshLabel = false;
|
||||
@@ -818,6 +821,10 @@ namespace XCharts
|
||||
DrawPainterBase(vh);
|
||||
DrawLegend(vh);
|
||||
foreach (var drawSerie in m_DrawSeries) drawSerie.DrawBase(vh);
|
||||
if (m_OnCustomDrawBaseCallback != null)
|
||||
{
|
||||
m_OnCustomDrawBaseCallback(vh);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDrawPainterSerie(VertexHelper vh, Painter painter)
|
||||
@@ -830,7 +837,15 @@ namespace XCharts
|
||||
for (int i = painter.index * rate; i < (painter.index + 1) * rate && i < maxSeries; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
if (m_OnCustomDrawSerieBeforeCallback != null)
|
||||
{
|
||||
m_OnCustomDrawSerieBeforeCallback.Invoke(vh, serie);
|
||||
}
|
||||
DrawPainterSerie(vh, serie);
|
||||
if (m_OnCustomDrawSerieAfterCallback != null)
|
||||
{
|
||||
m_OnCustomDrawSerieAfterCallback(vh, serie);
|
||||
}
|
||||
}
|
||||
m_RefreshLabel = true;
|
||||
}
|
||||
@@ -838,11 +853,11 @@ namespace XCharts
|
||||
protected virtual void OnDrawPainterTop(VertexHelper vh, Painter painter)
|
||||
{
|
||||
vh.Clear();
|
||||
if (m_OnCustomDrawCallback != null)
|
||||
{
|
||||
m_OnCustomDrawCallback(vh);
|
||||
}
|
||||
DrawPainterTop(vh);
|
||||
if (m_OnCustomDrawTopCallback != null)
|
||||
{
|
||||
m_OnCustomDrawTopCallback(vh);
|
||||
}
|
||||
DrawTooltip(vh);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user