[Effen] Fork stocks and fn.dart so we have something to work on during the porting process

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1156543004
This commit is contained in:
Hixie 2015-05-26 12:53:08 -07:00
parent c09aac3f3f
commit 24e81ea037
38 changed files with 30241 additions and 0 deletions

View File

@ -0,0 +1,4 @@
This is a copy of the stocks app... with everything removed.
The goal is to eventually replace the stocks app with this one, by
adding it back bit by bit as we port it to RenderNode.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,632 @@
[
[
"WSFSL",
"WSFS Financial Corporation",
"26.3499",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wsfsl"
],
[
"WSTC",
"West Corporation",
"34.78",
"$2.93B",
"2013",
"Miscellaneous",
"Business Services",
"http://www.nasdaq.com/symbol/wstc"
],
[
"WSTG",
"Wayside Technology Group, Inc.",
"17.08",
"$83.72M",
"n/a",
"Technology",
"Retail: Computer Software & Peripheral Equipment",
"http://www.nasdaq.com/symbol/wstg"
],
[
"WSTL",
"Westell Technologies, Inc.",
"1.54",
"$92.7M",
"1995",
"Public Utilities",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/wstl"
],
[
"WTBA",
"West Bancorporation",
"17.99",
"$288.18M",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtba"
],
[
"WTFC",
"Wintrust Financial Corporation",
"47.69",
"$2.23B",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtfc"
],
[
"WTFCW",
"Wintrust Financial Corporation",
"25.25",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/wtfcw"
],
[
"WVFC",
"WVS Financial Corp.",
"11.5",
"$23.58M",
"n/a",
"Finance",
"Banks",
"http://www.nasdaq.com/symbol/wvfc"
],
[
"WVVI",
"Willamette Valley Vineyards, Inc.",
"5.9499",
"$28.93M",
"n/a",
"Consumer Non-Durables",
"Beverages (Production/Distribution)",
"http://www.nasdaq.com/symbol/wvvi"
],
[
"WWD",
"Woodward, Inc.",
"48.75",
"$3.17B",
"n/a",
"Energy",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/wwd"
],
[
"WWWW",
"Web.com Group, Inc.",
"18.01",
"$946.04M",
"n/a",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/wwww"
],
[
"WYNN",
"Wynn Resorts, Limited",
"158.47",
"$16.06B",
"2002",
"Consumer Services",
"Hotels/Resorts",
"http://www.nasdaq.com/symbol/wynn"
],
[
"XBKS",
"Xenith Bankshares, Inc.",
"6.4001",
"$82.71M",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/xbks"
],
[
"XCRA",
"Xcerra Corporation",
"8.68",
"$472.42M",
"n/a",
"Capital Goods",
"Electrical Products",
"http://www.nasdaq.com/symbol/xcra"
],
[
"XENE",
"Xenon Pharmaceuticals Inc.",
"19.38",
"$274.83M",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xene"
],
[
"XENT",
"Intersect ENT, Inc.",
"22.7",
"$530.65M",
"2014",
"Health Care",
"Medical/Dental Instruments",
"http://www.nasdaq.com/symbol/xent"
],
[
"XGTI",
"XG Technology, Inc",
"0.49",
"$12.26M",
"2013",
"Consumer Durables",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/xgti"
],
[
"XGTIW",
"XG Technology, Inc",
"0.26",
"n/a",
"2013",
"Consumer Durables",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/xgtiw"
],
[
"XIV",
"VelocityShares Daily Inverse VIX Short Term ETN",
"31.285",
"$485.35M",
"n/a",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/xiv"
],
[
"XLNX",
"Xilinx, Inc.",
"41.675",
"$10.9B",
"1990",
"Technology",
"Semiconductors",
"http://www.nasdaq.com/symbol/xlnx"
],
[
"XLRN",
"Acceleron Pharma Inc.",
"39.98",
"$1.29B",
"2013",
"Health Care",
"Biotechnology: Biological Products (No Diagnostic Substances)",
"http://www.nasdaq.com/symbol/xlrn"
],
[
"XNCR",
"Xencor, Inc.",
"15.06",
"$473.52M",
"2013",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xncr"
],
[
"XNET",
"Xunlei Limited",
"7.25",
"$471.36M",
"2014",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/xnet"
],
[
"XNPT",
"XenoPort, Inc.",
"7.19",
"$447.49M",
"2005",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xnpt"
],
[
"XOMA",
"XOMA Corporation",
"4.05",
"$469.36M",
"1986",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xoma"
],
[
"XONE",
"The ExOne Company",
"16.32",
"$235.71M",
"2013",
"Capital Goods",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/xone"
],
[
"XOOM",
"Xoom Corporation",
"16.43",
"$631.69M",
"2013",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/xoom"
],
[
"XPLR",
"Xplore Technologies Corp",
"6.82",
"$57.83M",
"n/a",
"Technology",
"Computer Manufacturing",
"http://www.nasdaq.com/symbol/xplr"
],
[
"XRAY",
"DENTSPLY International Inc.",
"52.53",
"$7.43B",
"1987",
"Health Care",
"Medical/Dental Instruments",
"http://www.nasdaq.com/symbol/xray"
],
[
"XTLB",
"XTL Biopharmaceuticals Ltd.",
"2.21",
"$25.73M",
"n/a",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/xtlb"
],
[
"XXIA",
"Ixia",
"10.45",
"$819.24M",
"2000",
"Capital Goods",
"Electrical Products",
"http://www.nasdaq.com/symbol/xxia"
],
[
"YDIV",
"First Trust NASDAQ Technology Dividend Index Fund",
"19.3412",
"$12.57M",
"n/a",
"n/a",
"n/a",
"http://www.nasdaq.com/symbol/ydiv"
],
[
"YDLE",
"Yodlee, Inc.",
"13.01",
"$380.3M",
"2014",
"Technology",
"Computer Software: Prepackaged Software",
"http://www.nasdaq.com/symbol/ydle"
],
[
"YHOO",
"Yahoo! Inc.",
"44.11",
"$41.79B",
"1996",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/yhoo"
],
[
"YNDX",
"Yandex N.V.",
"17.01",
"$5.41B",
"2011",
"Technology",
"Computer Software: Programming, Data Processing",
"http://www.nasdaq.com/symbol/yndx"
],
[
"YOD",
"You On Demand Holdings, Inc.",
"2.25",
"$53.4M",
"n/a",
"Consumer Services",
"Television Services",
"http://www.nasdaq.com/symbol/yod"
],
[
"YORW",
"The York Water Company",
"23.07",
"$295.51M",
"n/a",
"Public Utilities",
"Water Supply",
"http://www.nasdaq.com/symbol/yorw"
],
[
"YPRO",
"AdvisorShares YieldPro ETF",
"23.94",
"$68.23M",
"n/a",
"n/a",
"n/a",
"http://www.nasdaq.com/symbol/ypro"
],
[
"YRCW",
"YRC Worldwide, Inc.",
"19.96",
"$623.91M",
"n/a",
"Transportation",
"Trucking Freight/Courier Services",
"http://www.nasdaq.com/symbol/yrcw"
],
[
"YY",
"YY Inc.",
"61.82",
"$3.5B",
"2012",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/yy"
],
[
"Z",
"Zillow Group, Inc.",
"125.42",
"$5.12B",
"2011",
"Miscellaneous",
"Business Services",
"http://www.nasdaq.com/symbol/z"
],
[
"ZAGG",
"ZAGG Inc",
"6.51",
"$197.48M",
"n/a",
"Consumer Services",
"Other Specialty Stores",
"http://www.nasdaq.com/symbol/zagg"
],
[
"ZAZA",
"ZaZa Energy Corporation",
"2.11",
"$27.28M",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/zaza"
],
[
"ZBRA",
"Zebra Technologies Corporation",
"91",
"$4.63B",
"1991",
"Technology",
"Industrial Machinery/Components",
"http://www.nasdaq.com/symbol/zbra"
],
[
"ZEUS",
"Olympic Steel, Inc.",
"16.35",
"$179.56M",
"1994",
"Basic Industries",
"Metal Fabrications",
"http://www.nasdaq.com/symbol/zeus"
],
[
"ZFGN",
"Zafgen, Inc.",
"40.64",
"$1.08B",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zfgn"
],
[
"ZGNX",
"Zogenix, Inc.",
"1.55",
"$237.21M",
"2010",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zgnx"
],
[
"ZHNE",
"Zhone Technologies, Inc.",
"1.54",
"$50.05M",
"n/a",
"Public Utilities",
"Telecommunications Equipment",
"http://www.nasdaq.com/symbol/zhne"
],
[
"ZINC",
"Horsehead Holding Corp.",
"13.49",
"$763.52M",
"2007",
"Capital Goods",
"Metal Fabrications",
"http://www.nasdaq.com/symbol/zinc"
],
[
"ZION",
"Zions Bancorporation",
"26.33",
"$5.34B",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zion"
],
[
"ZIONW",
"Zions Bancorporation",
"3.4",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zionw"
],
[
"ZIONZ",
"Zions Bancorporation",
"2.45",
"n/a",
"n/a",
"Finance",
"Major Banks",
"http://www.nasdaq.com/symbol/zionz"
],
[
"ZIOP",
"ZIOPHARM Oncology Inc",
"9.56",
"$1.11B",
"n/a",
"Health Care",
"Medical Specialities",
"http://www.nasdaq.com/symbol/ziop"
],
[
"ZIV",
"VelocityShares Daily Inverse VIX Medium Term ETN",
"41.1",
"$37.81M",
"n/a",
"Finance",
"Investment Bankers/Brokers/Service",
"http://www.nasdaq.com/symbol/ziv"
],
[
"ZIXI",
"Zix Corporation",
"3.81",
"$216.48M",
"n/a",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/zixi"
],
[
"ZLTQ",
"ZELTIQ Aesthetics, Inc.",
"34.23",
"$1.3B",
"2011",
"Health Care",
"Biotechnology: Electromedical & Electrotherapeutic Apparatus",
"http://www.nasdaq.com/symbol/zltq"
],
[
"ZN",
"Zion Oil & Gas Inc",
"1.85",
"$65.29M",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/zn"
],
[
"ZNGA",
"Zynga Inc.",
"2.32",
"$2.09B",
"2011",
"Technology",
"EDP Services",
"http://www.nasdaq.com/symbol/znga"
],
[
"ZNWAA",
"Zion Oil & Gas Inc",
"n/a",
"n/a",
"n/a",
"Energy",
"Oil & Gas Production",
"http://www.nasdaq.com/symbol/znwaa"
],
[
"ZSAN",
"Zosano Pharma Corporation",
"11.09",
"$131.04M",
"2015",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zsan"
],
[
"ZSPH",
"ZS Pharma, Inc.",
"50.51",
"$1.05B",
"2014",
"Health Care",
"Major Pharmaceuticals",
"http://www.nasdaq.com/symbol/zsph"
],
[
"ZU",
"zulily, inc.",
"14.4",
"$1.8B",
"2013",
"Consumer Services",
"Catalog/Specialty Distribution",
"http://www.nasdaq.com/symbol/zu"
],
[
"ZUMZ",
"Zumiez Inc.",
"38.77",
"$1.13B",
"2005",
"Consumer Services",
"Clothing/Shoe/Accessory Stores",
"http://www.nasdaq.com/symbol/zumz"
]
]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,227 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// import 'package:sky/framework/components/tool_bar.dart';
// import 'package:sky/framework/components/drawer.dart';
// import 'package:sky/framework/components/drawer_header.dart';
// import 'package:sky/framework/components/floating_action_button.dart';
// import 'package:sky/framework/components/icon.dart';
// import 'package:sky/framework/components/icon_button.dart';
// import 'package:sky/framework/components/input.dart';
// import 'package:sky/framework/components/menu_divider.dart';
// import 'package:sky/framework/components/menu_item.dart';
// import 'package:sky/framework/components/modal_overlay.dart';
// import 'package:sky/framework/components/popup_menu.dart';
// import 'package:sky/framework/components/radio.dart';
// import 'package:sky/framework/components/scaffold.dart';
import 'package:sky/framework/fn2.dart';
import 'package:sky/framework/theme/typography.dart' as typography;
import 'package:sky/framework/theme/colors.dart';
import 'stock_data.dart';
// import 'stock_list.dart';
// import 'stock_menu.dart';
import 'dart:async';
import 'package:sky/framework/layout2.dart';
enum StockMode { Optimistic, Pessimistic }
class StocksApp extends App {
// static final Style _toolBarStyle = new Style('''
// background-color: ${Purple[500]};''');
// static final Style _searchBarStyle = new Style('''
// background-color: ${Grey[50]};''');
// static final Style _titleStyle = new Style('''
// ${typography.white.title};''');
List<Stock> _stocks = [];
StocksApp() : super() {
// if (debug)
// new Timer(new Duration(seconds: 1), dumpState);
new StockDataFetcher((StockData data) {
setState(() {
data.appendTo(_stocks);
});
});
// _drawerController = new DrawerController(_handleDrawerStatusChanged);
}
bool _isSearching = false;
String _searchQuery;
void _handleSearchBegin(_) {
setState(() {
_isSearching = true;
});
}
void _handleSearchEnd(_) {
setState(() {
_isSearching = false;
_searchQuery = null;
});
}
void _handleSearchQueryChanged(String query) {
setState(() {
_searchQuery = query;
});
}
// DrawerController _drawerController;
bool _drawerShowing = false;
void _handleDrawerStatusChanged(bool showing) {
setState(() {
_drawerShowing = showing;
});
}
// PopupMenuController _menuController;
void _handleMenuShow(_) {
setState(() {
// _menuController = new PopupMenuController();
// _menuController.open();
});
}
void _handleMenuHide(_) {
setState(() {
// _menuController.close().then((_) {
// setState(() {
// _menuController = null;
// });
// });
});
}
bool _autorefresh = false;
void _handleAutorefreshChanged(bool value) {
setState(() {
_autorefresh = value;
});
}
StockMode _stockMode = StockMode.Optimistic;
void _handleStockModeChange(StockMode value) {
setState(() {
_stockMode = value;
});
}
// static FlexBoxParentData _flex1 = new FlexBoxParentData()..flex = 1;
// Drawer buildDrawer() {
// return new Drawer(
// controller: _drawerController,
// level: 3,
// children: [
// new DrawerHeader(children: [new Text('Stocks')]),
// new MenuItem(
// key: 'Stock list',
// icon: 'action/assessment',
// children: [new Text('Stock List')]),
// new MenuItem(
// key: 'Account Balance',
// icon: 'action/account_balance',
// children: [new Text('Account Balance')]),
// new MenuDivider(key: 'div1'),
// new MenuItem(
// key: 'Optimistic Menu Item',
// icon: 'action/thumb_up',
// onGestureTap: (event) => _handleStockModeChange(StockMode.Optimistic),
// children: [
// new ParentDataNode(new Text('Optimistic'), _flex1),
// new Radio(key: 'optimistic-radio', value: StockMode.Optimistic, groupValue: _stockMode, onChanged: _handleStockModeChange)
// ]),
// new MenuItem(
// key: 'Pessimistic Menu Item',
// icon: 'action/thumb_down',
// onGestureTap: (event) => _handleStockModeChange(StockMode.Pessimistic),
// children: [
// new ParentDataNode(new Text('Pessimistic'), _flex1),
// new Radio(key: 'pessimistic-radio', value: StockMode.Pessimistic, groupValue: _stockMode, onChanged: _handleStockModeChange)
// ]),
// new MenuDivider(key: 'div2'),
// new MenuItem(
// key: 'Settings',
// icon: 'action/settings',
// children: [new Text('Settings')]),
// new MenuItem(
// key: 'Help & Feedback',
// icon: 'action/help',
// children: [new Text('Help & Feedback')])
// ]
// );
// }
// UINode buildToolBar() {
// return new StyleNode(
// new ToolBar(
// left: new IconButton(
// icon: 'navigation/menu_white',
// onGestureTap: _drawerController.toggle),
// center: new Container(
// style: _titleStyle,
// children: [new Text('Stocks')]),
// right: [
// new IconButton(
// icon: 'action/search_white',
// onGestureTap: _handleSearchBegin),
// new IconButton(
// icon: 'navigation/more_vert_white',
// onGestureTap: _handleMenuShow)
// ]),
// _toolBarStyle);
// }
// // TODO(abarth): Should we factor this into a SearchBar in the framework?
// UINode buildSearchBar() {
// return new StyleNode(
// new ToolBar(
// left: new IconButton(
// icon: 'navigation/arrow_back_grey600',
// onGestureTap: _handleSearchEnd),
// center: new Input(
// focused: true,
// placeholder: 'Search stocks',
// onChanged: _handleSearchQueryChanged)),
// _searchBarStyle);
// }
// void addMenuToOverlays(List<UINode> overlays) {
// if (_menuController == null)
// return;
// overlays.add(new ModalOverlay(
// children: [new StockMenu(
// controller: _menuController,
// autorefresh: _autorefresh,
// onAutorefreshChanged: _handleAutorefreshChanged
// )],
// onDismiss: _handleMenuHide));
// }
UINode build() {
// List<UINode> overlays = [];
// addMenuToOverlays(overlays);
// return new Scaffold(
// header: _isSearching ? buildSearchBar() : buildToolBar(),
// content: new Stocklist(stocks: _stocks, query: _searchQuery),
// fab: new FloatingActionButton(
// content: new Icon(type: 'content/add_white', size: 24), level: 3),
// drawer: _drawerShowing ? buildDrawer() : null,
// overlays: overlays
// );
}
}
void main() {
new StocksApp();
}

