养成基本完毕,新UI,修bug,装备初步,
This commit is contained in:
@@ -153,8 +153,7 @@ namespace EasyChart
|
||||
|
||||
if (_tooltip != null)
|
||||
{
|
||||
_tooltip.userData = this;
|
||||
ChartTextStyleApplier.ApplyLabel(_tooltip, this, ChartTextRole.Tooltip);
|
||||
ChartTooltipModule.ApplyTooltipStyle(_tooltip, this);
|
||||
}
|
||||
|
||||
ScheduleLayoutRefresh();
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace EasyChart
|
||||
{
|
||||
public Vector2 centerOffset = Vector2.zero;
|
||||
public float padding = 10f;
|
||||
public float labelRadialOffset = 0f;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace EasyChart
|
||||
public sealed class ChartTheme : ScriptableObject
|
||||
{
|
||||
public Object primaryFont;
|
||||
public Object tooltipFont;
|
||||
public Object monoFont;
|
||||
public float fontScale = 1f;
|
||||
|
||||
@@ -31,6 +32,13 @@ namespace EasyChart
|
||||
[Padding4] public Vector4 panelPadding = Vector4.zero;
|
||||
public float panelRadius = 0f;
|
||||
|
||||
public Color tooltipTextColor = Color.white;
|
||||
public Color tooltipBackgroundColor = new Color(0f, 0f, 0f, 0.8f);
|
||||
public Color tooltipBorderColor = new Color(0f, 0f, 0f, 0f);
|
||||
public float tooltipBorderWidth = 0f;
|
||||
[Padding4] public Vector4 tooltipPadding = new Vector4(8f, 8f, 4f, 4f);
|
||||
public float tooltipCornerRadius = 4f;
|
||||
|
||||
public Color plotBackgroundColor = new Color(0f, 0f, 0f, 0f);
|
||||
public Color plotBorderColor = new Color(0f, 0f, 0f, 0f);
|
||||
public float plotBorderWidth = 0f;
|
||||
|
||||
@@ -94,13 +94,13 @@ namespace EasyChart
|
||||
var state = label.userData as AppliedState;
|
||||
|
||||
int themeId = theme != null ? theme.GetInstanceID() : 0;
|
||||
UnityEngine.Object fontObj = theme != null ? theme.primaryFont : null;
|
||||
UnityEngine.Object fontObj = ResolveRoleFontObject(theme, role);
|
||||
int fontId = fontObj != null ? fontObj.GetInstanceID() : 0;
|
||||
|
||||
float scale = theme != null ? theme.fontScale : 1f;
|
||||
float roleSizeOverride = ResolveRoleFontSizeOverride(theme, role);
|
||||
float appliedRoleSizeOverride = roleSizeOverride;
|
||||
if (roleSizeOverride >= 0f && HasInlineFontSize(label))
|
||||
if (role != ChartTextRole.Tooltip && roleSizeOverride >= 0f && HasInlineFontSize(label))
|
||||
{
|
||||
appliedRoleSizeOverride = -1f;
|
||||
}
|
||||
@@ -225,6 +225,18 @@ namespace EasyChart
|
||||
}
|
||||
}
|
||||
|
||||
private static UnityEngine.Object ResolveRoleFontObject(ChartTheme theme, ChartTextRole role)
|
||||
{
|
||||
if (theme == null) return null;
|
||||
|
||||
if (role == ChartTextRole.Tooltip && theme.tooltipFont != null)
|
||||
{
|
||||
return theme.tooltipFont;
|
||||
}
|
||||
|
||||
return theme.primaryFont;
|
||||
}
|
||||
|
||||
private static void ApplyFont(Label label, UnityEngine.Object fontObj)
|
||||
{
|
||||
if (label == null) return;
|
||||
|
||||
@@ -6,6 +6,12 @@ namespace EasyChart
|
||||
{
|
||||
internal sealed class ChartTooltipModule : IChartModule
|
||||
{
|
||||
private static readonly Color DefaultTooltipTextColor = Color.white;
|
||||
private static readonly Color DefaultTooltipBackgroundColor = new Color(0f, 0f, 0f, 0.8f);
|
||||
private static readonly Color DefaultTooltipBorderColor = new Color(0f, 0f, 0f, 0f);
|
||||
private static readonly Vector4 DefaultTooltipPadding = new Vector4(8f, 8f, 4f, 4f);
|
||||
private const float DefaultTooltipCornerRadius = 4f;
|
||||
|
||||
private ChartElement _owner;
|
||||
private VisualElement _cursorLine;
|
||||
private Label _tooltip;
|
||||
@@ -37,25 +43,15 @@ namespace EasyChart
|
||||
{
|
||||
_tooltip = new Label();
|
||||
_tooltip.style.position = Position.Absolute;
|
||||
_tooltip.style.backgroundColor = new Color(0, 0, 0, 0.8f);
|
||||
_tooltip.style.color = Color.white;
|
||||
_tooltip.style.paddingTop = 4;
|
||||
_tooltip.style.paddingBottom = 4;
|
||||
_tooltip.style.paddingLeft = 8;
|
||||
_tooltip.style.paddingRight = 8;
|
||||
_tooltip.style.borderTopLeftRadius = 4;
|
||||
_tooltip.style.borderTopRightRadius = 4;
|
||||
_tooltip.style.borderBottomLeftRadius = 4;
|
||||
_tooltip.style.borderBottomRightRadius = 4;
|
||||
_tooltip.visible = false;
|
||||
_tooltip.userData = _owner;
|
||||
ChartTextStyleApplier.ApplyLabel(_tooltip, _owner, ChartTextRole.Tooltip);
|
||||
ApplyTooltipStyle(_tooltip, _owner);
|
||||
chartArea.Add(_tooltip);
|
||||
}
|
||||
else if (_tooltip.parent == null)
|
||||
{
|
||||
_tooltip.userData = _owner;
|
||||
ChartTextStyleApplier.ApplyLabel(_tooltip, _owner, ChartTextRole.Tooltip);
|
||||
ApplyTooltipStyle(_tooltip, _owner);
|
||||
chartArea.Add(_tooltip);
|
||||
}
|
||||
|
||||
@@ -71,5 +67,46 @@ namespace EasyChart
|
||||
|
||||
_owner = null;
|
||||
}
|
||||
|
||||
internal static void ApplyTooltipStyle(Label tooltip, ChartElement owner)
|
||||
{
|
||||
if (tooltip == null) return;
|
||||
|
||||
tooltip.style.position = Position.Absolute;
|
||||
|
||||
var theme = owner != null ? owner.GetEffectiveThemeInternal() : ChartThemeRegistry.GlobalTheme;
|
||||
|
||||
Color textColor = theme != null ? theme.tooltipTextColor : DefaultTooltipTextColor;
|
||||
Color backgroundColor = theme != null ? theme.tooltipBackgroundColor : DefaultTooltipBackgroundColor;
|
||||
Color borderColor = theme != null ? theme.tooltipBorderColor : DefaultTooltipBorderColor;
|
||||
float borderWidth = theme != null ? Mathf.Max(0f, theme.tooltipBorderWidth) : 0f;
|
||||
Vector4 padding = theme != null ? theme.tooltipPadding : DefaultTooltipPadding;
|
||||
float cornerRadius = theme != null ? Mathf.Max(0f, theme.tooltipCornerRadius) : DefaultTooltipCornerRadius;
|
||||
|
||||
tooltip.style.color = textColor;
|
||||
tooltip.style.backgroundColor = backgroundColor;
|
||||
tooltip.style.paddingLeft = padding.x;
|
||||
tooltip.style.paddingRight = padding.y;
|
||||
tooltip.style.paddingTop = padding.z;
|
||||
tooltip.style.paddingBottom = padding.w;
|
||||
|
||||
tooltip.style.borderTopLeftRadius = cornerRadius;
|
||||
tooltip.style.borderTopRightRadius = cornerRadius;
|
||||
tooltip.style.borderBottomLeftRadius = cornerRadius;
|
||||
tooltip.style.borderBottomRightRadius = cornerRadius;
|
||||
|
||||
tooltip.style.borderLeftWidth = borderWidth;
|
||||
tooltip.style.borderRightWidth = borderWidth;
|
||||
tooltip.style.borderTopWidth = borderWidth;
|
||||
tooltip.style.borderBottomWidth = borderWidth;
|
||||
|
||||
tooltip.style.borderLeftColor = borderColor;
|
||||
tooltip.style.borderRightColor = borderColor;
|
||||
tooltip.style.borderTopColor = borderColor;
|
||||
tooltip.style.borderBottomColor = borderColor;
|
||||
|
||||
tooltip.userData = owner;
|
||||
ChartTextStyleApplier.ApplyLabel(tooltip, owner, ChartTextRole.Tooltip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,6 +364,9 @@ namespace EasyChart.Layers
|
||||
var labelColor = angleAxis.labelStyle != null ? angleAxis.labelStyle.color : angleAxis.labelColor;
|
||||
float labelRadius = outerRadiusPx + Mathf.Max(6f, fontSize * 0.6f);
|
||||
Vector2 axisOffset = angleAxis.labelStyle != null ? angleAxis.labelStyle.offset : angleAxis.labelOffset;
|
||||
float labelRadialOffset = primarySerie.settings is RadarSettings radarSettings && radarSettings.radar != null && radarSettings.radar.plot != null
|
||||
? radarSettings.radar.plot.labelRadialOffset
|
||||
: 0f;
|
||||
|
||||
for (int i = 0; i < dimensionCount; i++)
|
||||
{
|
||||
@@ -371,7 +374,7 @@ namespace EasyChart.Layers
|
||||
Vector2 dir = AngleToDir(angle);
|
||||
string text = ResolveDimensionLabel(labels, primarySerie, i);
|
||||
|
||||
Vector2 pos = center + dir * labelRadius + axisOffset;
|
||||
Vector2 pos = center + dir * (labelRadius + labelRadialOffset) + axisOffset;
|
||||
|
||||
float ax = Mathf.Abs(dir.x);
|
||||
float ay = Mathf.Abs(dir.y);
|
||||
|
||||
Reference in New Issue
Block a user