mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 19:50:10 +00:00
增加ItemStyle的backgroundGap可设置数据项背景间隙
This commit is contained in:
@@ -21,6 +21,7 @@ namespace XCharts.Editor
|
|||||||
PropertyField(prop, "m_MarkColor");
|
PropertyField(prop, "m_MarkColor");
|
||||||
PropertyField(prop, "m_BackgroundColor");
|
PropertyField(prop, "m_BackgroundColor");
|
||||||
PropertyField(prop, "m_BackgroundWidth");
|
PropertyField(prop, "m_BackgroundWidth");
|
||||||
|
PropertyField(prop, "m_BackgroundGap");
|
||||||
PropertyField(prop, "m_CenterColor");
|
PropertyField(prop, "m_CenterColor");
|
||||||
PropertyField(prop, "m_CenterGap");
|
PropertyField(prop, "m_CenterGap");
|
||||||
PropertyField(prop, "m_BorderWidth");
|
PropertyField(prop, "m_BorderWidth");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField][Since("v3.6.0")] private Color32 m_MarkColor;
|
[SerializeField][Since("v3.6.0")] private Color32 m_MarkColor;
|
||||||
[SerializeField] private Color32 m_BackgroundColor;
|
[SerializeField] private Color32 m_BackgroundColor;
|
||||||
[SerializeField] private float m_BackgroundWidth;
|
[SerializeField] private float m_BackgroundWidth;
|
||||||
|
[SerializeField][Since("v3.15.0")] private float m_BackgroundGap;
|
||||||
[SerializeField] private Color32 m_CenterColor;
|
[SerializeField] private Color32 m_CenterColor;
|
||||||
[SerializeField] private float m_CenterGap;
|
[SerializeField] private float m_CenterGap;
|
||||||
[SerializeField] private float m_BorderWidth = 0;
|
[SerializeField] private float m_BorderWidth = 0;
|
||||||
@@ -129,6 +130,15 @@ namespace XCharts.Runtime
|
|||||||
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// the gap between background and data item.
|
||||||
|
/// ||数据项背景间隙。
|
||||||
|
/// </summary>
|
||||||
|
public float backgroundGap
|
||||||
|
{
|
||||||
|
get { return m_BackgroundGap; }
|
||||||
|
set { if (PropertyUtil.SetStruct(ref m_BackgroundGap, value)) SetVerticesDirty(); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 中心区域颜色。
|
/// 中心区域颜色。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color32 centerColor
|
public Color32 centerColor
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ namespace XCharts.Runtime
|
|||||||
var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap;
|
var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap;
|
||||||
var borderGapAndWidth = borderWidth + borderGap;
|
var borderGapAndWidth = borderWidth + borderGap;
|
||||||
var backgroundColor = itemStyle.backgroundColor;
|
var backgroundColor = itemStyle.backgroundColor;
|
||||||
|
var backgroundGap = itemStyle.backgroundGap;
|
||||||
|
|
||||||
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting, interactDuration))
|
if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting, interactDuration))
|
||||||
{
|
{
|
||||||
@@ -237,16 +238,17 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
var pX = 0f;
|
var pX = 0f;
|
||||||
var pY = 0f;
|
var pY = 0f;
|
||||||
UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, relativedCategoryWidth, barWidth, isStack, value, ref pX, ref pY);
|
UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, relativedCategoryWidth,
|
||||||
|
barWidth, isStack, value, backgroundGap, ref pX, ref pY);
|
||||||
var barHig = 0f;
|
var barHig = 0f;
|
||||||
if (isPercentStack)
|
if (isPercentStack)
|
||||||
{
|
{
|
||||||
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i, m_SerieGrid.index);
|
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i, m_SerieGrid.index);
|
||||||
barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0;
|
barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * (relativedAxisLength - 2 * backgroundGap)) : 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, relativedCategoryWidth, relativedValue);
|
barHig = AxisHelper.GetAxisValueLength(m_SerieGrid, relativedAxis, relativedCategoryWidth, relativedValue, 2 * backgroundGap);
|
||||||
}
|
}
|
||||||
float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
|
float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig);
|
||||||
Vector3 plb, plt, prt, prb, top;
|
Vector3 plb, plt, prt, prb, top;
|
||||||
@@ -257,8 +259,8 @@ namespace XCharts.Runtime
|
|||||||
serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth,
|
serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth,
|
||||||
prt.x - borderGapAndWidth, prt.y - borderGapAndWidth);
|
prt.x - borderGapAndWidth, prt.y - borderGapAndWidth);
|
||||||
serieData.context.backgroundRect = isY ?
|
serieData.context.backgroundRect = isY ?
|
||||||
Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) :
|
Rect.MinMaxRect(m_SerieGrid.context.x, plb.y - backgroundGap, m_SerieGrid.context.x + relativedAxisLength, prt.y + backgroundGap) :
|
||||||
Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);
|
Rect.MinMaxRect(plb.x - backgroundGap, m_SerieGrid.context.y, prb.x + backgroundGap, m_SerieGrid.context.y + relativedAxisLength);
|
||||||
|
|
||||||
if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top)))
|
if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top)))
|
||||||
{
|
{
|
||||||
@@ -303,7 +305,7 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
private void UpdateXYPosition(GridCoord grid, bool isY, Axis axis, Axis relativedAxis, int i,
|
private void UpdateXYPosition(GridCoord grid, bool isY, Axis axis, Axis relativedAxis, int i,
|
||||||
float categoryWidth, float relativedCategoryWidth, float barWidth, bool isStack,
|
float categoryWidth, float relativedCategoryWidth, float barWidth, bool isStack,
|
||||||
double value, ref float pX, ref float pY)
|
double value, float backgroundGap, ref float pX, ref float pY)
|
||||||
{
|
{
|
||||||
if (isY)
|
if (isY)
|
||||||
{
|
{
|
||||||
@@ -320,7 +322,7 @@ namespace XCharts.Runtime
|
|||||||
pY = grid.context.y + valueLen - categoryWidth * 0.5f;
|
pY = grid.context.y + valueLen - categoryWidth * 0.5f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, relativedCategoryWidth, 0);
|
pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, relativedCategoryWidth, 0) + backgroundGap;
|
||||||
if (isStack)
|
if (isStack)
|
||||||
{
|
{
|
||||||
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
|
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
|
||||||
@@ -342,7 +344,7 @@ namespace XCharts.Runtime
|
|||||||
pX = grid.context.x + valueLen - categoryWidth * 0.5f;
|
pX = grid.context.x + valueLen - categoryWidth * 0.5f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, relativedCategoryWidth, 0);
|
pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, relativedCategoryWidth, 0) + backgroundGap;
|
||||||
if (isStack)
|
if (isStack)
|
||||||
{
|
{
|
||||||
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
|
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
|
||||||
|
|||||||
Reference in New Issue
Block a user