View File

@ -0,0 +1,93 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'package:sky/framework/fn.dart';
import 'package:sky/framework/layout.dart';
class StockArrow extends Component {
static final Style _style = new Style('''
width: 40px;
height: 40px;
align-items: center;
justify-content: center;
border-radius: 40px;
margin-right: 16px;
border: 1px solid transparent;'''
);
static final Style _upStyle = new Style('''
width: 0;
height: 0;
border-left: 9px solid transparent;
border-right: 9px solid transparent;
margin-bottom: 3px;
border-bottom: 9px solid white;'''
);
static final Style _downStyle = new Style('''
width: 0;
height: 0;
border-left: 9px solid transparent;
border-right: 9px solid transparent;
margin-top: 3px;
border-top: 9px solid white'''
);
double percentChange;
StockArrow({ Object key, this.percentChange }) : super(key: key);
// TODO(abarth): These should use sky/framework/theme/colors.dart.
final List<String> _kRedColors = [
'#E57373',
'#EF5350',
'#F44336',
'#E53935',
'#D32F2F',
'#C62828',
'#B71C1C',
];
// TODO(abarth): These should use sky/framework/theme/colors.dart.
final List<String> _kGreenColors = [
'#81C784',
'#66BB6A',
'#4CAF50',
'#43A047',
'#388E3C',
'#2E7D32',
'#1B5E20',
];
int _colorIndexForPercentChange(double percentChange) {
// Currently the max is 10%.
double maxPercent = 10.0;
return max(0, ((percentChange.abs() / maxPercent) * _kGreenColors.length).floor());
}
String _colorForPercentChange(double percentChange) {
if (percentChange > 0)
return _kGreenColors[_colorIndexForPercentChange(percentChange)];
return _kRedColors[_colorIndexForPercentChange(percentChange)];
}
UINode build() {
String border = _colorForPercentChange(percentChange).toString();
bool up = percentChange > 0;
String type = up ? 'bottom' : 'top';
return new FlexContainer(
inlineStyle: 'border-color: $border',
direction: FlexDirection.Row,
style: _style,
children: [
new Container(
inlineStyle: 'border-$type-color: $border',
style: up ? _upStyle : _downStyle
)
]
);
}
}

