FIX: makes format number round the value before using parseInt
This commit is contained in:
parent
322b66bcee
commit
ab089cd68b
|
@ -100,7 +100,7 @@ export default Ember.Component.extend(AsyncReport, {
|
|||
labels,
|
||||
datasets: reportsForPeriod.map(report => {
|
||||
return {
|
||||
data: Ember.makeArray(report.data).map(d => number(d.y, { ceil: true })),
|
||||
data: Ember.makeArray(report.data).map(d => number(d.y)),
|
||||
backgroundColor: "rgba(200,220,240,0.3)",
|
||||
borderColor: report.color
|
||||
};
|
||||
|
@ -147,7 +147,7 @@ export default Ember.Component.extend(AsyncReport, {
|
|||
scales: {
|
||||
yAxes: [{
|
||||
display: true,
|
||||
ticks: { callback: (label) => number(label, { ceil: true }) }
|
||||
ticks: { callback: (label) => number(label) }
|
||||
}],
|
||||
xAxes: [{
|
||||
display: true,
|
||||
|
|
|
@ -5,18 +5,18 @@
|
|||
<a href="{{report.reportUrl}}">{{report.title}}</a>
|
||||
</td>
|
||||
|
||||
<td class="value">{{number report.todayCount ceil=true}}</td>
|
||||
<td class="value">{{number report.todayCount}}</td>
|
||||
|
||||
<td class="value {{report.yesterdayTrend}}" title={{report.yesterdayCountTitle}}>
|
||||
{{number report.yesterdayCount ceil=true}} {{d-icon report.yesterdayTrendIcon}}
|
||||
{{number report.yesterdayCount}} {{d-icon report.yesterdayTrendIcon}}
|
||||
</td>
|
||||
|
||||
<td class="value {{report.sevenDaysTrend}}" title={{report.sevenDaysCountTitle}}>
|
||||
{{number report.lastSevenDaysCount ceil=true}} {{d-icon report.sevenDaysTrendIcon}}
|
||||
{{number report.lastSevenDaysCount}} {{d-icon report.sevenDaysTrendIcon}}
|
||||
</td>
|
||||
|
||||
<td class="value {{report.thirtyDaysTrend}}" title={{report.thirtyDaysCountTitle}}>
|
||||
{{number report.lastThirtyDaysCount ceil=true}} {{d-icon report.thirtyDaysTrendIcon}}
|
||||
{{number report.lastThirtyDaysCount}} {{d-icon report.thirtyDaysTrendIcon}}
|
||||
</td>
|
||||
|
||||
{{#if allTime}}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
<div class="trend {{report.trend}}">
|
||||
<span class="trend-value" title="{{report.trendTitle}}">
|
||||
{{#if report.average}}
|
||||
{{number report.currentAverage ceil=true}}{{#if report.percent}}%{{/if}}
|
||||
{{number report.currentAverage}}{{#if report.percent}}%{{/if}}
|
||||
{{else}}
|
||||
{{number report.currentTotal ceil=true noTitle="true"}}{{#if report.percent}}%{{/if}}
|
||||
{{number report.currentTotal noTitle="true"}}{{#if report.percent}}%{{/if}}
|
||||
{{/if}}
|
||||
</span>
|
||||
|
||||
|
|
|
@ -8,11 +8,7 @@ registerUnbound('raw-date', dt => longDate(new Date(dt)));
|
|||
registerUnbound('age-with-tooltip', dt => new safe(autoUpdatingRelativeAge(new Date(dt), {title: true})));
|
||||
|
||||
registerUnbound('number', (orig, params) => {
|
||||
if (params.ceil) {
|
||||
orig = Math.ceil(orig);
|
||||
}
|
||||
|
||||
orig = parseInt(orig, 10);
|
||||
orig = parseInt(Math.round(orig), 10);
|
||||
if (isNaN(orig)) { orig = 0; }
|
||||
|
||||
let title = I18n.toNumber(orig, { precision: 0 });
|
||||
|
|
|
@ -301,14 +301,10 @@ export function relativeAge(date, options) {
|
|||
return "UNKNOWN FORMAT";
|
||||
}
|
||||
|
||||
export function number(val, options = {}) {
|
||||
export function number(val) {
|
||||
let formattedNumber;
|
||||
|
||||
if (options.ceil) {
|
||||
val = Math.ceil(val);
|
||||
}
|
||||
|
||||
val = parseInt(val, 10);
|
||||
val = parseInt(Math.round(val), 10);
|
||||
if (isNaN(val)) val = 0;
|
||||
|
||||
if (val > 999999) {
|
||||
|
|
|
@ -213,8 +213,8 @@ QUnit.test("number", assert => {
|
|||
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
assert.equal(number(1000000), "1.0M", "it abbreviates a million");
|
||||
assert.equal(number(999999), "999k", "it abbreviates hundreds of thousands");
|
||||
assert.equal(number(18.2), "18", "it returns a float number converted to an integer as a string");
|
||||
assert.equal(number(18.6, { ceil: true }), "19", "it ceils the value if requested");
|
||||
assert.equal(number(18.2), "18", "it returns a float number rounded to an integer as a string");
|
||||
assert.equal(number(18.6), "19", "it returns a float number rounded to an integer as a string");
|
||||
});
|
||||
|
||||
QUnit.test("durationTiny", assert => {
|
||||
|
|
Loading…
Reference in New Issue