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; | 15 double percentChange; |
16 | 16 |
17 StockArrow({ Object key, this.percentChange }) : super(key: key); | 17 StockArrow({ Object key, this.percentChange }) : super(key: key); |
18 | 18 |
| 19 void syncFields(StockArrow source) { |
| 20 percentChange = source.percentChange; |
| 21 super.syncFields(source); |
| 22 } |
| 23 |
19 int _colorIndexForPercentChange(double percentChange) { | 24 int _colorIndexForPercentChange(double percentChange) { |
20 double maxPercent = 10.0; | 25 double maxPercent = 10.0; |
21 double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) /
maxPercent; | 26 double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) /
maxPercent; |
22 return 100 + (normalizedPercentChange * 8.0).floor() * 100; | 27 return 100 + (normalizedPercentChange * 8.0).floor() * 100; |
23 } | 28 } |
24 | 29 |
25 Color _colorForPercentChange(double percentChange) { | 30 Color _colorForPercentChange(double percentChange) { |
26 if (percentChange > 0) | 31 if (percentChange > 0) |
27 return colors.Green[_colorIndexForPercentChange(percentChange)]; | 32 return colors.Green[_colorIndexForPercentChange(percentChange)]; |
28 return colors.Red[_colorIndexForPercentChange(percentChange)]; | 33 return colors.Red[_colorIndexForPercentChange(percentChange)]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 canvas.restore(); | 70 canvas.restore(); |
66 }); | 71 }); |
67 | 72 |
68 return new Container( | 73 return new Container( |
69 child: arrow, | 74 child: arrow, |
70 width: size, | 75 width: size, |
71 height: size, | 76 height: size, |
72 margin: const EdgeDims.symmetric(horizontal: 5.0)); | 77 margin: const EdgeDims.symmetric(horizontal: 5.0)); |
73 } | 78 } |
74 } | 79 } |
OLD | NEW |