Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: packages/charted/lib/core/scales/ordinal_scale.dart

Issue 2213693002: Updated charted DEP to 0.4.X (Closed) Base URL: https://github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 1 //
2 // Copyright 2014 Google Inc. All rights reserved. 2 // Copyright 2014 Google Inc. All rights reserved.
3 // 3 //
4 // Use of this source code is governed by a BSD-style 4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at 5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd 6 // https://developers.google.com/open-source/licenses/bsd
7 // 7 //
8 part of charted.core.scales; 8 part of charted.core.scales;
9 9
10 class _OrdinalScale implements OrdinalScale { 10 class _OrdinalScale implements OrdinalScale {
(...skipping 21 matching lines...) Expand all
32 if (!_index.containsKey(value)) { 32 if (!_index.containsKey(value)) {
33 _index[value] = domain.length; 33 _index[value] = domain.length;
34 _domain.add(value); 34 _domain.add(value);
35 } 35 }
36 return _range.isNotEmpty 36 return _range.isNotEmpty
37 ? _range.elementAt(_index[value] % _range.length) 37 ? _range.elementAt(_index[value] % _range.length)
38 : 0; 38 : 0;
39 } 39 }
40 40
41 @override 41 @override
42 dynamic invert(num value) { 42 dynamic invert(value) {
43 int position = _range.indexOf(value); 43 int position = _range.indexOf(value);
44 return position > -1 && position < _domain.length 44 return position > -1 && position < _domain.length
45 ? _domain[position] 45 ? _domain[position]
46 : null; 46 : null;
47 } 47 }
48 48
49 @override 49 @override
50 set domain(Iterable values) { 50 set domain(Iterable values) {
51 _domain = []; 51 _domain = [];
52 _index.clear(); 52 _index.clear();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 @override 87 @override
88 void rangeRoundBands(Iterable range, 88 void rangeRoundBands(Iterable range,
89 [double padding = 0.0, double outerPadding]) => 89 [double padding = 0.0, double outerPadding]) =>
90 _setRangeRoundBands( 90 _setRangeRoundBands(
91 this, range, padding, outerPadding == null ? padding : outerPadding); 91 this, range, padding, outerPadding == null ? padding : outerPadding);
92 92
93 @override 93 @override
94 num get rangeBand => _rangeBand; 94 num get rangeBand => _rangeBand;
95 95
96 @override 96 @override
97 FormatFunction createTickFormatter([String format]) => identityFunction; 97 FormatFunction createTickFormatter([String format]) =>
98 (String s) => identityFunction/*<String>*/(s);
98 99
99 @override 100 @override
100 Iterable get ticks => _domain; 101 Iterable get ticks => _domain;
101 102
102 @override 103 @override
103 OrdinalScale clone() => new _OrdinalScale._clone(this); 104 OrdinalScale clone() => new _OrdinalScale._clone(this);
104 105
105 List _steps(start, step) => 106 List _steps(start, step) =>
106 new Range(domain.length).map((num i) => start + step * i).toList(); 107 new Range(domain.length).map((num i) => start + step * i).toList();
107 108
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (scale.domain.isNotEmpty) { 147 if (scale.domain.isNotEmpty) {
147 scale._reset(scale); 148 scale._reset(scale);
148 } 149 }
149 } 150 }
150 151
151 static void _setRangeRoundBands(_OrdinalScale scale, Iterable range, 152 static void _setRangeRoundBands(_OrdinalScale scale, Iterable range,
152 double padding, double outerPadding) { 153 double padding, double outerPadding) {
153 scale._reset = (_OrdinalScale s) { 154 scale._reset = (_OrdinalScale s) {
154 var start = range.first, 155 var start = range.first,
155 stop = range.last, 156 stop = range.last,
156 step = ((stop - start) / 157 step =
157 (s.domain.length - padding + 2 * outerPadding)).floor(), 158 ((stop - start) / (s.domain.length - padding + 2 * outerPadding))
159 .floor(),
158 error = stop - start - (s.domain.length - padding) * step; 160 error = stop - start - (s.domain.length - padding) * step;
159 161
160 s._range = s._steps(start + (error / 2).round(), step); 162 s._range = s._steps(start + (error / 2).round(), step);
161 s._rangeBand = (step * (1 - padding)).round(); 163 s._rangeBand = (step * (1 - padding)).round();
162 s._rangeExtent = new Extent(start, stop); 164 s._rangeExtent = new Extent(start, stop);
163 }; 165 };
164 if (scale.domain.isNotEmpty) { 166 if (scale.domain.isNotEmpty) {
165 scale._reset(scale); 167 scale._reset(scale);
166 } 168 }
167 } 169 }
168 170
169 // 171 //
170 // Properties that are valid only on quantitative scales. 172 // Properties that are valid only on quantitative scales.
171 // 173 //
172 174
173 bool clamp; 175 bool clamp;
174 bool nice; 176 bool nice;
175 bool rounded; 177 bool rounded;
176 int ticksCount; 178 int ticksCount;
177 } 179 }
OLDNEW
« no previous file with comments | « packages/charted/lib/core/scales/linear_scale.dart ('k') | packages/charted/lib/core/scales/time_scale.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698