mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 12:08:46 +00:00
增加LabelStyle的showCondition,showFilter,showThreshold可控制label显示和隐藏
This commit is contained in:
@@ -546,6 +546,7 @@ namespace XCharts.Runtime
|
||||
currLabel, color, chart);
|
||||
var offset = GetSerieDataLabelOffset(serieData, currLabel);
|
||||
var active = currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value);
|
||||
if (active) active = CheckLabelVisible(currLabel, serieData.index, value, i);
|
||||
if (active)
|
||||
{
|
||||
anyLabelActive = true;
|
||||
@@ -577,10 +578,11 @@ namespace XCharts.Runtime
|
||||
currLabel, color, chart);
|
||||
var labelPos = UpdateLabelPosition(serieData, currLabel);
|
||||
var active = currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value);
|
||||
if (active && currLabel.minGap > 0 && lastActiveLabelSerieData != null)
|
||||
if (active) active = CheckLabelVisible(currLabel, serieData.index, value, defaultDimension);
|
||||
if (active && currLabel.showMinGap > 0 && lastActiveLabelSerieData != null)
|
||||
{
|
||||
var dist = Mathf.Abs(labelPos.x - lastActiveLabelPos.x);
|
||||
if (dist < currLabel.minGap)
|
||||
if (dist < currLabel.showMinGap)
|
||||
{
|
||||
var currValue = serieData.GetData(1);
|
||||
if (Math.Abs(currValue) >= Math.Abs(lastActiveLabelValue))
|
||||
@@ -641,6 +643,66 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckLabelVisible(LabelStyle label, int dataIndex, double value, int dimension)
|
||||
{
|
||||
// showCondition: 基于阈值的条件检查(AND showFilter)
|
||||
bool conditionResult;
|
||||
switch (label.showCondition)
|
||||
{
|
||||
case LabelStyle.ShowCondition.GreaterThan:
|
||||
conditionResult = value > label.showThreshold;
|
||||
break;
|
||||
case LabelStyle.ShowCondition.LessThan:
|
||||
conditionResult = value < label.showThreshold;
|
||||
break;
|
||||
default: // Always
|
||||
conditionResult = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!conditionResult)
|
||||
return false;
|
||||
|
||||
// showFilter: 基于数据形态的过滤检查
|
||||
switch (label.showFilter)
|
||||
{
|
||||
case LabelStyle.ShowFilter.Peak:
|
||||
{
|
||||
bool isPeak = true;
|
||||
bool hasNeighbor = false;
|
||||
if (dataIndex > 0)
|
||||
{
|
||||
hasNeighbor = true;
|
||||
isPeak &= value > serie.data[dataIndex - 1].GetData(dimension);
|
||||
}
|
||||
if (dataIndex < serie.dataCount - 1)
|
||||
{
|
||||
hasNeighbor = true;
|
||||
isPeak &= value > serie.data[dataIndex + 1].GetData(dimension);
|
||||
}
|
||||
return isPeak && hasNeighbor;
|
||||
}
|
||||
case LabelStyle.ShowFilter.Valley:
|
||||
{
|
||||
bool isValley = true;
|
||||
bool hasNeighbor = false;
|
||||
if (dataIndex > 0)
|
||||
{
|
||||
hasNeighbor = true;
|
||||
isValley &= value < serie.data[dataIndex - 1].GetData(dimension);
|
||||
}
|
||||
if (dataIndex < serie.dataCount - 1)
|
||||
{
|
||||
hasNeighbor = true;
|
||||
isValley &= value < serie.data[dataIndex + 1].GetData(dimension);
|
||||
}
|
||||
return isValley && hasNeighbor;
|
||||
}
|
||||
default: // All
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RefreshEndLabelInternal()
|
||||
{
|
||||
if (m_EndLabel == null)
|
||||
|
||||
Reference in New Issue
Block a user