Sessions UI: visualization, month/year charts (#15902)
This commit is contained in:
parent
1bd521fc24
commit
cfa35f295b
38 changed files with 3271 additions and 715 deletions
|
|
@ -47,7 +47,7 @@ export default {
|
|||
let unit = format;
|
||||
let d = digits;
|
||||
if (POWER_UNIT.AUTO === unit) {
|
||||
if (watt >= 1_000_000) {
|
||||
if (watt >= 10_000_000) {
|
||||
unit = POWER_UNIT.MW;
|
||||
} else if (watt >= 1000 || 0 === watt) {
|
||||
unit = POWER_UNIT.KW;
|
||||
|
|
@ -82,6 +82,20 @@ export default {
|
|||
maximumFractionDigits: decimals,
|
||||
}).format(number);
|
||||
},
|
||||
fmtGrams: function (gramms, withUnit = true) {
|
||||
let unit = "gram";
|
||||
let value = gramms;
|
||||
if (gramms >= 1000) {
|
||||
unit = "kilogram";
|
||||
value = gramms / 1000;
|
||||
}
|
||||
return new Intl.NumberFormat(this.$i18n?.locale, {
|
||||
style: withUnit ? "unit" : "decimal",
|
||||
unit,
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0,
|
||||
}).format(value);
|
||||
},
|
||||
fmtCo2Short: function (gramms) {
|
||||
return `${this.fmtNumber(gramms, 0)} g`;
|
||||
},
|
||||
|
|
@ -203,6 +217,11 @@ export default {
|
|||
month: short ? "short" : "long",
|
||||
}).format(date);
|
||||
},
|
||||
fmtYear: function (date) {
|
||||
return new Intl.DateTimeFormat(this.$i18n?.locale, {
|
||||
year: "numeric",
|
||||
}).format(date);
|
||||
},
|
||||
fmtDayMonthYear: function (date) {
|
||||
return new Intl.DateTimeFormat(this.$i18n?.locale, {
|
||||
day: "numeric",
|
||||
|
|
@ -210,16 +229,23 @@ export default {
|
|||
year: "numeric",
|
||||
}).format(date);
|
||||
},
|
||||
fmtMoney: function (amout = 0, currency = "EUR", decimals = true) {
|
||||
return new Intl.NumberFormat(this.$i18n?.locale, {
|
||||
fmtDayMonth: function (date) {
|
||||
return new Intl.DateTimeFormat(this.$i18n?.locale, {
|
||||
weekday: "short",
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
}).format(date);
|
||||
},
|
||||
fmtMoney: function (amout = 0, currency = "EUR", decimals = true, withSymbol = false) {
|
||||
const currencyDisplay = withSymbol ? "narrowSymbol" : "code";
|
||||
const result = new Intl.NumberFormat(this.$i18n?.locale, {
|
||||
style: "currency",
|
||||
currency,
|
||||
currencyDisplay: "code",
|
||||
currencyDisplay,
|
||||
maximumFractionDigits: decimals ? undefined : 0,
|
||||
})
|
||||
.format(amout)
|
||||
.replace(currency, "")
|
||||
.trim();
|
||||
}).format(amout);
|
||||
|
||||
return withSymbol ? result : result.replace(currency, "").trim();
|
||||
},
|
||||
fmtCurrencySymbol: function (currency = "EUR") {
|
||||
const symbols = { EUR: "€", USD: "$" };
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const fmt = mount({
|
|||
describe("fmtW", () => {
|
||||
test("should format with units", () => {
|
||||
expect(fmt.fmtW(0, POWER_UNIT.AUTO)).eq("0,0 kW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO)).eq("1,2 MW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO)).eq("1.200,0 kW");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.MW)).eq("0,0 MW");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.MW)).eq("1,2 MW");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.KW)).eq("0,0 kW");
|
||||
|
|
@ -23,7 +23,7 @@ describe("fmtW", () => {
|
|||
});
|
||||
test("should format without units", () => {
|
||||
expect(fmt.fmtW(0, POWER_UNIT.AUTO, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO, false)).eq("1,2");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.AUTO, false)).eq("1.200,0");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.MW, false)).eq("0,0");
|
||||
expect(fmt.fmtW(1200000, POWER_UNIT.MW, false)).eq("1,2");
|
||||
expect(fmt.fmtW(0, POWER_UNIT.KW, false)).eq("0,0");
|
||||
|
|
@ -50,7 +50,7 @@ describe("fmtW", () => {
|
|||
describe("fmtWh", () => {
|
||||
test("should format with units", () => {
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.AUTO)).eq("0,0 kWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO)).eq("1,2 MWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO)).eq("1.200,0 kWh");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.MW)).eq("0,0 MWh");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.MW)).eq("1,2 MWh");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.KW)).eq("0,0 kWh");
|
||||
|
|
@ -60,7 +60,7 @@ describe("fmtWh", () => {
|
|||
});
|
||||
test("should format without units", () => {
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.AUTO, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO, false)).eq("1,2");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.AUTO, false)).eq("1.200,0");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.MW, false)).eq("0,0");
|
||||
expect(fmt.fmtWh(1200000, POWER_UNIT.MW, false)).eq("1,2");
|
||||
expect(fmt.fmtWh(0, POWER_UNIT.KW, false)).eq("0,0");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue