Skip to content

Commit ed8b478

Browse files
Updated the tooltip background fix in the open source.
1 parent 420a69e commit ed8b478

17 files changed

+95
-75
lines changed

maui/src/Charts/Behaviors/ChartTooltipBehavior.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
6868
null,
6969
BindingMode.Default,
7070
null,
71-
defaultValueCreator: BackgroundDefaultValueCreator);
71+
null);
7272

7373
/// <summary>
7474
/// Identifies the <see cref="Duration"/> bindable property.
@@ -98,7 +98,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
9898
null,
9999
BindingMode.Default,
100100
null,
101-
defaultValueCreator: TextColorDefaultValueCreator);
101+
null);
102102

103103
/// <summary>
104104
/// Identifies the <see cref="Margin"/> bindable property.
@@ -125,7 +125,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
125125
nameof(FontSize),
126126
typeof(float),
127127
typeof(ChartTooltipBehavior),
128-
14f,
128+
float.NaN,
129129
BindingMode.Default,
130130
null);
131131

@@ -738,16 +738,6 @@ void Tooltip_TooltipClosed(object? sender, TooltipClosedEventArgs e)
738738
return view;
739739
}
740740

741-
static object TextColorDefaultValueCreator(BindableObject bindable)
742-
{
743-
return Color.FromArgb("#F4EFF4");
744-
}
745-
746-
static object BackgroundDefaultValueCreator(BindableObject bindable)
747-
{
748-
return new SolidColorBrush(Color.FromArgb("#1C1B1F"));
749-
}
750-
751741
#endregion
752742

753743
#endregion

maui/src/Charts/ChartBase.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public abstract class ChartBase : View, IContentView, IChart
117117
typeof(ChartBase),
118118
null,
119119
BindingMode.Default,
120+
null,
120121
null);
121122

122123
/// <summary>
@@ -603,7 +604,6 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
603604
continue;
604605
}
605606

606-
SetDefaultTooltipValue(behavior);
607607
var tooltipInfo = chartSeries.GetTooltipInfo(behavior, x, y);
608608
if (tooltipInfo != null)
609609
{
@@ -682,7 +682,6 @@ public void SaveAsImage(string fileName)
682682
if (_defaultToolTipBehavior == null)
683683
{
684684
_defaultToolTipBehavior = new ChartTooltipBehavior();
685-
SetDefaultTooltipValue(_defaultToolTipBehavior);
686685
_defaultToolTipBehavior.Chart = this;
687686
// defaultToolTipBehavior.IsDefault = true;
688687
}
@@ -698,13 +697,6 @@ public void SaveAsImage(string fileName)
698697
}
699698
}
700699

701-
internal void SetDefaultTooltipValue(ChartTooltipBehavior behavior)
702-
{
703-
behavior.Background = TooltipBackground ?? behavior.Background;
704-
behavior.TextColor = TooltipTextColor ?? behavior.TextColor;
705-
behavior.FontSize = !double.IsNaN(TooltipFontSize) ? (float)TooltipFontSize : behavior.FontSize;
706-
}
707-
708700
SfTooltip? IChart.TooltipView
709701
{
710702
get { return _tooltipView; }

maui/src/Charts/Series/BoxAndWhiskerSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,13 @@ internal override void GenerateSegments(SeriesView seriesView)
11891189
Y = yPosition,
11901190
Index = index,
11911191
Margin = tooltipBehavior.Margin,
1192-
TextColor = tooltipBehavior.TextColor,
11931192
FontFamily = tooltipBehavior.FontFamily,
1194-
FontSize = tooltipBehavior.FontSize,
11951193
FontAttributes = tooltipBehavior.FontAttributes,
1196-
Background = tooltipBehavior.Background,
11971194
Item = dataPoint
11981195
};
11991196

1197+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
1198+
12001199
if (IsOutlierTouch)
12011200
{
12021201
tooltipInfo.Text = yValue.ToString();

maui/src/Charts/Series/CartesianSeries.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,14 +1340,14 @@ internal bool IsDataInVisibleRange(double xValue, double yValue)
13401340
Y = yPosition,
13411341
Index = index,
13421342
Margin = tooltipBehavior.Margin,
1343-
TextColor = tooltipBehavior.TextColor,
13441343
FontFamily = tooltipBehavior.FontFamily,
1345-
FontSize = tooltipBehavior.FontSize,
13461344
FontAttributes = tooltipBehavior.FontAttributes,
1347-
Background = tooltipBehavior.Background,
13481345
Text = yValue == 0 ? yValue.ToString("0.##") : yValue.ToString("#.##"),
13491346
Item = dataPoint
13501347
};
1348+
1349+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
1350+
13511351
return tooltipInfo;
13521352
}
13531353