View File

@ -0,0 +1,72 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'dart:math';
import 'package:sky/framework/net/fetch.dart';
// Snapshot from http://www.nasdaq.com/screening/company-list.aspx
// Fetched 2/23/2014.
// "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",
// Data in stock_data.json
final Random _rng = new Random();
class Stock {
String symbol;
String name;
double lastSale;
String marketCap;
double percentChange;
Stock(this.symbol, this.name, this.lastSale, this.marketCap, this.percentChange);
Stock.fromFields(List<String> fields) {
// FIXME: This class should only have static data, not lastSale, etc.
// "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",
lastSale = 0.0;
try{
lastSale = double.parse(fields[2]);
} catch(_) {}
symbol = fields[0];
name = fields[1];
marketCap = fields[4];
percentChange = (_rng.nextDouble() * 20) - 10;
}
}
class StockData {
List<List<String>> _data;
StockData(this._data);
void appendTo(List<Stock> stocks) {
for (List<String> fields in _data)
stocks.add(new Stock.fromFields(fields));
}
}
typedef void StockDataCallback(StockData data);
const _kChunkCount = 30;
class StockDataFetcher {
int _currentChunk = 0;
final StockDataCallback callback;
StockDataFetcher(this.callback) {
_fetchNextChunk();
}
void _fetchNextChunk() {
fetch('data/stock_data_${_currentChunk++}.json').then((Response response) {
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
callback(new StockData(decoder.convert(json)));
if (_currentChunk < _kChunkCount)
_fetchNextChunk();
});
}
}

