This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
base_bar_renderer_config.dart
124 lines (108 loc) · 4.81 KB
/
base_bar_renderer_config.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
// for details.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'package:collection/equality.dart' show ListEquality;
import '../common/chart_canvas.dart' show FillPatternType;
import '../common/series_renderer_config.dart'
show RendererAttributes, SeriesRendererConfig;
import '../layout/layout_view.dart' show LayoutViewConfig;
import '../../common/symbol_renderer.dart' show SymbolRenderer;
/// Shared configuration for bar chart renderers.
///
/// Bar renderers support 4 different modes of rendering multiple series on the
/// chart, configured by the grouped and stacked flags.
/// * grouped - Render bars for each series that shares a domain value
/// side-by-side.
/// * stacked - Render bars for each series that shares a domain value in a
/// stack, ordered in the same order as the series list.
/// * grouped-stacked: Render bars for each series that shares a domain value in
/// a group of bar stacks. Each stack will contain all the series that share a
/// series category.
/// * floating style - When grouped and stacked are both false, all bars that
/// share a domain value will be rendered in the same domain space. Each datum
/// should be configured with a measure offset to position its bar along the
/// measure axis. Bars will freely overlap if their measure values and measure
/// offsets overlap. Note that bars for each series will be rendered in order,
/// such that bars from the last series will be "on top" of bars from previous
/// series.
abstract class BaseBarRendererConfig<T, D> extends LayoutViewConfig
implements SeriesRendererConfig<T, D> {
final String customRendererId;
final SymbolRenderer symbolRenderer;
final List<int> barWeights;
/// Defines the way multiple series of bars are rendered per domain.
final BarGroupingType groupingType;
final int minBarLengthPx;
final FillPatternType fillPattern;
final double stackHorizontalSeparator;
/// Stroke width of the target line.
final double strokeWidthPx;
final rendererAttributes = new RendererAttributes();
BaseBarRendererConfig(
{this.customRendererId,
this.barWeights,
this.groupingType = BarGroupingType.grouped,
this.minBarLengthPx = 0,
this.fillPattern,
this.stackHorizontalSeparator,
this.strokeWidthPx = 0.0,
this.symbolRenderer});
/// Whether or not the bars should be organized into groups.
bool get grouped =>
groupingType == BarGroupingType.grouped ||
groupingType == BarGroupingType.groupedStacked;
/// Whether or not the bars should be organized into stacks.
bool get stacked =>
groupingType == BarGroupingType.stacked ||
groupingType == BarGroupingType.groupedStacked;
@override
bool operator ==(o) {
if (identical(this, o)) {
return true;
}
if (!(o is BaseBarRendererConfig)) {
return false;
}
return o.customRendererId == customRendererId &&
new ListEquality().equals(o.barWeights, barWeights) &&
o.fillPattern == fillPattern &&
o.groupingType == groupingType &&
o.minBarLengthPx == minBarLengthPx &&
o.stackHorizontalSeparator == stackHorizontalSeparator &&
o.strokeWidthPx == strokeWidthPx &&
o.symbolRenderer == symbolRenderer;
}
int get hashcode {
var hash = 1;
hash = hash * 31 + (customRendererId?.hashCode ?? 0);
hash = hash * 31 + (barWeights?.hashCode ?? 0);
hash = hash * 31 + (fillPattern?.hashCode ?? 0);
hash = hash * 31 + (groupingType?.hashCode ?? 0);
hash = hash * 31 + (minBarLengthPx?.hashCode ?? 0);
hash = hash * 31 + (stackHorizontalSeparator?.hashCode ?? 0);
hash = hash * 31 + (strokeWidthPx?.hashCode ?? 0);
hash = hash * 31 + (symbolRenderer?.hashCode ?? 0);
return hash;
}
}
/// Defines the way multiple series of bars are renderered per domain.
///
/// * [grouped] - Render bars for each series that shares a domain value
/// side-by-side.
/// * [stacked] - Render bars for each series that shares a domain value in a
/// stack, ordered in the same order as the series list.
/// * [groupedStacked]: Render bars for each series that shares a domain value
/// in a group of bar stacks. Each stack will contain all the series that
/// share a series category.
enum BarGroupingType { grouped, groupedStacked, stacked }