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

Side by Side Diff: sky/examples/stocks2/lib/stock_arrow.dart

Issue 1172513002: Restore stock_arrow elemnt of the stocks2 demo (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Updated per todays changes Created 5 years, 6 months 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
« no previous file with comments | « no previous file | sky/examples/stocks2/lib/stock_row.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'dart:math';
6 import 'package:sky/framework/fn2.dart'; 5 import 'package:sky/framework/fn2.dart';
6 import 'package:vector_math/vector_math.dart';
7 import 'package:sky/framework/rendering/box.dart';
8 import 'package:sky/framework/rendering/object.dart';
9 import 'package:sky/framework/theme2/colors.dart' as colors;
10
11 import 'dart:math' as math;
12 import 'dart:sky' as sky;
7 13
8 class StockArrow extends Component { 14 class StockArrow extends Component {
9 static final Style _style = new Style('''
10 width: 40px;
11 height: 40px;
12 align-items: center;
13 justify-content: center;
14 border-radius: 40px;
15 margin-right: 16px;
16 border: 1px solid transparent;'''
17 );
18
19 static final Style _upStyle = new Style('''
20 width: 0;
21 height: 0;
22 border-left: 9px solid transparent;
23 border-right: 9px solid transparent;
24 margin-bottom: 3px;
25 border-bottom: 9px solid white;'''
26 );
27
28 static final Style _downStyle = new Style('''
29 width: 0;
30 height: 0;
31 border-left: 9px solid transparent;
32 border-right: 9px solid transparent;
33 margin-top: 3px;
34 border-top: 9px solid white'''
35 );
36
37 double percentChange; 15 double percentChange;
38 16
39 StockArrow({ Object key, this.percentChange }) : super(key: key); 17 StockArrow({ Object key, this.percentChange }) : super(key: key);
40 18
41 // TODO(abarth): These should use sky/framework/theme/colors.dart.
42 final List<String> _kRedColors = [
43 '#E57373',
44 '#EF5350',
45 '#F44336',
46 '#E53935',
47 '#D32F2F',
48 '#C62828',
49 '#B71C1C',
50 ];
51
52 // TODO(abarth): These should use sky/framework/theme/colors.dart.
53 final List<String> _kGreenColors = [
54 '#81C784',
55 '#66BB6A',
56 '#4CAF50',
57 '#43A047',
58 '#388E3C',
59 '#2E7D32',
60 '#1B5E20',
61 ];
62
63 int _colorIndexForPercentChange(double percentChange) { 19 int _colorIndexForPercentChange(double percentChange) {
64 // Currently the max is 10%.
65 double maxPercent = 10.0; 20 double maxPercent = 10.0;
66 return max(0, ((percentChange.abs() / maxPercent) * _kGreenColors.length).fl oor()); 21 double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent;
22 return 100 + (normalizedPercentChange * 8.0).floor() * 100;
67 } 23 }
68 24
69 String _colorForPercentChange(double percentChange) { 25 Color _colorForPercentChange(double percentChange) {
70 if (percentChange > 0) 26 if (percentChange > 0)
71 return _kGreenColors[_colorIndexForPercentChange(percentChange)]; 27 return colors.Green[_colorIndexForPercentChange(percentChange)];
72 return _kRedColors[_colorIndexForPercentChange(percentChange)]; 28 return colors.Red[_colorIndexForPercentChange(percentChange)];
73 } 29 }
74 30
75 UINode build() { 31 UINode build() {
76 String border = _colorForPercentChange(percentChange).toString(); 32 // TODO(jackson): This should change colors with the theme
77 bool up = percentChange > 0; 33 Color color = _colorForPercentChange(percentChange);
78 String type = up ? 'bottom' : 'top'; 34 const double size = 40.0;
79 35 var arrow = new CustomPaint(callback: (sky.Canvas canvas) {
80 return new FlexContainer( 36 Paint paint = new Paint()..color = color;
81 inlineStyle: 'border-color: $border', 37 paint.setStyle(sky.PaintingStyle.stroke);
82 direction: FlexDirection.horizontal, 38 paint.strokeWidth = 2.0;
83 style: _style, 39 var padding = paint.strokeWidth * 3.0;
84 children: [ 40 var w = size - padding * 2.0;
85 new Container( 41 var h = size - padding * 2.0;
86 inlineStyle: 'border-$type-color: $border', 42 canvas.save();
87 style: up ? _upStyle : _downStyle 43 canvas.translate(padding, padding);
88 ) 44 if (percentChange < 0.0) {
89 ] 45 var cx = w / 2.0;
90 ); 46 var cy = h / 2.0;
47 canvas.translate(cx, cy);
48 canvas.rotate(math.PI);
49 canvas.translate(-cx, -cy);
50 }
51 canvas.drawLine(0.0, h, w, h, paint);
52 canvas.drawLine(w, h, w / 2.0, 0.0, paint);
53 canvas.drawLine(w / 2.0, 0.0, 0.0, h, paint);
54 canvas.restore();
55 });
56 return new Container(
57 child: arrow,
58 margin: const EdgeDims.symmetric(horizontal: 5.0),
59 constraints: new BoxConstraints(minWidth: size, minHeight: size));
abarth-chromium 2015/06/09 00:33:07 Why not just: width: size, height: size, ? That
91 } 60 }
92 } 61 }
OLDNEW
« no previous file with comments | « no previous file | sky/examples/stocks2/lib/stock_row.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698