Skip to content

Commit dfb6db2

Browse files
committed
refactor: Update tooltip configuration and interaction settings in charts
1 parent 6685fec commit dfb6db2

5 files changed

Lines changed: 29 additions & 33 deletions

File tree

sdk/python/examples/controls/charts/candlestick_chart/example_1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def handle_event(e: ftc.CandlestickChartEvent):
9999
horizontal_alignment=ftc.HorizontalAlignment.CENTER,
100100
fit_inside_horizontally=True,
101101
),
102-
handle_built_in_touches=False,
103102
on_event=handle_event,
104103
)
105104

sdk/python/examples/controls/charts/scatter_chart/example_1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(
1919
radius=radius,
2020
color=color,
2121
show_tooltip=show_tooltip,
22+
selected=y == 43,
2223
)
2324

2425

@@ -145,7 +146,7 @@ def handle_event(e: ftc.ScatterChartEvent):
145146
right_axis=ftc.ChartAxis(show_labels=False),
146147
top_axis=ftc.ChartAxis(show_labels=False),
147148
bottom_axis=ftc.ChartAxis(show_labels=False),
148-
show_tooltips_for_selected_spots_only=True,
149+
show_tooltips_for_selected_spots_only=False,
149150
on_event=handle_event,
150151
animation=ft.Animation(
151152
duration=ft.Duration(milliseconds=600),

sdk/python/packages/flet-charts/src/flet_charts/candlestick_chart.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
class CandlestickChartTooltip:
1818
"""Configuration of the tooltip for [`CandlestickChart`][(p).]s."""
1919

20-
bgcolor: ft.ColorValue = "#FF607D8B"
20+
bgcolor: ft.ColorValue = "#FFFFECEF"
2121
"""
2222
Background color applied to the tooltip bubble.
2323
"""
2424

25-
border_radius: Optional[ft.BorderRadiusValue] = None
25+
border_radius: ft.BorderRadiusValue = field(
26+
default_factory=lambda: ft.BorderRadius.all(4)
27+
)
2628
"""
2729
Corner radius of the tooltip bubble.
2830
"""
@@ -159,17 +161,18 @@ class CandlestickChart(ft.LayoutControl):
159161
Enables automatic tooltips and highlighting when hovering the chart.
160162
"""
161163

162-
handle_built_in_touches: bool = True
164+
show_tooltips_for_selected_spots_only: bool = False
163165
"""
164-
Allows the chart to manage tooltip visibility automatically.
166+
Whether to permanently and only show the tooltips of spots with their
167+
[`selected`][(p).CandlestickChartSpot.selected] property set to `True`.
165168
"""
166169

167170
long_press_duration: Optional[ft.DurationValue] = None
168171
"""
169172
The duration of a long press on the chart.
170173
"""
171174

172-
touch_spot_threshold: Optional[ft.Number] = None
175+
touch_spot_threshold: ft.Number = 4
173176
"""
174177
The distance threshold to consider a touch near a candlestick.
175178
"""

sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/candlestick_chart.dart

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class _CandlestickChartControlState extends State<CandlestickChartControl> {
3737
final bottomTitles = parseAxisTitles(widget.control.child("bottom_axis"));
3838

3939
final interactive = widget.control.getBool("interactive", true)!;
40-
final handleBuiltInTouches =
41-
widget.control.getBool("handle_built_in_touches", true)!;
42-
final touchSpotThreshold = widget.control.getDouble("touch_spot_threshold");
4340

4441
final spotControls = widget.control.children("spots");
4542
final candlestickSpots = spotControls.map((spot) {
@@ -54,22 +51,12 @@ class _CandlestickChartControlState extends State<CandlestickChartControl> {
5451
);
5552
}).toList();
5653

57-
final selectedIndicators = spotControls
58-
.asMap()
59-
.entries
60-
.where((e) => e.value.getBool("selected", false)!)
61-
.map((e) => e.key)
62-
.toList();
63-
64-
final showingIndicators =
65-
(!interactive || !handleBuiltInTouches) ? selectedIndicators : <int>[];
66-
6754
final candlestickTouchData = CandlestickTouchData(
6855
enabled: interactive && !widget.control.disabled,
6956
handleBuiltInTouches: !widget.control
7057
.getBool("show_tooltips_for_selected_spots_only", false)!,
7158
longPressDuration: widget.control.getDuration("long_press_duration"),
72-
touchSpotThreshold: touchSpotThreshold,
59+
touchSpotThreshold: widget.control.getDouble("touch_spot_threshold", 4)!,
7360
touchTooltipData: parseCandlestickTouchTooltipData(
7461
context,
7562
widget.control,
@@ -113,7 +100,12 @@ class _CandlestickChartControlState extends State<CandlestickChartControl> {
113100
widget.control.get("vertical_grid_lines"),
114101
theme),
115102
candlestickTouchData: candlestickTouchData,
116-
showingTooltipIndicators: showingIndicators,
103+
showingTooltipIndicators: spotControls
104+
.asMap()
105+
.entries
106+
.where((e) => e.value.getBool("selected", false)!)
107+
.map((e) => e.key)
108+
.toList(),
117109
rotationQuarterTurns:
118110
widget.control.getInt("rotation_quarter_turns", 0)!,
119111
),

sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/utils/candlestick_chart.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ CandlestickTouchTooltipData parseCandlestickTouchTooltipData(
3939
final theme = Theme.of(context);
4040

4141
return CandlestickTouchTooltipData(
42-
tooltipBorder:
43-
parseBorderSide(tooltip["border_side"], theme, defaultValue: BorderSide.none)!,
42+
tooltipBorder: parseBorderSide(tooltip["border_side"], theme,
43+
defaultValue: BorderSide.none)!,
4444
rotateAngle: parseDouble(tooltip["rotation"], 0.0)!,
45-
tooltipBorderRadius: parseBorderRadius(tooltip["border_radius"]),
46-
tooltipPadding: parsePadding(
47-
tooltip["padding"], const EdgeInsets.symmetric(horizontal: 16, vertical: 8))!,
45+
tooltipBorderRadius:
46+
parseBorderRadius(tooltip["border_radius"], BorderRadius.circular(4))!,
47+
tooltipPadding: parsePadding(tooltip["padding"],
48+
const EdgeInsets.symmetric(horizontal: 16, vertical: 8))!,
4849
tooltipHorizontalAlignment: parseFLHorizontalAlignment(
4950
tooltip["horizontal_alignment"], FLHorizontalAlignment.center)!,
5051
tooltipHorizontalOffset: parseDouble(tooltip["horizontal_offset"], 0)!,
5152
maxContentWidth: parseDouble(tooltip["max_width"], 120)!,
5253
fitInsideHorizontally:
5354
parseBool(tooltip["fit_inside_horizontally"], false)!,
54-
fitInsideVertically:
55-
parseBool(tooltip["fit_inside_vertically"], false)!,
55+
fitInsideVertically: parseBool(tooltip["fit_inside_vertically"], false)!,
5656
showOnTopOfTheChartBoxArea:
5757
parseBool(tooltip["show_on_top_of_chart_box_area"], false)!,
58-
getTooltipColor: (spot) => parseColor(
59-
tooltip["bgcolor"], theme, const Color.fromRGBO(96, 125, 139, 1))!,
58+
getTooltipColor: (spot) =>
59+
parseColor(tooltip["bgcolor"], theme, const Color(0xFFFFECEF))!,
6060
getTooltipItems: (painter, touchedSpot, spotIndex) {
6161
if (spotIndex < 0 || spotIndex >= spotControls.length) {
6262
return null;
@@ -105,8 +105,9 @@ CandlestickTooltipItem? parseCandlestickTooltipItem(
105105
textStyle: textStyle,
106106
bottomMargin: parseDouble(tooltip["bottom_margin"], 8)!,
107107
textAlign: parseTextAlign(tooltip["text_align"], TextAlign.center)!,
108-
textDirection:
109-
parseBool(tooltip["rtl"], false)! ? TextDirection.rtl : TextDirection.ltr,
108+
textDirection: parseBool(tooltip["rtl"], false)!
109+
? TextDirection.rtl
110+
: TextDirection.ltr,
110111
children: tooltip["text_spans"] != null
111112
? parseTextSpans(tooltip["text_spans"], theme, (s, eventName,
112113
[eventData]) {

0 commit comments

Comments
 (0)