Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions maui/src/Charts/Behaviors/ChartTooltipBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
null,
BindingMode.Default,
null,
defaultValueCreator: BackgroundDefaultValueCreator);
null);

/// <summary>
/// Identifies the <see cref="Duration"/> bindable property.
Expand Down Expand Up @@ -98,7 +98,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
null,
BindingMode.Default,
null,
defaultValueCreator: TextColorDefaultValueCreator);
null);

/// <summary>
/// Identifies the <see cref="Margin"/> bindable property.
Expand All @@ -125,7 +125,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
nameof(FontSize),
typeof(float),
typeof(ChartTooltipBehavior),
14f,
float.NaN,
BindingMode.Default,
null);

Expand Down Expand Up @@ -738,16 +738,6 @@ void Tooltip_TooltipClosed(object? sender, TooltipClosedEventArgs e)
return view;
}

static object TextColorDefaultValueCreator(BindableObject bindable)
{
return Color.FromArgb("#F4EFF4");
}

static object BackgroundDefaultValueCreator(BindableObject bindable)
{
return new SolidColorBrush(Color.FromArgb("#1C1B1F"));
}

#endregion

#endregion
Expand Down
10 changes: 1 addition & 9 deletions maui/src/Charts/ChartBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public abstract class ChartBase : View, IContentView, IChart
typeof(ChartBase),
null,
BindingMode.Default,
null,
null);

/// <summary>
Expand Down Expand Up @@ -603,7 +604,6 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
continue;
}

SetDefaultTooltipValue(behavior);
var tooltipInfo = chartSeries.GetTooltipInfo(behavior, x, y);
if (tooltipInfo != null)
{
Expand Down Expand Up @@ -682,7 +682,6 @@ public void SaveAsImage(string fileName)
if (_defaultToolTipBehavior == null)
{
_defaultToolTipBehavior = new ChartTooltipBehavior();
SetDefaultTooltipValue(_defaultToolTipBehavior);
_defaultToolTipBehavior.Chart = this;
// defaultToolTipBehavior.IsDefault = true;
}
Expand All @@ -698,13 +697,6 @@ public void SaveAsImage(string fileName)
}
}

internal void SetDefaultTooltipValue(ChartTooltipBehavior behavior)
{
behavior.Background = TooltipBackground ?? behavior.Background;
behavior.TextColor = TooltipTextColor ?? behavior.TextColor;
behavior.FontSize = !double.IsNaN(TooltipFontSize) ? (float)TooltipFontSize : behavior.FontSize;
}

SfTooltip? IChart.TooltipView
{
get { return _tooltipView; }
Expand Down
5 changes: 2 additions & 3 deletions maui/src/Charts/Series/BoxAndWhiskerSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,14 +1185,13 @@ internal override void GenerateSegments(SeriesView seriesView)
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);

if (IsOutlierTouch)
{
tooltipInfo.Text = yValue.ToString();
Expand Down
6 changes: 3 additions & 3 deletions maui/src/Charts/Series/CartesianSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,14 @@ internal bool IsDataInVisibleRange(double xValue, double yValue)
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = yValue == 0 ? yValue.ToString("0.##") : yValue.ToString("#.##"),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);

return tooltipInfo;
}

Expand Down
16 changes: 16 additions & 0 deletions maui/src/Charts/Series/ChartSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,22 @@ internal virtual void GenerateSegments(SeriesView seriesView)
{
}

/// <summary>
/// Updates the tooltip appearance including background, text color, and font size.
///
/// ChartTooltipBehavior Background with AppThemeBinding · Issue #159 · syncfusion/maui-toolkit
/// Resolved the issue where tooltip background doesn't update dynamically by changing the theme when using AppThemeBinding.
/// </summary>
internal void UpdateTooltipAppearance(TooltipInfo info, ChartTooltipBehavior tooltipBehavior)
{
if (Chart is ChartBase chart)
{
info.Background = tooltipBehavior.Background ?? chart.TooltipBackground ?? new SolidColorBrush(Color.FromArgb("#1C1B1F"));
info.TextColor = tooltipBehavior.TextColor ?? chart.TooltipTextColor ?? Color.FromArgb("#F4EFF4");
info.FontSize = !float.IsNaN(tooltipBehavior.FontSize) ? tooltipBehavior.FontSize : !float.IsNaN((float)chart.TooltipFontSize) ? (float)chart.TooltipFontSize : 14.0f;
}
}

internal virtual void InitiateDataLabels(ChartSegment segment)
{
if (DataLabels.Count > _segments.Count)
Expand Down
5 changes: 2 additions & 3 deletions maui/src/Charts/Series/HiLoOpenCloseSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,13 @@ internal virtual void CreateSegment(SeriesView seriesView, double[] values, bool
Index = index,
Text = (yValue == 0 ? yValue.ToString(" 0.##") : yValue.ToString(" #.##")) + "/" + (lowValue == 0 ? lowValue.ToString(" 0.##") : lowValue.ToString(" #.##")) + "/" + (openValue == 0 ? openValue.ToString(" 0.##") : openValue.ToString(" #.##")) + "/" + (closeValue == 0 ? closeValue.ToString(" 0.##") : closeValue.ToString(" #.##")),
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);

return tooltipInfo;
}

Expand Down
6 changes: 3 additions & 3 deletions maui/src/Charts/Series/PieSeries.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Specialized;
using Microsoft.Maui.Controls;
using Syncfusion.Maui.Toolkit.Graphics.Internals;

namespace Syncfusion.Maui.Toolkit.Charts
Expand Down Expand Up @@ -642,15 +643,14 @@ internal override void SetIndividualPoint(object obj, int index, bool replace)
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = yValue.ToString("#.##"),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);

