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

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

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 /// Log scale is similar to linear scale, except there's a logarithmic 10 /// Log scale is similar to linear scale, except there's a logarithmic
11 /// transform that is applied to the input domain value before the output 11 /// transform that is applied to the input domain value before the output
12 /// range value is computed. 12 /// range value is computed.
13 /// 13 ///
14 /// The mapping to the output range value y can be expressed as a function 14 /// The mapping to the output range value y can be expressed as a function
15 /// of the input domain value x: y = m log(x) + b. 15 /// of the input domain value x: y = m log(x) + b.
16 /// 16 ///
17 /// As log(0) is negative infinity, a log scale must have either an 17 /// As log(0) is negative infinity, a log scale must have either an
18 /// exclusively-positive or exclusively-negative domain; the domain must not 18 /// exclusively-positive or exclusively-negative domain; the domain must not
19 /// include or cross zero. 19 /// include or cross zero.
20 class LogScale implements Scale { 20 class LogScale implements Scale {
21 static const defaultBase = 10; 21 static const defaultBase = 10;
22 static const defaultDomain = const [1, 10]; 22 static const defaultDomain = const [1, 10];
23 static final negativeNumbersRoundFunctionsPair = 23 static final negativeNumbersRoundFunctionsPair =
24 new RoundingFunctions( 24 new RoundingFunctions((x) => -((-x).floor()), (x) => -((-x).ceil()));
25 (x) => -((-x).floor()),
26 (x) => -((-x).ceil()));
27 25
28 final LinearScale _linear; 26 final LinearScale _linear;
29 27
30 bool _nice = false; 28 bool _nice = false;
31 int _base = defaultBase; 29 int _base = defaultBase;
32 int _ticksCount = 10; 30 int _ticksCount = 10;
33 bool _positive = true; 31 bool _positive = true;
34 List _domain = defaultDomain; 32 List _domain = defaultDomain;
35 33
36 LogScale() : _linear = new LinearScale(); 34 LogScale() : _linear = new LinearScale();
37 35
38 LogScale._clone(LogScale source) 36 LogScale._clone(LogScale source)
39 : _linear = source._linear.clone(), 37 : _linear = source._linear.clone(),
40 _domain = source._domain.toList(), 38 _domain = source._domain.toList(),
41 _positive = source._positive, 39 _positive = source._positive,
42 _base = source._base, 40 _base = source._base,
43 _nice = source._nice, 41 _nice = source._nice,
44 _ticksCount = source._ticksCount; 42 _ticksCount = source._ticksCount;
45 43
46 num _log(x) => (_positive ? 44 num _log(x) =>
47 math.log(x < 0 ? 0 : x) : -math.log(x > 0 ? 0 : -x)) / math.log(base); 45 (_positive ? math.log(x < 0 ? 0 : x) : -math.log(x > 0 ? 0 : -x)) /
46 math.log(base);
48 47
49 num _pow(x) => _positive ? math.pow(base, x) : -math.pow(base, -x); 48 num _pow(x) => _positive ? math.pow(base, x) : -math.pow(base, -x);
50 49
51 set base(int value) { 50 set base(int value) {
52 if (_base != value) { 51 if (_base != value) {
53 _base = value; 52 _base = value;
54 _reset(); 53 _reset();
55 } 54 }
56 } 55 }
57 56
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return d / _pow((_log(d) + e).ceil()) <= k ? logFormatFunction(d) : ''; 170 return d / _pow((_log(d) + e).ceil()) <= k ? logFormatFunction(d) : '';
172 } else { 171 } else {
173 return d / _pow((_log(d) + e).floor()) <= k ? logFormatFunction(d) : ''; 172 return d / _pow((_log(d) + e).floor()) <= k ? logFormatFunction(d) : '';
174 } 173 }
175 }; 174 };
176 } 175 }
177 176
178 @override 177 @override
179 LogScale clone() => new LogScale._clone(this); 178 LogScale clone() => new LogScale._clone(this);
180 } 179 }
OLDNEW
« no previous file with comments | « packages/charted/lib/core/scales/linear_scale.dart ('k') | packages/charted/lib/core/scales/ordinal_scale.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698