UX: makes table report trend icons as charts

This commit will also reverse icon orientation if higher_is_better = false
This commit is contained in:
Joffrey JAFFEUX 2018-05-25 12:09:30 +02:00 committed by GitHub
parent 20b94bc714
commit e67ac93e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 41 deletions

View File

@ -80,20 +80,25 @@ const Report = Discourse.Model.extend({
return Ember.makeArray(data).length === 0 ? 0 : parseFloat((total / parseFloat(data.length)).toFixed(1));
},
@computed("trend")
trendIcon(trend) {
switch (trend) {
case "trending-up":
return "angle-up";
case "trending-down":
return "angle-down";
case "high-trending-up":
return "angle-double-up";
case "high-trending-down":
return "angle-double-down";
default:
return null;
}
@computed("trend", "higher_is_better")
trendIcon(trend, higherIsBetter) {
return this._iconForTrend(trend, higherIsBetter);
},
@computed("sevenDaysTrend", "higher_is_better")
sevenDaysTrendIcon(sevenDaysTrend, higherIsBetter) {
return this._iconForTrend(sevenDaysTrend, higherIsBetter);
},
@computed("thirtyDaysTrend", "higher_is_better")
thirtyDaysTrendIcon(thirtyDaysTrend, higherIsBetter) {
return this._iconForTrend(thirtyDaysTrend, higherIsBetter);
},
@computed("yesterdayTrend", "higher_is_better")
yesterdayTrendIcon(yesterdayTrend, higherIsBetter) {
console.log("yesterdayTrendIcon", yesterdayTrend, higherIsBetter, this._iconForTrend(yesterdayTrend, higherIsBetter))
return this._iconForTrend(yesterdayTrend, higherIsBetter);
},
@computed("prev_period", "currentTotal", "currentAverage")
@ -216,6 +221,21 @@ const Report = Discourse.Model.extend({
} else if (change < 0) {
return higherIsBetter ? "trending-down" : "trending-up";
}
},
_iconForTrend(trend, higherIsBetter) {
switch (trend) {
case "trending-up":
return higherIsBetter ? "angle-up" : "angle-down";
case "trending-down":
return higherIsBetter ? "angle-down" : "angle-up";
case "high-trending-up":
return higherIsBetter ? "angle-double-up" : "angle-double-down";
case "high-trending-down":
return higherIsBetter ? "angle-double-down" : "angle-double-up";
default:
return null;
}
}
});

View File

@ -8,15 +8,15 @@
<td class="value">{{number report.todayCount}}</td>
<td class="value {{report.yesterdayTrend}}" title={{report.yesterdayCountTitle}}>
{{number report.yesterdayCount}} {{d-icon "caret-up" class="up"}} {{d-icon "caret-down" class="down"}}
{{number report.yesterdayCount}} {{d-icon report.yesterdayTrendIcon}}
</td>
<td class="value {{report.sevenDaysTrend}}" title={{report.sevenDaysCountTitle}}>
{{number report.lastSevenDaysCount}} {{d-icon "caret-up" class="up"}} {{d-icon "caret-down" class="down"}}
{{number report.lastSevenDaysCount}} {{d-icon report.sevenDaysTrendIcon}}
</td>
<td class="value {{report.thirtyDaysTrend}}" title={{report.thirtyDaysCountTitle}}>
{{number report.lastThirtyDaysCount}} {{d-icon "caret-up" class="up"}} {{d-icon "caret-down" class="down"}}
{{number report.lastThirtyDaysCount}} {{d-icon report.thirtyDaysTrendIcon}}
</td>
{{#if allTime}}

View File

@ -339,7 +339,6 @@
padding: 8px 12px 8px;
}
i {
display: none;
margin-right: -12px; // align on caret
@media screen and (max-width: 650px) {
margin-right: -9px;
@ -347,22 +346,10 @@
}
&.high-trending-up, &.trending-up {
i.up {
color: $success;
display: inline;
}
i { color: $success; }
}
&.high-trending-down, &.trending-down {
i.down {
color: $danger;
display: inline;
}
}
&.no-change {
i.down {
display: inline;
visibility: hidden;
}
i { color: $danger; }
}
}
}