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 | |
8 class StockArrow extends Component { | |
9 static final Style _style = new Style(''' | |
10 width: 40px; | |
11 height: 40px; | |
12 display: flex; | |
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 Node build() { | |
77 String border = _colorForPercentChange(percentChange).toString(); | |
78 bool up = percentChange > 0; | |
79 String type = up ? 'bottom' : 'top'; | |
80 | |
81 return new Container( | |
82 inlineStyle: 'border-color: $border', | |
83 style: _style, | |
84 children: [ | |
85 new Container( | |
86 inlineStyle: 'border-$type-color: $border', | |
87 style: up ? _upStyle : _downStyle | |
88 ) | |
89 ] | |
90 ); | |
91 } | |
92 } | |
OLD | NEW |