OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 import 'dart:math'; | |
6 import 'package:sky/framework/fn.dart'; | |
7 import 'package:sky/framework/layout.dart'; | |
8 | |
9 class StockArrow extends Component { | |
10 static final Style _style = new Style(''' | |
11 width: 40px; | |
12 height: 40px; | |
13 align-items: center; | |
14 justify-content: center; | |
15 border-radius: 40px; | |
16 margin-right: 16px; | |
17 border: 1px solid transparent;''' | |
18 ); | |
19 | |
20 static final Style _upStyle = new Style(''' | |
21 width: 0; | |
22 height: 0; | |
23 border-left: 9px solid transparent; | |
24 border-right: 9px solid transparent; | |
25 margin-bottom: 3px; | |
26 border-bottom: 9px solid white;''' | |
27 ); | |
28 | |
29 static final Style _downStyle = new Style(''' | |
30 width: 0; | |
31 height: 0; | |
32 border-left: 9px solid transparent; | |
33 border-right: 9px solid transparent; | |
34 margin-top: 3px; | |
35 border-top: 9px solid white''' | |
36 ); | |
37 | |
38 double percentChange; | |
39 | |
40 StockArrow({ Object key, this.percentChange }) : super(key: key); | |
41 | |
42 // TODO(abarth): These should use sky/framework/theme/colors.dart. | |
43 final List<String> _kRedColors = [ | |
44 '#E57373', | |
45 '#EF5350', | |
46 '#F44336', | |
47 '#E53935', | |
48 '#D32F2F', | |
49 '#C62828', | |
50 '#B71C1C', | |
51 ]; | |
52 | |
53 // TODO(abarth): These should use sky/framework/theme/colors.dart. | |
54 final List<String> _kGreenColors = [ | |
55 '#81C784', | |
56 '#66BB6A', | |
57 '#4CAF50', | |
58 '#43A047', | |
59 '#388E3C', | |
60 '#2E7D32', | |
61 '#1B5E20', | |
62 ]; | |
63 | |
64 int _colorIndexForPercentChange(double percentChange) { | |
65 // Currently the max is 10%. | |
66 double maxPercent = 10.0; | |
67 return max(0, ((percentChange.abs() / maxPercent) * _kGreenColors.length).fl
oor()); | |
68 } | |
69 | |
70 String _colorForPercentChange(double percentChange) { | |
71 if (percentChange > 0) | |
72 return _kGreenColors[_colorIndexForPercentChange(percentChange)]; | |
73 return _kRedColors[_colorIndexForPercentChange(percentChange)]; | |
74 } | |
75 | |
76 UINode build() { | |
77 String border = _colorForPercentChange(percentChange).toString(); | |
78 bool up = percentChange > 0; | |
79 String type = up ? 'bottom' : 'top'; | |
80 | |
81 return new FlexContainer( | |
82 inlineStyle: 'border-color: $border', | |
83 direction: FlexDirection.Row, | |
84 style: _style, | |
85 children: [ | |
86 new Container( | |
87 inlineStyle: 'border-$type-color: $border', | |
88 style: up ? _upStyle : _downStyle | |
89 ) | |
90 ] | |
91 ); | |
92 } | |
93 } | |
OLD | NEW |