Skip to content

Commit

Permalink
fix(#200): RangeError: maximumFactionDigits value is out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze committed May 31, 2024
1 parent 6984729 commit 0451b38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
14 changes: 7 additions & 7 deletions __tests__/__snapshots__/remaining.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`SankeyChart with remaining type entities matches snapshot 2`] = `
<div class="spacerv" style="height:69.5px;"></div>
<div class="box type-entity" style="height:61px;">
<div style="background-color:var(--warning-color);" title="2kW Total" class="">
<div style="background-color:var(--warning-color);" title="1.8kW Total" class="">
</div>
<div class="label" style="line-height:15px;">
Expand Down Expand Up @@ -81,7 +81,7 @@ exports[`SankeyChart with remaining type entities matches snapshot 2`] = `
<div class="spacerv" style="height:5px;"></div>
<div class="box type-remaining_child_state" style="height:190px;">
<div style="background-color:darkslateblue;" title="6kW Total
<div style="background-color:darkslateblue;" title="5.6kW Total
All
All
All
Expand Down Expand Up @@ -146,7 +146,7 @@ IDK" class="">
<div class="box type-entity" style="height:63px;">
<div style="background-color:var(--primary-color);" title="2kW Varmtvann
<div style="background-color:var(--primary-color);" title="1.9kW Varmtvann
Blaa" class="">
</div>
Expand All @@ -162,7 +162,7 @@ Blaa" class="">
<div class="spacerv" style="height:5.5px;"></div>
<div class="box type-entity" style="height:63px;">
<div style="background-color:var(--primary-color);" title="2kВ Avfukter" class="">
<div style="background-color:var(--primary-color);" title="1.9kВ Avfukter" class="">
</div>
<div class="label" style="line-height:15px;">
Expand All @@ -177,7 +177,7 @@ Blaa" class="">
<div class="spacerv" style="height:5.5px;"></div>
<div class="box type-entity" style="height:63px;">
<div style="background-color:var(--primary-color);" title="2kW " class="">
<div style="background-color:var(--primary-color);" title="1.9kW " class="">
</div>
<div class="label" style="line-height:15px;">
Expand Down Expand Up @@ -211,7 +211,7 @@ Blaa" class="">
<div class="spacerv" style="height:68.5px;"></div>
<div class="box type-passthrough" style="height:63px;">
<div style="background-color:red;" title="2kW " class="">
<div style="background-color:red;" title="1.9kW " class="">
</div>
Expand All @@ -226,7 +226,7 @@ Blaa" class="">
<div class="spacerv" style="height:68.5px;"></div>
<div class="box type-entity" style="height:63px;">
<div style="background-color:red;" title="2kW " class="">
<div style="background-color:red;" title="1.9kW " class="">
</div>
<div class="label" style="line-height:15px;">
Expand Down
1 change: 1 addition & 0 deletions __tests__/remaining.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('SankeyChart with remaining type entities', () => {
show_states: true,
min_state: 0.1,
unit_prefix: 'k',
round: 1,
sections: [
{
entities: [
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ export function formatState(state: number, round: number, locale: FrontendLocale

if (!monetary_unit) {
return formatNumber(parseFloat(rounded), locale, {
minimumFractionDigits: 0,
maximumFractionDigits: decimals - 1,
});
} else {
return formatNumber(parseFloat(rounded), locale, {
style: 'currency',
currency: monetary_unit,
minimumFractionDigits: decimals - 1,
maximumFractionDigits: decimals - 1,
});
}
}
Expand Down

0 comments on commit 0451b38

Please sign in to comment.