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

Side by Side Diff: sky/examples/stocks/stocks.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 | « sky/examples/stocks/stock.sky ('k') | no next file » | 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-drawer.sky" /> 6 <import src="/sky/framework/sky-drawer.sky" />
7 <import src="/sky/framework/sky-element.sky" /> 7 <import src="/sky/framework/sky-element.sky" />
8 <import src="/sky/framework/sky-scrollable.sky" /> 8 <import src="/sky/framework/sky-scrollable.sky" />
9 <import src="stock.sky" as='view'/> 9 <import src="stock.sky" as='view'/>
10 <import src='companylist.sky' as='model'/> 10 <import src='companylist.sky' as='model'/>
11 11
12 <sky-element> 12 <sky-element>
13 <template> 13 <template>
14 <style> 14 <style>
15 :host { 15 :host {
16 display: flex; 16 display: flex;
17 flex-direction: column; 17 flex-direction: column;
18 height: -webkit-fill-available; 18 height: -webkit-fill-available;
19 font: 'Helvetica'; 19 font-family: 'Roboto Regular', 'Helvetica';
20 font-size: 16px;
20 } 21 }
21 sky-drawer { 22 sky-drawer {
22 position: absolute; 23 position: absolute;
23 z-index: 1; 24 z-index: 1;
24 top: 0; 25 top: 0;
25 left: 0; 26 left: 0;
26 bottom: 0; 27 bottom: 0;
27 right: 0; 28 right: 0;
28 } 29 }
29 sky-toolbar { 30 sky-toolbar {
(...skipping 29 matching lines...) Expand all
59 <div id="menu" /> 60 <div id="menu" />
60 I am a stocks app 61 I am a stocks app
61 </sky-toolbar> 62 </sky-toolbar>
62 <sky-scrollable id='stock_list'> 63 <sky-scrollable id='stock_list'>
63 </sky-scrollable> 64 </sky-scrollable>
64 </template> 65 </template>
65 <script> 66 <script>
66 import "dart:sky"; 67 import "dart:sky";
67 import "dart:math"; 68 import "dart:math";
68 69
70 List pick(List list, int count) {
71 var rng = new Random();
72 List picked = new List();
73 for (int i = 0; i < count; i++) {
74 picked.add(list[rng.nextInt(list.length)]);
75 }
76 return picked;
77 }
78
69 @Tagname('stocks') 79 @Tagname('stocks')
70 class Stocks extends SkyElement { 80 class Stocks extends SkyElement {
71 Element _drawer; 81 Element _drawer;
72 82
73 void shadowRootReady() { 83 void shadowRootReady() {
74 _drawer = shadowRoot.getElementById('drawer'); 84 _drawer = shadowRoot.getElementById('drawer');
75 Element menu = shadowRoot.getElementById('menu'); 85 Element menu = shadowRoot.getElementById('menu');
76 menu.addEventListener('click', _handleMenuClick); 86 menu.addEventListener('click', _handleMenuClick);
77 populateStockList(); 87 populateStockList();
78 } 88 }
79 89
80 void populateStockList() { 90 void populateStockList() {
81 Element stockList = shadowRoot.getElementById('stock_list'); 91 Element stockList = shadowRoot.getElementById('stock_list');
82 // Limit to 100 to avoid taking seconds to load. 92 // Limit to 100 to avoid taking seconds to load.
83 var rng = new Random(); 93 List<model.Stock> picked = pick(model.oracle.stocks, 100);
84 for (var i = 0; i < 100; i++) { 94 picked.sort((a, b) => a.symbol.compareTo(b.symbol));
85 List<model.Stock> list = model.oracle.stocks; 95 for (model.Stock stock in picked) {
86 model.Stock stock = list[rng.nextInt(list.length)];
87 stockList.appendChild(new view.Stock()..model = stock); 96 stockList.appendChild(new view.Stock()..model = stock);
88 } 97 }
89 } 98 }
90 99
91 void _handleMenuClick(_) { 100 void _handleMenuClick(_) {
92 _drawer.toggle(); 101 _drawer.toggle();
93 } 102 }
94 } 103 }
95 104
96 _init(script) => register(script, Stocks); 105 _init(script) => register(script, Stocks);
97 </script> 106 </script>
98 </sky-element> 107 </sky-element>
OLDNEW
« no previous file with comments | « sky/examples/stocks/stock.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698