Skip to content

Commit 65766db

Browse files
committed
Gauge and bar chart widgets take the caller's scoped values
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjsYaRkTHNKszSHjd3j264
1 parent b6c24d8 commit 65766db

2 files changed

Lines changed: 43 additions & 20 deletions

File tree

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class PassiveBarChartWidget extends StatelessWidget {
2525
final WidgetBuildSettings settings;
2626
final List<VariableData> variablesOverrides;
2727

28+
/// The values bindings read, when the caller has them, e.g. the editor's
29+
/// variable defaults on the design canvas. Defaults to the context's.
30+
final ScopedValues? scopedValues;
31+
2832
/// Overrides [BarChartProperties.animate], e.g. to hold still in the editor.
2933
final bool? animate;
3034

@@ -33,6 +37,7 @@ class PassiveBarChartWidget extends StatelessWidget {
3337
required this.node,
3438
required this.settings,
3539
this.variablesOverrides = const [],
40+
this.scopedValues,
3641
this.animate,
3742
});
3843

@@ -56,10 +61,9 @@ class PassiveBarChartWidget extends StatelessWidget {
5661

5762
@override
5863
Widget build(BuildContext context) {
59-
final ScopedValues scopedValues = ScopedValues.of(
60-
context,
61-
variablesOverrides: variablesOverrides,
62-
);
64+
final ScopedValues scopedValues =
65+
this.scopedValues ??
66+
ScopedValues.of(context, variablesOverrides: variablesOverrides);
6367
final BarChartProperties props = node.properties;
6468
Object? bound(String property) =>
6569
PropertyValueDelegate.getPropertyValue<Object>(
@@ -71,9 +75,7 @@ class PassiveBarChartWidget extends StatelessWidget {
7175
final List<double?> values =
7276
_list(bound('values'))?.map(_number).toList() ?? node.values;
7377
final List<String> labels =
74-
_list(
75-
bound('labels'),
76-
)?.map((e) => e == null ? '' : '$e').toList() ??
78+
_list(bound('labels'))?.map((e) => e == null ? '' : '$e').toList() ??
7779
node.labels;
7880
final Object? boundHighlight = bound('highlight');
7981
final int? highlight = boundHighlight != null
@@ -111,8 +113,10 @@ class PassiveBarChartWidget extends StatelessWidget {
111113
final double labelHeight = hasLabels
112114
? props.labelFontSize * 1.2 + props.labelGap
113115
: 0;
114-
final double height = (constraints.maxHeight - labelHeight - 1)
115-
.clamp(0, double.infinity);
116+
final double height = (constraints.maxHeight - labelHeight - 1).clamp(
117+
0,
118+
double.infinity,
119+
);
116120
return Column(
117121
crossAxisAlignment: CrossAxisAlignment.stretch,
118122
children: [
@@ -135,7 +139,8 @@ class PassiveBarChartWidget extends StatelessWidget {
135139
Positioned(
136140
right: 0,
137141
width: props.gridLabelWidth - 6,
138-
bottom: height * g / props.gridLines -
142+
bottom:
143+
height * g / props.gridLines -
139144
props.labelFontSize / 2,
140145
child: Text(
141146
props.gridLabels[g - 1],
@@ -235,7 +240,8 @@ class PassiveBarChartWidget extends StatelessWidget {
235240
props.emptyHeight,
236241
height,
237242
);
238-
final Color barColor = highlight == null || highlight < 0 || index == highlight
243+
final Color barColor =
244+
highlight == null || highlight < 0 || index == highlight
239245
? color
240246
: color.withValues(alpha: color.a * props.dimmedOpacity);
241247
return TweenAnimationBuilder<double>(

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class PassiveGaugeWidget extends StatelessWidget {
2525
final WidgetBuildSettings settings;
2626
final List<VariableData> variablesOverrides;
2727

28+
/// The values bindings read, when the caller has them, e.g. the editor's
29+
/// variable defaults on the design canvas. Defaults to the context's.
30+
final ScopedValues? scopedValues;
31+
2832
/// Overrides [GaugeProperties.animate], e.g. to hold still in the editor.
2933
final bool? animate;
3034

@@ -33,15 +37,15 @@ class PassiveGaugeWidget extends StatelessWidget {
3337
required this.node,
3438
required this.settings,
3539
this.variablesOverrides = const [],
40+
this.scopedValues,
3641
this.animate,
3742
});
3843

3944
@override
4045
Widget build(BuildContext context) {
41-
final ScopedValues scopedValues = ScopedValues.of(
42-
context,
43-
variablesOverrides: variablesOverrides,
44-
);
46+
final ScopedValues scopedValues =
47+
this.scopedValues ??
48+
ScopedValues.of(context, variablesOverrides: variablesOverrides);
4549
final GaugeProperties props = node.properties;
4650
final double value =
4751
_number(
@@ -173,7 +177,13 @@ class GaugePainter extends CustomPainter {
173177
..strokeWidth = stroke;
174178
canvas.drawArc(rect, start, sweep, false, paint..color = track);
175179
if (fraction > 0) {
176-
canvas.drawArc(rect, start, sweep * fraction, false, paint..color = color);
180+
canvas.drawArc(
181+
rect,
182+
start,
183+
sweep * fraction,
184+
false,
185+
paint..color = color,
186+
);
177187
}
178188
}
179189

@@ -256,8 +266,7 @@ class GaugePainter extends CustomPainter {
256266

257267
if (props.segments > 0) {
258268
final double gap = props.segmentGap;
259-
final double seg =
260-
(length - gap * (props.segments - 1)) / props.segments;
269+
final double seg = (length - gap * (props.segments - 1)) / props.segments;
261270
final int lit = (fraction * props.segments).round();
262271
final Radius segRadius = Radius.circular(
263272
math.min(props.cornerRadius, seg / 2),
@@ -311,7 +320,11 @@ class GaugePainter extends CustomPainter {
311320
final double p = length * i / props.ticks;
312321
if (vertical) {
313322
final double y = inner.bottom - p;
314-
canvas.drawLine(Offset(inner.left, y), Offset(inner.left + w, y), tick);
323+
canvas.drawLine(
324+
Offset(inner.left, y),
325+
Offset(inner.left + w, y),
326+
tick,
327+
);
315328
canvas.drawLine(
316329
Offset(inner.right - w, y),
317330
Offset(inner.right, y),
@@ -345,7 +358,11 @@ class GaugePainter extends CustomPainter {
345358
final double total = (b - a).distance;
346359
final Offset dir = (b - a) / total;
347360
for (double t = 0; t < total; t += dash * 2) {
348-
canvas.drawLine(a + dir * t, a + dir * math.min(t + dash, total), paint);
361+
canvas.drawLine(
362+
a + dir * t,
363+
a + dir * math.min(t + dash, total),
364+
paint,
365+
);
349366
}
350367
} else {
351368
canvas.drawLine(a, b, paint);

0 commit comments

Comments
 (0)