1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +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

@@ -35,11 +35,12 @@ class ShapesScatterPlotChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
ShapesScatterPlotChart(this.seriesList, {this.animate});
const ShapesScatterPlotChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [ScatterPlotChart] with sample data and no transition.
factory ShapesScatterPlotChart.withSampleData() {
return new ShapesScatterPlotChart(
return ShapesScatterPlotChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -51,49 +52,49 @@ class ShapesScatterPlotChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory ShapesScatterPlotChart.withRandomData() {
return new ShapesScatterPlotChart(_createRandomData());
return ShapesScatterPlotChart(_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.
@@ -125,43 +126,41 @@ class ShapesScatterPlotChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.ScatterPlotChart(seriesList,
return charts.ScatterPlotChart(seriesList,
animate: animate,
// 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, _) {