1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

web/chart: fix sample (#909)

This commit is contained in:
Brett Morgan
2021-10-07 08:10:34 +11:00
committed by GitHub
parent 0fe216a1cf
commit 2d9ba2f9eb
118 changed files with 3655 additions and 3511 deletions

View File

@@ -41,11 +41,12 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
SelectionScatterPlotHighlight(this.seriesList, {this.animate});
const SelectionScatterPlotHighlight(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [ScatterPlotChart] with sample data and no transition.
factory SelectionScatterPlotHighlight.withSampleData() {
return new SelectionScatterPlotHighlight(
return SelectionScatterPlotHighlight(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -57,49 +58,49 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory SelectionScatterPlotHighlight.withRandomData() {
return new SelectionScatterPlotHighlight(_createRandomData());
return SelectionScatterPlotHighlight(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble();
makeRadius(int value) => (random.nextInt(value) + 2).toDouble();
final data = [
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
'circle', null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
// Render a hollow circle, filled in with white.
new LinearSales(random.nextInt(100), random.nextInt(100),
makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
'circle', charts.MaterialPalette.white, 2.0),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
'circle', null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
// Render a hollow circle, filled in with white.
new LinearSales(random.nextInt(100), random.nextInt(100),
makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0),
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
null, null, null),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
'circle', charts.MaterialPalette.white, 2.0),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
null, null),
// Render a hollow square, filled in with white.
new LinearSales(random.nextInt(100), random.nextInt(100),
makeRadius(4) + 4, null, charts.MaterialPalette.white, 2.0),
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
null, charts.MaterialPalette.white, 2.0),
];
final maxMeasure = 100;
const maxMeasure = 100;
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (LinearSales sales, _) {
// Color bucket the measure column value into 3 distinct colors.
@@ -131,7 +132,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.ScatterPlotChart(seriesList,
return charts.ScatterPlotChart(seriesList,
animate: animate,
behaviors: [
// Optional - Configures a [LinePointHighlighter] behavior with
@@ -143,7 +144,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
// in an empty list. An empty list is necessary because passing in a
// null value will be treated the same as not passing in a value at
// all.
new charts.LinePointHighlighter(
charts.LinePointHighlighter(
showHorizontalFollowLine:
charts.LinePointHighlighterFollowLineType.nearest,
showVerticalFollowLine:
@@ -153,44 +154,42 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
// highlighter. Changing the trigger to tap and drag allows the
// highlighter to follow the dragging gesture but it is not
// recommended to be used when pan/zoom behavior is enabled.
new charts.SelectNearest(
charts.SelectNearest(
eventTrigger: charts.SelectionTrigger.tapAndDrag),
],
// Configure the point renderer to have a map of custom symbol
// renderers.
defaultRenderer:
new charts.PointRendererConfig<num>(customSymbolRenderers: {
'circle': new charts.CircleSymbolRenderer(),
'rect': new charts.RectSymbolRenderer(),
charts.PointRendererConfig<num>(customSymbolRenderers: {
'circle': charts.CircleSymbolRenderer(),
'rect': charts.RectSymbolRenderer(),
}));
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5, 3.0, 'circle', null, null),
new LinearSales(10, 25, 5.0, null, null, null),
new LinearSales(12, 75, 4.0, null, null, null),
LinearSales(0, 5, 3.0, 'circle', null, null),
LinearSales(10, 25, 5.0, null, null, null),
LinearSales(12, 75, 4.0, null, null, null),
// Render a hollow circle, filled in with white.
new LinearSales(
13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0),
new LinearSales(16, 50, 4.0, null, null, null),
new LinearSales(24, 75, 3.0, null, null, null),
new LinearSales(25, 100, 3.0, 'circle', null, null),
new LinearSales(34, 150, 5.0, null, null, null),
new LinearSales(37, 10, 4.5, null, null, null),
LinearSales(13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0),
LinearSales(16, 50, 4.0, null, null, null),
LinearSales(24, 75, 3.0, null, null, null),
LinearSales(25, 100, 3.0, 'circle', null, null),
LinearSales(34, 150, 5.0, null, null, null),
LinearSales(37, 10, 4.5, null, null, null),
// Render a hollow circle, filled in with white.
new LinearSales(
45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0),
new LinearSales(52, 15, 4.0, null, null, null),
LinearSales(45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0),
LinearSales(52, 15, 4.0, null, null, null),
// Render a hollow square, filled in with white.
new LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0),
LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0),
];
final maxMeasure = 300;
const maxMeasure = 300;
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
// Providing a color function is optional.
colorFn: (LinearSales sales, _) {