Skip to content

Commit 76e4ea7

Browse files
committed
Let a line chart's axis title and readout units be bound
yAxisTitle and the cursor readout's scale, decimals and suffix read their bindings, so a chart can follow a units setting (feet or metres). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F3B1XCZZ7QGvZLUGgSG5H4
1 parent 2b921e7 commit 76e4ea7

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎lib/src/transformers/node_transformers/passive_line_chart_transformer.dart‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class LineChartSpec {
260260
color: LineChartGeometry.parseColor(t['color']),
261261
),
262262
],
263-
yAxisTitle: props.yAxisTitle,
263+
yAxisTitle: text(bound('yAxisTitle')) ?? props.yAxisTitle,
264264
areaBands: [
265265
for (final Map b in maps('areaBands'))
266266
if ((x(b['from']), x(b['to']), n(b['below']), c(b)) case (
@@ -341,9 +341,11 @@ class LineChartSpec {
341341
props.tooltipValueStyle,
342342
),
343343
tooltipXFormat: props.tooltipXFormat,
344-
tooltipYScale: props.tooltipYScale,
345-
tooltipYDecimals: props.tooltipYDecimals,
346-
tooltipYSuffix: props.tooltipYSuffix,
344+
// The readout's units can follow a setting (feet or metres).
345+
tooltipYScale: n(bound('tooltipYScale')) ?? props.tooltipYScale,
346+
tooltipYDecimals:
347+
n(bound('tooltipYDecimals'))?.round() ?? props.tooltipYDecimals,
348+
tooltipYSuffix: text(bound('tooltipYSuffix')) ?? props.tooltipYSuffix,
347349
tooltipTrend: props.tooltipTrend,
348350
);
349351
}

‎test/line_chart_test.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,25 @@ void main() {
373373
expect(find.byType(PassiveLineChartWidget), findsOneWidget);
374374
});
375375
});
376+
377+
testWidgets('the axis title and readout units can be bound', (
378+
tester,
379+
) async {
380+
await pumpChart(
381+
tester,
382+
chart(
383+
variables: {
384+
'yAxisTitle': r"${= 1 > 0 ? 'M' : 'FT'}",
385+
'tooltipYScale': r'${= 0.3048}',
386+
'tooltipYDecimals': r'${= 2}',
387+
'tooltipYSuffix': r"${= ' m'}",
388+
},
389+
),
390+
);
391+
final spec = painterOf(tester).spec;
392+
expect(spec.yAxisTitle, 'M');
393+
expect(spec.tooltipYScale, 0.3048);
394+
expect(spec.tooltipYDecimals, 2);
395+
expect(spec.tooltipYSuffix, ' m');
396+
});
376397
}

0 commit comments

Comments
 (0)