mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 16:52:45 +08:00
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,
|
labels,
|
||||||
datasets: reportsForPeriod.map(report => {
|
datasets: reportsForPeriod.map(report => {
|
||||||
return {
|
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)",
|
backgroundColor: "rgba(200,220,240,0.3)",
|
||||||
borderColor: report.color
|
borderColor: report.color
|
||||||
};
|
};
|
||||||
|
@ -147,7 +147,7 @@ export default Ember.Component.extend(AsyncReport, {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
display: true,
|
display: true,
|
||||||
ticks: { callback: (label) => number(label, { ceil: true }) }
|
ticks: { callback: (label) => number(label) }
|
||||||
}],
|
}],
|
||||||
xAxes: [{
|
xAxes: [{
|
||||||
display: true,
|
display: true,
|
||||||
|
|
|
@ -5,18 +5,18 @@
|
||||||
<a href="{{report.reportUrl}}">{{report.title}}</a>
|
<a href="{{report.reportUrl}}">{{report.title}}</a>
|
||||||
</td>
|
</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}}>
|
<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>
|
||||||
|
|
||||||
<td class="value {{report.sevenDaysTrend}}" title={{report.sevenDaysCountTitle}}>
|
<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>
|
||||||
|
|
||||||
<td class="value {{report.thirtyDaysTrend}}" title={{report.thirtyDaysCountTitle}}>
|
<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>
|
</td>
|
||||||
|
|
||||||
{{#if allTime}}
|
{{#if allTime}}
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
<div class="trend {{report.trend}}">
|
<div class="trend {{report.trend}}">
|
||||||
<span class="trend-value" title="{{report.trendTitle}}">
|
<span class="trend-value" title="{{report.trendTitle}}">
|
||||||
{{#if report.average}}
|
{{#if report.average}}
|
||||||
{{number report.currentAverage ceil=true}}{{#if report.percent}}%{{/if}}
|
{{number report.currentAverage}}{{#if report.percent}}%{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{number report.currentTotal ceil=true noTitle="true"}}{{#if report.percent}}%{{/if}}
|
{{number report.currentTotal noTitle="true"}}{{#if report.percent}}%{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</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('age-with-tooltip', dt => new safe(autoUpdatingRelativeAge(new Date(dt), {title: true})));
|
||||||
|
|
||||||
registerUnbound('number', (orig, params) => {
|
registerUnbound('number', (orig, params) => {
|
||||||
if (params.ceil) {
|
orig = parseInt(Math.round(orig), 10);
|
||||||
orig = Math.ceil(orig);
|
|
||||||
}
|
|
||||||
|
|
||||||
orig = parseInt(orig, 10);
|
|
||||||
if (isNaN(orig)) { orig = 0; }
|
if (isNaN(orig)) { orig = 0; }
|
||||||
|
|
||||||
let title = I18n.toNumber(orig, { precision: 0 });
|
let title = I18n.toNumber(orig, { precision: 0 });
|
||||||
|
|
|
@ -301,14 +301,10 @@ export function relativeAge(date, options) {
|
||||||
return "UNKNOWN FORMAT";
|
return "UNKNOWN FORMAT";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function number(val, options = {}) {
|
export function number(val) {
|
||||||
let formattedNumber;
|
let formattedNumber;
|
||||||
|
|
||||||
if (options.ceil) {
|
val = parseInt(Math.round(val), 10);
|
||||||
val = Math.ceil(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
val = parseInt(val, 10);
|
|
||||||
if (isNaN(val)) val = 0;
|
if (isNaN(val)) val = 0;
|
||||||
|
|
||||||
if (val > 999999) {
|
if (val > 999999) {
|
||||||
|
|
|
@ -213,8 +213,8 @@ QUnit.test("number", assert => {
|
||||||
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
|
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||||
assert.equal(number(1000000), "1.0M", "it abbreviates a million");
|
assert.equal(number(1000000), "1.0M", "it abbreviates a million");
|
||||||
assert.equal(number(999999), "999k", "it abbreviates hundreds of thousands");
|
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.2), "18", "it returns a float number rounded to an integer as a string");
|
||||||
assert.equal(number(18.6, { ceil: true }), "19", "it ceils the value if requested");
|
assert.equal(number(18.6), "19", "it returns a float number rounded to an integer as a string");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("durationTiny", assert => {
|
QUnit.test("durationTiny", assert => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user