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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/examples/stocks/stocks.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/stocks/stock.sky
diff --git a/sky/examples/stocks/stock.sky b/sky/examples/stocks/stock.sky
index e147718e7b7dec7d37df7dccae02f4f613cdf1b2..624c203cdca4cab78b2b34490baea16dd15e37bd 100644
--- a/sky/examples/stocks/stock.sky
+++ b/sky/examples/stocks/stock.sky
@@ -9,30 +9,28 @@
<template>
<style>
:host {
- height: 50px;
+ // TODO(eseidel): Why does setting height here make this too big?
+ // height: 48px;
+ max-height: 48px;
display: flex;
- width: 100%;
- border: 1px solid black;
+ border-bottom: 1px solid black;
+ padding-top: 16px;
+ padding-left: 16px;
+ padding-right: 16px;
+ padding-bottom: 20px;
}
#ticker {
- padding: 10px;
flex-grow: 1;
}
#last-sale {
- padding: 10px;
+ padding-right: 20px;
}
#change {
- padding: 10px;
border-radius: 5px;
- min-width: 70px;
+ min-width: 72px;
+ padding-right: 10px;
text-align: right;
}
- .positive {
- background-color: green;
- }
- .negative {
- background-color: red;
- }
</style>
<div id="ticker" />
<div id="last-sale" />
@@ -40,6 +38,45 @@
</template>
<script>
import "dart:sky";
+import "dart:math";
+
+List<String> redColors = [
+ '#FFEBEE',
+ '#FFCDD2',
+ '#EF9A9A',
+ '#E57373',
+ '#EF5350',
+ '#F44336',
+ '#E53935',
+ '#D32F2F',
+ '#C62828',
+ '#B71C1C',
+];
+
+List<String> greenColors = [
+ '#E8F5E9',
+ '#C8E6C9',
+ '#A5D6A7',
+ '#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) * greenColors.length).floor());
+}
+
+String colorForPercentChange(double percentChange) {
+ if (percentChange > 0)
+ return greenColors[colorIndexForPercentChange(percentChange)];
+ return redColors[colorIndexForPercentChange(percentChange)];
+}
@Tagname('stock')
class Stock extends SkyElement {
@@ -56,7 +93,7 @@ class Stock extends SkyElement {
if (model.percentChange > 0)
changeString = "+" + changeString;
change.textContent = changeString;
- change.classList.add((model.percentChange < 0) ? 'negative' : 'positive');
+ change.style['background-color'] = colorForPercentChange(model.percentChange);
}
}
« 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