View File

@ -0,0 +1,32 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/framework/components/fixed_height_scrollable.dart';
import 'package:sky/framework/fn.dart';
import 'stock_data.dart';
import 'stock_row.dart';
class Stocklist extends FixedHeightScrollable {
String query;
List<Stock> stocks;
Stocklist({
Object key,
this.stocks,
this.query
}) : super(key: key);
List<UINode> buildItems(int start, int count) {
var filteredStocks = stocks.where((stock) {
return query == null ||
stock.symbol.contains(new RegExp(query, caseSensitive: false));
});
itemCount = filteredStocks.length;
return filteredStocks
.skip(start)
.take(count)
.map((stock) => new StockRow(stock: stock))
.toList(growable: false);
}
}

View File

@ -0,0 +1,44 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/framework/fn.dart';
import 'package:sky/framework/layout.dart';
import 'package:sky/framework/components/popup_menu.dart';
import 'package:sky/framework/components/checkbox.dart';
import 'package:sky/framework/theme/view_configuration.dart';
class StockMenu extends Component {
static final Style _style = new Style('''
position: absolute;
right: 8px;
top: ${8 + kStatusBarHeight}px;''');
PopupMenuController controller;
StockMenu({Object key, this.controller, this.autorefresh: false, this.onAutorefreshChanged}) : super(key: key);
final bool autorefresh;
final ValueChanged onAutorefreshChanged;
static FlexBoxParentData _flex1 = new FlexBoxParentData()..flex = 1;
UINode build() {
var checkbox = new Checkbox(
checked: this.autorefresh,
onChanged: this.onAutorefreshChanged
);
return new StyleNode(
new PopupMenu(
controller: controller,
items: [
[new Text('Add stock')],
[new Text('Remove stock')],
[new ParentDataNode(new Text('Autorefresh'), _flex1), checkbox],
],
level: 4),
_style
);
}
}

