OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'package:sky/framework/fn2.dart'; | 5 import 'package:sky/framework/fn2.dart'; |
6 import 'package:vector_math/vector_math.dart'; | 6 import 'package:vector_math/vector_math.dart'; |
7 import 'package:sky/framework/rendering/box.dart'; | 7 import 'package:sky/framework/rendering/box.dart'; |
8 import 'package:sky/framework/rendering/object.dart'; | 8 import 'package:sky/framework/rendering/object.dart'; |
9 import 'package:sky/framework/theme2/colors.dart' as colors; | 9 import 'package:sky/framework/theme2/colors.dart' as colors; |
10 | 10 |
11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
12 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
13 | 13 |
14 class StockArrow extends Component { | 14 class StockArrow extends Component { |
15 double percentChange; | |
16 | 15 |
17 StockArrow({ Object key, this.percentChange }) : super(key: key); | 16 StockArrow({ Object key, this.percentChange }) : super(key: key); |
18 | 17 |
| 18 final double percentChange; |
| 19 |
19 int _colorIndexForPercentChange(double percentChange) { | 20 int _colorIndexForPercentChange(double percentChange) { |
20 double maxPercent = 10.0; | 21 double maxPercent = 10.0; |
21 double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) /
maxPercent; | 22 double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) /
maxPercent; |
22 return 100 + (normalizedPercentChange * 8.0).floor() * 100; | 23 return 100 + (normalizedPercentChange * 8.0).floor() * 100; |
23 } | 24 } |
24 | 25 |
25 Color _colorForPercentChange(double percentChange) { | 26 Color _colorForPercentChange(double percentChange) { |
26 if (percentChange > 0) | 27 if (percentChange > 0) |
27 return colors.Green[_colorIndexForPercentChange(percentChange)]; | 28 return colors.Green[_colorIndexForPercentChange(percentChange)]; |
28 return colors.Red[_colorIndexForPercentChange(percentChange)]; | 29 return colors.Red[_colorIndexForPercentChange(percentChange)]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 65 |
65 canvas.restore(); | 66 canvas.restore(); |
66 }); | 67 }); |
67 | 68 |
68 return new Container( | 69 return new Container( |
69 child: arrow, | 70 child: arrow, |
70 width: size, | 71 width: size, |
71 height: size, | 72 height: size, |
72 margin: const EdgeDims.symmetric(horizontal: 5.0)); | 73 margin: const EdgeDims.symmetric(horizontal: 5.0)); |
73 } | 74 } |
| 75 |
74 } | 76 } |
OLD | NEW |