Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 555c9ab

Browse files
stuartmorgan-gGooglerstereotype441
authored
GitHub Sync (#710)
* Internal changes PiperOrigin-RevId: 386374477 * Fix `getNearestDatumDetailPerSeries` function in `LineRenderer` for area charts. The measure distance of the first series above the given point is set to 0 to make sure the `SelectNearest` behavior selects the correct series in area charts. PiperOrigin-RevId: 391045574 * Fix `getNearestDatumDetailPerSeries` function in `LineRenderer` for area charts. The measure distance of the first series above the given point is set to 0 to make sure the `SelectNearest` behavior selects the correct series in area charts. PiperOrigin-RevId: 391058485 * Fix `getNearestDatumDetailPerSeries` function in `LineRenderer` for area charts. The measure distance of the first series above the given point is set to 0 to make sure the `SelectNearest` behavior selects the correct series in area charts. PiperOrigin-RevId: 391240493 * Automated g4 rollback of changelist 391240493. Internal changes. *** Reason for rollback *** Breaks play console ui scuba test. *** Original change description *** Automated g4 rollback of changelist 391058485. *** Reason for rollback *** Fix broken test *** Original change description *** Automated g4 rollback of changelist 391045574. *** Reason for rollback *** Causing continuous build failure *** PiperOrigin-RevId: 391271021 * Internal changes PiperOrigin-RevId: 392084061 * Fix getNearestDatumDetailPerSeries function in LineRenderer for area charts. The measure distance of the first series above the given point is set to 0 to make sure the SelectNearest behavior selects the correct series in area charts. PiperOrigin-RevId: 392863701 * Fix exception caused by null y coordinate. PiperOrigin-RevId: 393199512 * Add functions to draw horizontal or vertical links onto the dart charts web canvas. PiperOrigin-RevId: 393802496 * Update code in preparation for the fix to dart-lang/language#1785 to roll out. In short, this bug prevents implicitly typed condition variables from participating in type promotion in some circumstances (see the bug for more details). Since the bug only occurs when the condition variable is implicitly typed, we can ensure a smooth rollout by giving explicit `bool` types to the condition variables affected by this bug. Once the fix has fully rolled out to google3 we will be able to remove these explicit types once again. Tested: TAP --sample ran all affected tests and none failed http://test/OCL:394261565:BASE:394223559:1630517438374:b19cc4e4 PiperOrigin-RevId: 394291389 * Internal changes PiperOrigin-RevId: 394393084 * Update code in preparation for the fix to dart-lang/language#1785 to roll out. In short, this bug prevents implicitly typed condition variables from participating in type promotion in some circumstances (see the bug for more details). Since the bug only occurs when the condition variable is implicitly typed, we can ensure a smooth rollout by giving explicit `bool` types to the condition variables affected by this bug. Once the fix has fully rolled out to google3 we will be able to remove these explicit types once again. Tested: Some test failures are present, but the CL author has decided to mail the change anyway PiperOrigin-RevId: 394482159 * Add barGroupInnerPaddingPx in BarRendererConfig to allow configuration of padding between grouped bars PiperOrigin-RevId: 394589317 * Internal changes PiperOrigin-RevId: 394593125 * Create `AutoAdjustingStatickTickProvider` for bar charts, which selects a tick increment (from a list of available increments) such that the ticks don't collide on the chart. PiperOrigin-RevId: 394645415 * Internal changes PiperOrigin-RevId: 395812304 * Internal changes PiperOrigin-RevId: 395954739 * Internal changes PiperOrigin-RevId: 396359518 * Internal changes PiperOrigin-RevId: 396414170 * Internal changes PiperOrigin-RevId: 396573153 * Internal changes PiperOrigin-RevId: 396579689 * Internal changes PiperOrigin-RevId: 396581475 * Internal changes PiperOrigin-RevId: 396587541 * Add skeleton of Sankey Chart files to be used in static Sankey diagram. PiperOrigin-RevId: 397091086 * Add generic graph class initializers PiperOrigin-RevId: 401770789 * Add ingoing and outgoing node links and toSeriesList conversion. PiperOrigin-RevId: 401774582 * Internal changes PiperOrigin-RevId: 401812322 * Add barGroupInnerPaddingPx in BarTargetLineRendererConfig to allow configuration of padding between grouped target lines PiperOrigin-RevId: 402968313 * Convert from Travis to GitHub Actions for external CI PiperOrigin-RevId: 403395009 * Skip daylight saving tests on unsupported configurations The tests of time zone handling expect the local machine to use PST (or equivalent) time zones, since DateTime doesn't have a concept of a set, non-local time zone. That causes these tests to fail when run in any other time zone, which can frequently happen with external CI such as Travis or GitHub actions. This conditionally skips those tests on machines that don't have the necessary local time zone behavior, so that the rest of the unit tests can be run in external CI. PiperOrigin-RevId: 403509608 * Add Sankey specific links and nodes PiperOrigin-RevId: 404285533 * Add topological graph sort with cycle detection PiperOrigin-RevId: 404804722 * internal changes PiperOrigin-RevId: 406857881 * Update CHANGELOGs and pubspec.yamls PiperOrigin-RevId: 407073944 Co-authored-by: Googler <[email protected]> Co-authored-by: paulberry <[email protected]>
1 parent 3047709 commit 555c9ab

File tree

64 files changed

+2620
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2620
-341
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-20.04
8+
strategy:
9+
matrix:
10+
channel: [master, stable]
11+
# Disable fail-fast; we want results from all channels even if one fails.
12+
fail-fast: false
13+
14+
steps:
15+
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
16+
with:
17+
path: charts
18+
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
19+
with:
20+
path: flutter
21+
repository: flutter/flutter
22+
ref: ${{ matrix.channel }}
23+
# Shallow clones don't work; see https://github.com/flutter/flutter/issues/18532
24+
fetch-depth: 0
25+
- name: Add Flutter tags
26+
# Add tags, which are also necessary for version checks to work.
27+
run: git fetch origin +refs/tags/*:refs/tags/*
28+
working-directory: ${{ github.workspace }}/flutter
29+
- name: Add Flutter to path
30+
run: echo "$GITHUB_WORKSPACE/flutter/bin" >> $GITHUB_PATH
31+
- name: Doctor
32+
# Run doctor, for ease of debugging any issues.
33+
run: flutter doctor -v
34+
- name: charts_common tests
35+
run: |
36+
dart pub get
37+
dart pub run test
38+
working-directory: ${{ github.workspace }}/charts/charts_common
39+
- name: charts_flutter tests
40+
run: flutter test
41+
working-directory: ${{ github.workspace }}/charts/charts_flutter
42+

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

charts_common/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.12.0
2+
* Expose `NumericScale`, `LinearScale` and `ScaleSpec`
3+
* Add functions to draw horizontal or vertical links.
4+
* Added more padding options.
5+
* Create `AutoAdjustingStatickTickProvider` for bar charts.
6+
* Add generic graph class initializers.
7+
* Add ingoing and outgoing node links and toSeriesList conversion.
8+
* Bug fixes.
9+
110
# 0.11.0
211
* Null support
312
* Update to latest from internal repo

charts_common/lib/common.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
export 'src/chart/bar/bar_chart.dart' show BarChart;
1717
export 'src/chart/bar/bar_error_decorator.dart' show BarErrorDecorator;
1818
export 'src/chart/bar/bar_label_decorator.dart'
19-
show BarLabelAnchor, BarLabelDecorator, BarLabelPlacement, BarLabelPosition;
19+
show
20+
BarLabelAnchor,
21+
BarLabelDecorator,
22+
BarLabelPlacement,
23+
BarLabelPosition,
24+
BarLabelVerticalPosition;
2025
export 'src/chart/bar/bar_lane_renderer_config.dart' show BarLaneRendererConfig;
2126
export 'src/chart/bar/bar_renderer.dart'
2227
show BarRenderer, BarRendererElement, ImmutableBarRendererElement;
@@ -57,12 +62,15 @@ export 'src/chart/cartesian/axis/draw_strategy/small_tick_draw_strategy.dart'
5762
show SmallTickRendererSpec;
5863
export 'src/chart/cartesian/axis/draw_strategy/tick_draw_strategy.dart'
5964
show TickDrawStrategy;
65+
export 'src/chart/cartesian/axis/linear/linear_scale.dart' show LinearScale;
6066
export 'src/chart/cartesian/axis/numeric_extents.dart' show NumericExtents;
67+
export 'src/chart/cartesian/axis/numeric_scale.dart' show NumericScale;
6168
export 'src/chart/cartesian/axis/spec/axis_spec.dart'
6269
show
6370
AxisSpec,
6471
LineStyleSpec,
6572
RenderSpec,
73+
ScaleSpec,
6674
TextStyleSpec,
6775
TickLabelAnchor,
6876
TickLabelJustification,
@@ -95,6 +103,7 @@ export 'src/chart/cartesian/axis/spec/numeric_axis_spec.dart'
95103
StaticNumericTickProviderSpec;
96104
export 'src/chart/cartesian/axis/spec/ordinal_axis_spec.dart'
97105
show
106+
AutoAdjustingStaticOrdinalTickProviderSpec,
98107
BasicOrdinalTickProviderSpec,
99108
BasicOrdinalTickFormatterSpec,
100109
FixedPixelOrdinalScaleSpec,
@@ -195,7 +204,7 @@ export 'src/chart/common/behavior/zoom/panning_tick_provider.dart'
195204
export 'src/chart/common/canvas_shapes.dart'
196205
show CanvasBarStack, CanvasPie, CanvasPieSlice, CanvasRect;
197206
export 'src/chart/common/chart_canvas.dart'
198-
show ChartCanvas, FillPatternType, BlendMode;
207+
show ChartCanvas, FillPatternType, BlendMode, LinkOrientation, Link;
199208
export 'src/chart/common/chart_context.dart' show ChartContext;
200209
export 'src/chart/common/datum_details.dart'
201210
show DatumDetails, DomainFormatter, MeasureFormatter;
@@ -263,7 +272,11 @@ export 'src/chart/treemap/treemap_label_decorator.dart'
263272
show TreeMapLabelDecorator;
264273
export 'src/chart/treemap/treemap_renderer_config.dart'
265274
show TreeMapRendererConfig, TreeMapTileType;
275+
export 'src/chart/sankey/sankey_chart.dart' show SankeyChart;
276+
export 'src/chart/sankey/sankey_renderer_config.dart' show SankeyRendererConfig;
266277
export 'src/common/color.dart' show Color;
278+
export 'src/chart/link/link_chart.dart' show LinkChart;
279+
export 'src/chart/link/link_renderer_config.dart' show LinkRendererConfig;
267280
export 'src/common/date_time_factory.dart'
268281
show DateTimeFactory, LocalDateTimeFactory, UTCDateTimeFactory;
269282
export 'src/common/gesture_listener.dart' show GestureListener;
@@ -293,6 +306,8 @@ export 'src/common/text_measurement.dart' show TextMeasurement;
293306
export 'src/common/text_style.dart' show TextStyle;
294307
export 'src/data/series.dart' show AttributeKey, Series, TypedAccessorFn;
295308
export 'src/data/tree.dart' show Tree, TreeNode;
309+
export 'src/data/graph.dart' show Graph;
310+
export 'src/data/sankey_graph.dart' show SankeyGraph;
296311
//
297312
// DO NOT ADD ANYTHING BELOW THIS. IT WILL BREAK OPENSOURCE.
298313
//

charts_common/lib/src/chart/bar/bar_label_decorator.dart

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
3232
static const _defaultLabelPlacement = BarLabelPlacement.followMeasureAxis;
3333
static const _defaultHorizontalLabelAnchor = BarLabelAnchor.start;
3434
static const _defaultVerticalLabelAnchor = BarLabelAnchor.end;
35+
static const _defaultlabelVerticalPosition = BarLabelVerticalPosition.middle;
3536
static final _defaultInsideLabelStyle =
3637
TextStyleSpec(fontSize: 12, color: Color.white);
3738
static final _defaultOutsideLabelStyle =
@@ -54,17 +55,21 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
5455
/// For labels drawn inside the bar, configures label anchor position.
5556
final BarLabelAnchor? labelAnchor;
5657

58+
/// For labels on horizontal bars, configures the label's vertical position.
59+
final BarLabelVerticalPosition? labelVerticalPosition;
60+
5761
/// Space before and after the label text.
5862
final int labelPadding;
5963

60-
BarLabelDecorator(
61-
{TextStyleSpec? insideLabelStyleSpec,
62-
TextStyleSpec? outsideLabelStyleSpec,
63-
this.labelAnchor,
64-
this.labelPosition = _defaultLabelPosition,
65-
this.labelPlacement = _defaultLabelPlacement,
66-
this.labelPadding = _defaultLabelPadding})
67-
: insideLabelStyleSpec = insideLabelStyleSpec ?? _defaultInsideLabelStyle,
64+
BarLabelDecorator({
65+
TextStyleSpec? insideLabelStyleSpec,
66+
TextStyleSpec? outsideLabelStyleSpec,
67+
this.labelAnchor,
68+
this.labelPosition = _defaultLabelPosition,
69+
this.labelPlacement = _defaultLabelPlacement,
70+
this.labelPadding = _defaultLabelPadding,
71+
this.labelVerticalPosition = _defaultlabelVerticalPosition,
72+
}) : insideLabelStyleSpec = insideLabelStyleSpec ?? _defaultInsideLabelStyle,
6873
outsideLabelStyleSpec =
6974
outsideLabelStyleSpec ?? _defaultOutsideLabelStyle;
7075

@@ -287,16 +292,19 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
287292
labelElement.textStyle = datumInsideLabelStyle;
288293
labelElement.maxWidth = insideBarWidth;
289294
} else {
290-
// calculatedLabelPosition == LabelPosition.outside
295+
// this block for...
296+
// calculatedLabelPosition == LabelPosition.outside ||
297+
// calculatedLabelPosition == LabelPosition.right
291298
labelElement.textStyle = datumOutsideLabelStyle;
292299
labelElement.maxWidth = outsideBarWidth;
293300
}
294301

295302
// Only calculate and draw label if there's actually space for the label.
296-
if (labelElement.maxWidth! < 0 ||
297-
(labelElement.maxWidthStrategy == null &&
298-
labelElement.measurement.horizontalSliceWidth >
299-
labelElement.maxWidth!)) {
303+
if ((labelElement.maxWidth! < 0 ||
304+
(labelElement.maxWidthStrategy == null &&
305+
labelElement.measurement.horizontalSliceWidth >
306+
labelElement.maxWidth!)) &&
307+
labelVerticalPosition != BarLabelVerticalPosition.top) {
300308
return;
301309
}
302310

@@ -331,8 +339,7 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
331339
}
332340
break;
333341
}
334-
} else {
335-
// calculatedLabelPosition == LabelPosition.outside
342+
} else if (calculatedLabelPosition == BarLabelPosition.outside) {
336343
if (measure < 0 &&
337344
labelPlacement == BarLabelPlacement.opposeAxisBaseline) {
338345
labelX = bounds.left - labelPadding;
@@ -341,13 +348,35 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
341348
labelX = bounds.right + labelPadding;
342349
labelElement.textDirection = TextDirection.ltr;
343350
}
351+
} else {
352+
// calculatedLabelPosition == BarLabelPosition.right
353+
if (measure < 0) {
354+
labelX =
355+
(bounds.right - labelElement.measurement.horizontalSliceWidth)
356+
.round();
357+
} else {
358+
labelX = (bounds.left +
359+
drawBounds.width -
360+
labelElement.measurement.horizontalSliceWidth)
361+
.round();
362+
}
344363
}
345364

346-
// Center the label inside the bar.
347-
final labelY = (bounds.top +
348-
(bounds.bottom - bounds.top) / 2 -
349-
labelElement.measurement.verticalSliceWidth / 2)
350-
.round();
365+
// Calculate label's y position based on BarLabelVerticalPosition.
366+
final labelY;
367+
if (labelVerticalPosition == BarLabelVerticalPosition.middle) {
368+
// Center the label inside the bar.
369+
labelY = (bounds.top +
370+
(bounds.bottom - bounds.top) / 2 -
371+
labelElement.measurement.verticalSliceWidth / 2)
372+
.round();
373+
} else {
374+
/// labelVerticalPosition == BarLabelVerticalPosition.top
375+
labelY = (bounds.top -
376+
labelElement.measurement.verticalSliceWidth -
377+
labelPadding)
378+
.round();
379+
}
351380

352381
canvas.drawText(labelElement, labelX, labelY);
353382
}
@@ -368,7 +397,8 @@ class BarLabelDecorator<D> extends BarRendererDecorator<D> {
368397
..color = labelSpec?.color ?? Color.black
369398
..fontFamily = labelSpec?.fontFamily
370399
..fontSize = labelSpec?.fontSize ?? 12
371-
..lineHeight = labelSpec?.lineHeight;
400+
..lineHeight = labelSpec?.lineHeight
401+
..fontWeight = labelSpec?.fontWeight ?? "400";
372402
}
373403

374404
/// Helper function to get datum specific style
@@ -409,6 +439,10 @@ enum BarLabelPosition {
409439

410440
/// Always place label on the inside.
411441
inside,
442+
443+
/// Right align the label with the horizontal bars. The label will be inside
444+
/// or above the bar based on the BarLabelVerticalPosition.
445+
right,
412446
}
413447

414448
/// Configures where to place the label relative to the axis.
@@ -435,3 +469,12 @@ enum BarLabelAnchor {
435469
/// Anchor to the measure end.
436470
end,
437471
}
472+
473+
/// Configures where to place labels vertically on horizontal bars.
474+
enum BarLabelVerticalPosition {
475+
/// Anchors label to be on top of bar
476+
top,
477+
478+
/// Anchors label to be inline with bar
479+
middle,
480+
}

charts_common/lib/src/chart/bar/bar_lane_renderer.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
133133
final barGroupWeight = series.getAttr(barGroupWeightKey);
134134
final allBarGroupWeights = series.getAttr(allBarGroupWeightsKey);
135135
final measureAxisPosition = measureAxis.getLocation(0.0);
136-
final maxMeasureValue = _getMaxMeasureValue(measureAxis);
136+
final measureFn = series.measureFn;
137137

138138
// Create a fake series for [BarLabelDecorator] to use when looking up the
139139
// index of each datum.
@@ -173,6 +173,14 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
173173
var animatingBar =
174174
barStackList.firstWhereOrNull((bar) => bar.key == barKey);
175175

176+
final renderNegativeLanes =
177+
(config as BarLaneRendererConfig).renderNegativeLanes;
178+
179+
final measureValue = measureFn(0);
180+
final measureIsNegative = measureValue != null && measureValue < 0;
181+
final maxMeasureValue = _getMaxMeasureValue(
182+
measureAxis, measureIsNegative && renderNegativeLanes);
183+
176184
// If we don't have any existing bar element, create a new bar and have
177185
// it animate in from the domain axis.
178186
if (animatingBar == null) {
@@ -197,7 +205,7 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
197205
numBarGroups: barGroupCount,
198206
strokeWidthPx: config.strokeWidthPx,
199207
measureIsNull: false,
200-
measureIsNegative: false);
208+
measureIsNegative: renderNegativeLanes && measureIsNegative);
201209

202210
barStackList.add(animatingBar);
203211
} else {
@@ -227,7 +235,7 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
227235
numBarGroups: barGroupCount,
228236
strokeWidthPx: config.strokeWidthPx,
229237
measureIsNull: false,
230-
measureIsNegative: false);
238+
measureIsNegative: renderNegativeLanes && measureIsNegative);
231239

232240
animatingBar.setNewTarget(barElement);
233241

@@ -245,7 +253,7 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
245253
seriesList[0].getAttr(measureAxisKey) as ImmutableAxis<num>;
246254

247255
final measureAxisPosition = measureAxis.getLocation(0.0);
248-
final maxMeasureValue = _getMaxMeasureValue(measureAxis);
256+
final maxMeasureValue = _getMaxMeasureValue(measureAxis, false);
249257

250258
final barGroupIndex = 0;
251259
final previousBarGroupWeight = 0.0;
@@ -344,10 +352,10 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
344352
}
345353

346354
/// Gets the maximum measure value that will fit in the draw area.
347-
num _getMaxMeasureValue(ImmutableAxis<num> measureAxis) {
355+
num _getMaxMeasureValue(ImmutableAxis<num> measureAxis, bool laneIsNegative) {
348356
final pos = chart.vertical
349357
? chart.drawAreaBounds.top
350-
: isRtl
358+
: ((isRtl && !laneIsNegative) || (!isRtl && laneIsNegative))
351359
? chart.drawAreaBounds.left
352360
: chart.drawAreaBounds.right;
353361

0 commit comments

Comments
 (0)