View File

@ -0,0 +1,72 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/framework/components/ink_well.dart';
import 'package:sky/framework/fn.dart';
import 'package:sky/framework/layout.dart';
import 'package:sky/framework/theme/typography.dart' as typography;
import 'stock_arrow.dart';
import 'stock_data.dart';
class StockRow extends Component {
static final Style _style = new Style('''
align-items: center;
border-bottom: 1px solid #F4F4F4;
padding-top: 16px;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 20px;'''
);
static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1;
static final Style _lastSaleStyle = new Style('''
text-align: right;
padding-right: 16px;'''
);
static final Style _changeStyle = new Style('''
${typography.black.caption};
text-align: right;'''
);
Stock stock;
StockRow({Stock stock}) : super(key: stock.symbol) {
this.stock = stock;
}
UINode build() {
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0)
changeInPrice = "+" + changeInPrice;
List<UINode> children = [
new StockArrow(
percentChange: stock.percentChange
),
new ParentDataNode(
new Container(
key: 'Ticker',
children: [new Text(stock.symbol)]
),
_tickerFlex
),
new Container(
key: 'LastSale',
style: _lastSaleStyle,
children: [new Text(lastSale)]
),
new Container(
key: 'Change',
style: _changeStyle,
children: [new Text(changeInPrice)]
)
];
return new StyleNode(new InkWell(children: children), _style);
}
}

View File

@ -0,0 +1,7 @@
name: stocks
author: Chromium Authors <sky-dev@googlegroups.com>
description: A demo application using Sky that shows stock data
homepage: https://github.com/domokit/sky_sdk/tree/master/examples/stocks
version: 0.0.1
dependencies:
sky: '>=0.0.1 <1.0.0'