maui/src/Charts/Series/ChartSeries.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,16 @@ internal virtual void GenerateSegments(SeriesView seriesView)
17371737
{
17381738
}
17391739

1740+
internal void UpdateTooltipAppearance(TooltipInfo info, ChartTooltipBehavior tooltipBehavior)
1741+
{
1742+
if (Chart is ChartBase chart)
1743+
{
1744+
info.Background = tooltipBehavior.Background ?? chart.TooltipBackground ?? new SolidColorBrush(Color.FromArgb("#1C1B1F"));
1745+
info.TextColor = tooltipBehavior.TextColor ?? chart.TooltipTextColor ?? Color.FromArgb("#F4EFF4");
1746+
info.FontSize = !float.IsNaN(tooltipBehavior.FontSize) ? tooltipBehavior.FontSize : !float.IsNaN((float)chart.TooltipFontSize) ? (float)chart.TooltipFontSize : 14.0f;
1747+
}
1748+
}
1749+
17401750
internal virtual void InitiateDataLabels(ChartSegment segment)
17411751
{
17421752
if (DataLabels.Count > _segments.Count)

maui/src/Charts/Series/HiLoOpenCloseSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ internal virtual void CreateSegment(SeriesView seriesView, double[] values, bool
322322
Index = index,
323323
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(" #.##")),
324324
Margin = tooltipBehavior.Margin,
325-
TextColor = tooltipBehavior.TextColor,
326325
FontFamily = tooltipBehavior.FontFamily,
327-
FontSize = tooltipBehavior.FontSize,
328326
FontAttributes = tooltipBehavior.FontAttributes,
329-
Background = tooltipBehavior.Background,
330327
Item = dataPoint
331328
};
332329

330+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
331+
333332
return tooltipInfo;
334333
}
335334

maui/src/Charts/Series/PieSeries.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Specialized;
2+
using Microsoft.Maui.Controls;
23
using Syncfusion.Maui.Toolkit.Graphics.Internals;
34

45
namespace Syncfusion.Maui.Toolkit.Charts
@@ -642,15 +643,14 @@ internal override void SetIndividualPoint(object obj, int index, bool replace)
642643
Y = yPosition,
643644
Index = index,
644645
Margin = tooltipBehavior.Margin,
645-
TextColor = tooltipBehavior.TextColor,
646646
FontFamily = tooltipBehavior.FontFamily,
647-
FontSize = tooltipBehavior.FontSize,
648647
FontAttributes = tooltipBehavior.FontAttributes,
649-
Background = tooltipBehavior.Background,
650648
Text = yValue.ToString("#.##"),
651649
Item = dataPoint
652650
};
653651

652+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
653+
654654
return tooltipInfo;
655655
}
656656

maui/src/Charts/Series/PolarSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,13 @@ internal void UpdateAssociatedAxes()
866866
Y = yPosition,
867867
Index = index,
868868
Margin = tooltipBehavior.Margin,
869-
TextColor = tooltipBehavior.TextColor,
870869
FontFamily = tooltipBehavior.FontFamily,
871-
FontSize = tooltipBehavior.FontSize,
872870
FontAttributes = tooltipBehavior.FontAttributes,
873-
Background = tooltipBehavior.Background,
874871
Text = yValue.ToString("#.##"),
875872
Item = dataPoint
876873
};
874+
875+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
877876
return tooltipInfo;
878877
}
879878

maui/src/Charts/Series/RadialBarSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,14 +764,13 @@ internal override void OnSeriesLayout()
764764
Y = yPosition,
765765
Index = index,
766766
Margin = tooltipBehavior.Margin,
767-
TextColor = tooltipBehavior.TextColor,
768767
FontFamily = tooltipBehavior.FontFamily,
769-
FontSize = tooltipBehavior.FontSize,
770768
FontAttributes = tooltipBehavior.FontAttributes,
771-
Background = tooltipBehavior.Background,
772769
Text = yValue.ToString("#.##"),
773770
Item = dataPoint
774771
};
772+
773+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
775774
return tooltipInfo;
776775
}
777776

maui/src/Charts/Series/StackingAreaSeries.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,13 @@ internal override bool IsIndividualSegment()
548548
Y = yPosition,
549549
Index = index,
550550
Margin = tooltipBehavior.Margin,
551-
TextColor = tooltipBehavior.TextColor,
552551
FontFamily = tooltipBehavior.FontFamily,
553-
FontSize = tooltipBehavior.FontSize,
554552
FontAttributes = tooltipBehavior.FontAttributes,
555-
Background = tooltipBehavior.Background,
556553
Text = content.ToString(),
557554
Item = dataPoint
558555
};
559556

557+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
560558
return tooltipInfo;
561559
}
562560

0 commit comments

Comments
 (0)