1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-11 23:39:14 +00:00

Web charts common update (#111)

This commit is contained in:
Brett Morgan
2019-07-10 06:37:53 +10:00
committed by GitHub
parent eac7833d1d
commit 3af5bbf125
145 changed files with 2491 additions and 2687 deletions

View File

@@ -38,14 +38,14 @@ void main() {
Rectangle bounds;
setUp(() {
decorator = new TestComparisonPointsDecorator<num>();
bounds = new Rectangle<int>(0, 0, 100, 100);
decorator = TestComparisonPointsDecorator<num>();
bounds = Rectangle<int>(0, 0, 100, 100);
});
group('compute bounded points', () {
test('with line inside bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 10.0,
xLower: 5.0,
xUpper: 50.0,
@@ -66,8 +66,8 @@ void main() {
});
test('with line entirely above bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 10.0,
xLower: 5.0,
xUpper: 50.0,
@@ -82,8 +82,8 @@ void main() {
});
test('with line entirely below bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 10.0,
xLower: 5.0,
xUpper: 50.0,
@@ -98,8 +98,8 @@ void main() {
});
test('with line entirely left of bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: -10.0,
xLower: -5.0,
xUpper: -50.0,
@@ -114,8 +114,8 @@ void main() {
});
test('with line entirely right of bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 110.0,
xLower: 105.0,
xUpper: 150.0,
@@ -130,8 +130,8 @@ void main() {
});
test('with horizontal line extending beyond bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 10.0,
xLower: -10.0,
xUpper: 110.0,
@@ -152,8 +152,8 @@ void main() {
});
test('with vertical line extending beyond bounds', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 20.0,
xLower: 20.0,
xUpper: 20.0,
@@ -174,8 +174,8 @@ void main() {
});
test('with diagonal from top left to bottom right', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 50.0,
xLower: -50.0,
xUpper: 150.0,
@@ -196,8 +196,8 @@ void main() {
});
test('with diagonal from bottom left to top right', () {
final element = new PointRendererElement<num>()
..point = new DatumPoint<num>(
final element = PointRendererElement<num>()
..point = DatumPoint<num>(
x: 50.0,
xLower: -50.0,
xUpper: 150.0,

View File

@@ -42,19 +42,19 @@ void main() {
setUp(() {
var myFakeDesktopData = [
// This datum should get a default bounds line radius value.
new MyRow('MyCampaign1', 0, 5, 3.0, null, null),
new MyRow('MyCampaign2', 10, 25, 5.0, 4.0, 'shape 1'),
new MyRow('MyCampaign3', 12, 75, 4.0, 4.0, 'shape 2'),
MyRow('MyCampaign1', 0, 5, 3.0, null, null),
MyRow('MyCampaign2', 10, 25, 5.0, 4.0, 'shape 1'),
MyRow('MyCampaign3', 12, 75, 4.0, 4.0, 'shape 2'),
// This datum should always get default radius values.
new MyRow('MyCampaign4', 13, 225, null, null, null),
MyRow('MyCampaign4', 13, 225, null, null, null),
];
final maxMeasure = 300;
numericSeriesList = [
new MutableSeries<int>(new Series<MyRow, int>(
MutableSeries<int>(Series<MyRow, int>(
id: 'Desktop',
colorFn: (MyRow row, _) {
colorFn: (row, _) {
// Color bucket the measure column value into 3 distinct colors.
final bucket = row.clickCount / maxMeasure;
@@ -66,20 +66,20 @@ void main() {
return MaterialPalette.green.shadeDefault;
}
},
domainFn: (MyRow row, _) => row.campaign,
measureFn: (MyRow row, _) => row.clickCount,
measureOffsetFn: (MyRow row, _) => 0,
radiusPxFn: (MyRow row, _) => row.radius,
domainFn: (row, _) => row.campaign,
measureFn: (row, _) => row.clickCount,
measureOffsetFn: (row, _) => 0,
radiusPxFn: (row, _) => row.radius,
data: myFakeDesktopData)
// Define a bounds line radius function.
..setAttribute(boundsLineRadiusPxFnKey,
(int index) => myFakeDesktopData[index].boundsRadius))
(index) => myFakeDesktopData[index].boundsRadius))
];
});
group('preprocess', () {
test('with numeric data and simple points', () {
renderer = new PointRenderer<int>(config: new PointRendererConfig());
renderer = PointRenderer<int>(config: PointRendererConfig());
renderer.preprocessSeries(numericSeriesList);
@@ -115,9 +115,8 @@ void main() {
});
test('with numeric data and missing radiusPxFn', () {
renderer = new PointRenderer<int>(
config:
new PointRendererConfig(radiusPx: 2.0, boundsLineRadiusPx: 1.5));
renderer = PointRenderer<int>(
config: PointRendererConfig(radiusPx: 2.0, boundsLineRadiusPx: 1.5));
// Remove the radius functions to test configured defaults.
numericSeriesList[0].radiusPxFn = null;
@@ -145,10 +144,10 @@ void main() {
});
test('with custom symbol renderer ID in data', () {
renderer = new PointRenderer<int>(config: new PointRendererConfig());
renderer = PointRenderer<int>(config: PointRendererConfig());
numericSeriesList[0].setAttr(pointSymbolRendererFnKey,
(int index) => numericSeriesList[0].data[index].shape as String);
(index) => numericSeriesList[0].data[index].shape as String);
renderer.preprocessSeries(numericSeriesList);
@@ -167,10 +166,10 @@ void main() {
});
test('with custom symbol renderer ID in series and data', () {
renderer = new PointRenderer<int>(config: new PointRendererConfig());
renderer = PointRenderer<int>(config: PointRendererConfig());
numericSeriesList[0].setAttr(pointSymbolRendererFnKey,
(int index) => numericSeriesList[0].data[index].shape as String);
(index) => numericSeriesList[0].data[index].shape as String);
numericSeriesList[0].setAttr(pointSymbolRendererIdKey, 'shape 0');
renderer.preprocessSeries(numericSeriesList);

View File

@@ -44,34 +44,34 @@ void main() {
setUp(() {
var myFakeDesktopData = [
// This datum should get a default bounds line radius value.
new MyRow('MyCampaign1', 0, 0, 0, 3.0, null, null),
new MyRow('MyCampaign2', 10, 10, 12, 5.0, 4.0, 'shape 1'),
new MyRow('MyCampaign3', 10, 10, 14, 4.0, 4.0, 'shape 2'),
MyRow('MyCampaign1', 0, 0, 0, 3.0, null, null),
MyRow('MyCampaign2', 10, 10, 12, 5.0, 4.0, 'shape 1'),
MyRow('MyCampaign3', 10, 10, 14, 4.0, 4.0, 'shape 2'),
// This datum should always get default radius values.
new MyRow('MyCampaign4', 13, 12, 15, null, null, null),
MyRow('MyCampaign4', 13, 12, 15, null, null, null),
];
numericSeriesList = [
new MutableSeries<int>(new Series<MyRow, int>(
MutableSeries<int>(Series<MyRow, int>(
id: 'Desktop',
colorFn: (MyRow row, _) => MaterialPalette.blue.shadeDefault,
domainFn: (MyRow row, _) => row.campaign,
domainLowerBoundFn: (MyRow row, _) => row.campaignLower,
domainUpperBoundFn: (MyRow row, _) => row.campaignUpper,
measureFn: (MyRow row, _) => 0,
measureOffsetFn: (MyRow row, _) => 0,
radiusPxFn: (MyRow row, _) => row.radius,
colorFn: (row, _) => MaterialPalette.blue.shadeDefault,
domainFn: (row, _) => row.campaign,
domainLowerBoundFn: (row, _) => row.campaignLower,
domainUpperBoundFn: (row, _) => row.campaignUpper,
measureFn: (row, _) => 0,
measureOffsetFn: (row, _) => 0,
radiusPxFn: (row, _) => row.radius,
data: myFakeDesktopData)
// Define a bounds line radius function.
..setAttribute(boundsLineRadiusPxFnKey,
(int index) => myFakeDesktopData[index].boundsRadius))
(index) => myFakeDesktopData[index].boundsRadius))
];
});
group('preprocess', () {
test('with numeric data and simple points', () {
renderer = new SymbolAnnotationRenderer<int>(
config: new SymbolAnnotationRendererConfig());
renderer = SymbolAnnotationRenderer<int>(
config: SymbolAnnotationRendererConfig());
renderer.preprocessSeries(numericSeriesList);