Skip to main content
Sign in
Snippets Groups Projects
Commit df66a269 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Add compact & inline options to ValueChange

parent 046abf18
No related branches found
No related tags found
1 merge request!90Carte budget etat
...@@ -84,7 +84,8 @@ ...@@ -84,7 +84,8 @@
title="⚠️ Les dispositifs n'étant pas tous à jour, cette somme est à considérer avec prudence." title="⚠️ Les dispositifs n'étant pas tous à jour, cette somme est à considérer avec prudence."
> >
<ValueChange <ValueChange
legend={true} compact
legend
unitName="currency-EUR" unitName="currency-EUR"
valueByCalculationName={{ valueByCalculationName={{
amendment: amendmentStateBudget.irpp, amendment: amendmentStateBudget.irpp,
...@@ -139,6 +140,8 @@ ...@@ -139,6 +140,8 @@
<!-- TODO use M€, etc --> <!-- TODO use M€, etc -->
<span class="text-xl font-bold" <span class="text-xl font-bold"
><ValueChange ><ValueChange
compact
inline
unitName="currency-EUR" unitName="currency-EUR"
valueByCalculationName={{ valueByCalculationName={{
amendment: amendmentQuantile.irpp, amendment: amendmentQuantile.irpp,
...@@ -150,6 +153,7 @@ ...@@ -150,6 +153,7 @@
</p> </p>
<p class="text-xs text-gray-600"> <p class="text-xs text-gray-600">
Soit <ValueChange Soit <ValueChange
inline
unitName="/1" unitName="/1"
valueByCalculationName={{ valueByCalculationName={{
amendment: amendmentQuantile.irpp / amendmentStateBudget.irpp, amendment: amendmentQuantile.irpp / amendmentStateBudget.irpp,
...@@ -167,6 +171,7 @@ ...@@ -167,6 +171,7 @@
En moyenne, un foyer de ce décile est prélevé de <span En moyenne, un foyer de ce décile est prélevé de <span
class="text-xl font-bold" class="text-xl font-bold"
><ValueChange ><ValueChange
inline
unitName="currency-EUR" unitName="currency-EUR"
valueByCalculationName={{ valueByCalculationName={{
amendment: amendmentQuantile.irpp / amendmentQuantile.count, amendment: amendmentQuantile.irpp / amendmentQuantile.count,
...@@ -179,6 +184,7 @@ ...@@ -179,6 +184,7 @@
<p class="text-xs text-gray-600"> <p class="text-xs text-gray-600">
<!-- TODO: Remplacer lawQuantile.rfr par lawQuantile.rfr_moyen (ie lawQuantile.rfr_total / lawQuantile.count ) --> <!-- TODO: Remplacer lawQuantile.rfr par lawQuantile.rfr_moyen (ie lawQuantile.rfr_total / lawQuantile.count ) -->
Soit <ValueChange Soit <ValueChange
inline
unitName="/1" unitName="/1"
valueByCalculationName={{ valueByCalculationName={{
amendment: amendment:
... ...
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
import { valueFormatter } from "$lib/values" import { valueFormatter } from "$lib/values"
import type { VariableValueByCalculationName } from "$lib/variables" import type { VariableValueByCalculationName } from "$lib/variables"
export let compact = false // For example: 1,2 Md €
export let inline = false
export let legend = false
export let unitName: string | undefined | null export let unitName: string | undefined | null
export let valueByCalculationName: VariableValueByCalculationName export let valueByCalculationName: VariableValueByCalculationName
export let legend = false
$: amendmentValue = valueByCalculationName.amendment as number | undefined $: amendmentValue = valueByCalculationName.amendment as number | undefined
...@@ -19,7 +21,7 @@ ...@@ -19,7 +21,7 @@
: billValue : billValue
: lawValue : lawValue
$: format = valueFormatter(baseValue, unitName) $: format = valueFormatter(baseValue, unitName, compact)
$: amendmentValueFormatted = $: amendmentValueFormatted =
amendmentValue === undefined ? undefined : format(amendmentValue) amendmentValue === undefined ? undefined : format(amendmentValue)
...@@ -56,39 +58,55 @@ ...@@ -56,39 +58,55 @@
</script> </script>
{#if showLawValue} {#if showLawValue}
<div class="flex flex-col"> <span class:block={!inline}>
<div <span
class={showBillValue class={showBillValue
? "line-through-bill " ? "line-through-bill "
: showAmendmentValue : showAmendmentValue
? "line-through-amendment " ? "line-through-amendment "
: ""} : ""}
class:block={!inline}
> >
{lawValueFormatted} {lawValueFormatted}
</div> </span>
{#if legend}<div class="text-xs font-normal"> {#if legend}
<span class="text-xs font-normal" class:block={!inline}>
(Droit&nbsp;en&nbsp;vigueur) (Droit&nbsp;en&nbsp;vigueur)
</div>{/if} </span>
</div> {/if}
</span>
{/if} {/if}
{#if showBillValue} {#if showBillValue}
<div> <span class:block={!inline}>
<div <span
class=" text-le-rouge-bill" class=" text-le-rouge-bill"
class:block={!inline}
class:line-through-amendment={showAmendmentValue} class:line-through-amendment={showAmendmentValue}
> >
{billValueFormatted} {billValueFormatted}
</div> </span>
{#if legend}<div class="text-xs font-normal text-le-rouge-bill"> {#if legend}
<span
class="text-xs font-normal text-le-rouge-bill"
class:block={!inline}
>
(PLF/PLFSS) (PLF/PLFSS)
</div>{/if} </span>
</div> {/if}
</span>
{/if} {/if}
{#if showAmendmentValue} {#if showAmendmentValue}
<div> <span class:block={!inline}>
<div class="bg-le-jaune px-1 text-black">{amendmentValueFormatted}</div> <span class="bg-le-jaune px-1 text-black" class:block={!inline}>
{#if legend}<div class="text-xs font-normal text-le-jaune-dark"> {amendmentValueFormatted}
</span>
{#if legend}
<span
class="text-xs font-normal text-le-jaune-dark"
class:block={!inline}
>
(Votre&nbsp;réforme) (Votre&nbsp;réforme)
</div>{/if} </span>
</div> {/if}
</span>
{/if} {/if}
...@@ -5,6 +5,7 @@ export function formatValue(value: number, unitName?: string): string { ...@@ -5,6 +5,7 @@ export function formatValue(value: number, unitName?: string): string {
export function valueFormatter( export function valueFormatter(
baseValue: unknown, baseValue: unknown,
unitName?: string | undefined | null, unitName?: string | undefined | null,
compact: boolean = false,
): (value: unknown) => string { ): (value: unknown) => string {
return baseValue === undefined return baseValue === undefined
? ((() => "") as (value: unknown) => string) ? ((() => "") as (value: unknown) => string)
...@@ -20,7 +21,16 @@ export function valueFormatter( ...@@ -20,7 +21,16 @@ export function valueFormatter(
style: "percent", style: "percent",
}).format as (value: unknown) => string) }).format as (value: unknown) => string)
: unitName != null && unitName.startsWith("currency-") : unitName != null && unitName.startsWith("currency-")
? (new Intl.NumberFormat("fr-FR", { ? compact
? (value: unknown): string =>
new Intl.NumberFormat("fr-FR", {
currency: unitName.replace(/^currency-/, ""),
maximumFractionDigits: 2,
minimumFractionDigits: 0,
notation: "compact", // Example: 3,2 Md €
style: "currency",
}).format(Math.round(value as number))
: (new Intl.NumberFormat("fr-FR", {
currency: unitName.replace(/^currency-/, ""), currency: unitName.replace(/^currency-/, ""),
maximumFractionDigits: 0, maximumFractionDigits: 0,
minimumFractionDigits: 0, minimumFractionDigits: 0,
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment