FIX: makes format number round the value before using parseInt

This commit is contained in:
Joffrey JAFFEUX 2018-06-07 10:44:21 +02:00 committed by GitHub
parent 322b66bcee
commit ab089cd68b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 21 deletions

View File

@ -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,

View File

@ -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}}

View File

@ -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>

View File

@ -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 });

View File

@ -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) {

View File

@ -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 => {