return tooltipInfo;
}

Expand Down
5 changes: 2 additions & 3 deletions maui/src/Charts/Series/PolarSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,13 @@ internal void UpdateAssociatedAxes()
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = yValue.ToString("#.##"),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
return tooltipInfo;
}

Expand Down
5 changes: 2 additions & 3 deletions maui/src/Charts/Series/RadialBarSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,13 @@ internal override void OnSeriesLayout()
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = yValue.ToString("#.##"),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
return tooltipInfo;
}

Expand Down
4 changes: 1 addition & 3 deletions maui/src/Charts/Series/StackingAreaSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,13 @@ internal override bool IsIndividualSegment()
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = content.ToString(),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
return tooltipInfo;
}

Expand Down
6 changes: 2 additions & 4 deletions maui/src/Charts/Series/StackingColumnSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,12 @@ internal override void SetTooltipTargetRect(TooltipInfo tooltipInfo, Rect series
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = content.ToString()
};
;

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
tooltipInfo.Item = dataPoint;

return tooltipInfo;
Expand Down
4 changes: 1 addition & 3 deletions maui/src/Charts/Series/StackingLineSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,13 @@ internal override void DrawDataLabels(ICanvas canvas)
Y = yPosition,
Index = index,
Margin = tooltipBehavior.Margin,
TextColor = tooltipBehavior.TextColor,
FontFamily = tooltipBehavior.FontFamily,
FontSize = tooltipBehavior.FontSize,
FontAttributes = tooltipBehavior.FontAttributes,
Background = tooltipBehavior.Background,
Text = content.ToString(),
Item = dataPoint
};

UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
return tooltipInfo;
}

Expand Down
7 changes: 3 additions & 4 deletions maui/src/Charts/SfFunnelChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,19 +1199,18 @@ void IPyramidChartDependent.OnSelectionBehaviorPropertyChanged(object oldValue,
object dataPoint = _actualData[index];
double yValue = _yValues[index];
var segment = (FunnelSegment)_segments[index];
SetDefaultTooltipValue(behavior);

TooltipInfo tooltipInfo = new TooltipInfo(this)
{
X = segment.SegmentBounds.Center.X + (float)_seriesBounds.Left,
Y = segment.SegmentBounds.Center.Y + (float)_seriesBounds.Top,
Index = index,
Margin = behavior.Margin,
TextColor = behavior.TextColor,
TextColor = behavior.TextColor ?? TooltipTextColor ?? Color.FromArgb("#F4EFF4"),
FontFamily = behavior.FontFamily,
FontSize = behavior.FontSize,
FontSize = !float.IsNaN(behavior.FontSize) ? behavior.FontSize : !float.IsNaN((float)TooltipFontSize) ? (float)TooltipFontSize : 14.0f,
FontAttributes = behavior.FontAttributes,
Background = behavior.Background,
Background = behavior.Background ?? TooltipBackground ?? new SolidColorBrush(Color.FromArgb("#1C1B1F")),
Text = yValue.ToString("#.##"),
Item = dataPoint
};
Expand Down
1 change: 0 additions & 1 deletion maui/src/Charts/SfPolarChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,6 @@ protected override void OnBindingContextChanged()
continue;
}

SetDefaultTooltipValue(behavior);
TooltipInfo? tooltipInfo = chartSeries.GetTooltipInfo(behavior, x, y);

if (tooltipInfo != null)
Expand Down
8 changes: 4 additions & 4 deletions maui/src/Charts/SfPyramidChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,18 +1223,18 @@ internal override void UpdateLegendItems()
object dataPoint = _actualData[index];
double yValue = _yValues[index];
var segment = (ChartSegment)_segments[index];
SetDefaultTooltipValue(behavior);

TooltipInfo tooltipInfo = new TooltipInfo(this)
{
X = segment.SegmentBounds.Center.X + (float)_seriesBounds.Left,
Y = segment.SegmentBounds.Center.Y + (float)_seriesBounds.Top,
Index = index,
Margin = behavior.Margin,
TextColor = behavior.TextColor,
TextColor = behavior.TextColor ?? TooltipTextColor ?? Color.FromArgb("#F4EFF4"),
FontFamily = behavior.FontFamily,
FontSize = behavior.FontSize,
FontSize = !float.IsNaN(behavior.FontSize) ? behavior.FontSize : !float.IsNaN((float)TooltipFontSize) ? (float)TooltipFontSize : 14.0f,
FontAttributes = behavior.FontAttributes,
Background = behavior.Background,
Background = behavior.Background ?? TooltipBackground ?? new SolidColorBrush(Color.FromArgb("#1C1B1F")),
Text = yValue.ToString("#.##"),
Item = dataPoint
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ public void ChartTooltipBehaviorDefaultTests()
var behavior = new ChartTooltipBehavior();

// ChartTooltipBehavior specific properties
Assert.NotNull(behavior.Background);
Assert.IsType<SolidColorBrush>(behavior.Background);
Assert.Equal(Color.FromArgb("#1C1B1F"), ((SolidColorBrush)behavior.Background).Color);
Assert.Null(behavior.Background);
Assert.Equal(2, behavior.Duration);
Assert.Equal(Color.FromArgb("#F4EFF4"), behavior.TextColor);
Assert.Null(behavior.TextColor);
Assert.Equal(new Thickness(0), behavior.Margin);
Assert.Equal(14f, behavior.FontSize);
Assert.Equal(float.NaN, behavior.FontSize);
Assert.Null(behavior.FontFamily);
Assert.Equal(FontAttributes.None, behavior.FontAttributes);

Expand Down
Loading