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

Side by Side Diff: sky/examples/stocks/stock.sky

Issue 930193004: Attempt to make the stocks example more more material-friendly. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/stocks/stocks.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/sky/framework/sky-element.sky" /> 6 <import src="/sky/framework/sky-element.sky" />
7 7
8 <sky-element> 8 <sky-element>
9 <template> 9 <template>
10 <style> 10 <style>
11 :host { 11 :host {
12 height: 50px; 12 // TODO(eseidel): Why does setting height here make this too big?
13 // height: 48px;
14 max-height: 48px;
13 display: flex; 15 display: flex;
14 width: 100%; 16 border-bottom: 1px solid black;
15 border: 1px solid black; 17 padding-top: 16px;
18 padding-left: 16px;
19 padding-right: 16px;
20 padding-bottom: 20px;
16 } 21 }
17 #ticker { 22 #ticker {
18 padding: 10px;
19 flex-grow: 1; 23 flex-grow: 1;
20 } 24 }
21 #last-sale { 25 #last-sale {
22 padding: 10px; 26 padding-right: 20px;
23 } 27 }
24 #change { 28 #change {
25 padding: 10px;
26 border-radius: 5px; 29 border-radius: 5px;
27 min-width: 70px; 30 min-width: 72px;
31 padding-right: 10px;
28 text-align: right; 32 text-align: right;
29 } 33 }
30 .positive {
31 background-color: green;
32 }
33 .negative {
34 background-color: red;
35 }
36 </style> 34 </style>
37 <div id="ticker" /> 35 <div id="ticker" />
38 <div id="last-sale" /> 36 <div id="last-sale" />
39 <div id="change" /> 37 <div id="change" />
40 </template> 38 </template>
41 <script> 39 <script>
42 import "dart:sky"; 40 import "dart:sky";
41 import "dart:math";
42
43 List<String> redColors = [
44 '#FFEBEE',
45 '#FFCDD2',
46 '#EF9A9A',
47 '#E57373',
48 '#EF5350',
49 '#F44336',
50 '#E53935',
51 '#D32F2F',
52 '#C62828',
53 '#B71C1C',
54 ];
55
56 List<String> greenColors = [
57 '#E8F5E9',
58 '#C8E6C9',
59 '#A5D6A7',
60 '#81C784',
61 '#66BB6A',
62 '#4CAF50',
63 '#43A047',
64 '#388E3C',
65 '#2E7D32',
66 '#1B5E20',
67 ];
68
69 int colorIndexForPercentChange(double percentChange) {
70 // Currently the max is 10%.
71 double maxPercent = 10.0;
72 return max(0, ((percentChange.abs() / maxPercent) * greenColors.length).floor( ));
73 }
74
75 String colorForPercentChange(double percentChange) {
76 if (percentChange > 0)
77 return greenColors[colorIndexForPercentChange(percentChange)];
78 return redColors[colorIndexForPercentChange(percentChange)];
79 }
43 80
44 @Tagname('stock') 81 @Tagname('stock')
45 class Stock extends SkyElement { 82 class Stock extends SkyElement {
46 var model; // model.Stock 83 var model; // model.Stock
47 84
48 void shadowRootReady() { 85 void shadowRootReady() {
49 shadowRoot.getElementById('ticker').textContent = model.symbol; 86 shadowRoot.getElementById('ticker').textContent = model.symbol;
50 87
51 Element lastSale = shadowRoot.getElementById('last-sale'); 88 Element lastSale = shadowRoot.getElementById('last-sale');
52 lastSale.textContent = "\$${model.lastSale.toStringAsFixed(2)}"; 89 lastSale.textContent = "\$${model.lastSale.toStringAsFixed(2)}";
53 90
54 Element change = shadowRoot.getElementById('change'); 91 Element change = shadowRoot.getElementById('change');
55 String changeString = "${model.percentChange.toStringAsFixed(2)}%"; 92 String changeString = "${model.percentChange.toStringAsFixed(2)}%";
56 if (model.percentChange > 0) 93 if (model.percentChange > 0)
57 changeString = "+" + changeString; 94 changeString = "+" + changeString;
58 change.textContent = changeString; 95 change.textContent = changeString;
59 change.classList.add((model.percentChange < 0) ? 'negative' : 'positive'); 96 change.style['background-color'] = colorForPercentChange(model.percentChange );
60 } 97 }
61 } 98 }
62 99
63 _init(script) => register(script, Stock); 100 _init(script) => register(script, Stock);
64 </script> 101 </script>
65 </sky-element> 102 </sky-element>
OLDNEW
« no previous file with comments | « no previous file | sky/examples/stocks/stocks.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698