From f0f89afce786e76ddc31e450020013afb87eb489 Mon Sep 17 00:00:00 2001 From: Matthieu Viry Date: Tue, 22 Oct 2024 17:15:53 +0200 Subject: [PATCH] Change legend note about classification when classification method changes --- src/components/Modals/LayerSettings.tsx | 47 +++++++++++++++++++++++-- src/i18n/en/index.ts | 1 + src/i18n/fr/index.ts | 1 + src/i18n/i18n-types.ts | 8 +++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/components/Modals/LayerSettings.tsx b/src/components/Modals/LayerSettings.tsx index 2a115a3c..b3b6e117 100644 --- a/src/components/Modals/LayerSettings.tsx +++ b/src/components/Modals/LayerSettings.tsx @@ -20,7 +20,6 @@ import { webSafeFonts, fonts } from '../../helpers/font'; import { makeDorlingDemersSimulation } from '../../helpers/geo'; import { generateIdLegend } from '../../helpers/legends'; import { getPossibleLegendPosition } from '../LegendRenderer/common.tsx'; -import { semiCirclePath } from '../../helpers/svg'; // Sub-components import DetailsSummary from '../DetailsSummary.tsx'; @@ -49,7 +48,6 @@ import { } from '../../store/LayersDescriptionStore'; import { setClassificationPanelStore } from '../../store/ClassificationPanelStore'; import { applicationSettingsStore } from '../../store/ApplicationSettingsStore'; -import { globalStore } from '../../store/GlobalStore'; // Types / Interfaces import { @@ -79,7 +77,7 @@ import { type GeoJSONFeature, type ProportionalSymbolSingleColorParameters, type LayerDescriptionCategoricalPictogram, - type CategoricalPictogramParameters, type ID3Element, + type CategoricalPictogramParameters, ClassificationMethod, } from '../../global.d'; // Styles @@ -118,6 +116,37 @@ const redrawLayer = (targetId: string) => { ); }; +/** + * Update the note of the legend of a choropleth layer + * to change the "Classified using XXX method" if any + * and if the classification method has changed. + * @param {string} targetId + */ +const updateLegendNote = ( + targetId: string, + newMethod: ClassificationMethod, + LL: Accessor, +) => { + // All the possible 'Classified using XXX method' messages in the current language + const allMessages = Object.values(ClassificationMethod) + .map((m) => LL().ClassificationPanel.classificationMethodLegendDescriptions[m]() as string); + + setLayersDescriptionStoreBase( + produce((draft: LayersDescriptionStoreType) => { + draft.layoutFeaturesAndLegends.forEach((l) => { + if (l.layerId === targetId && l.type === LegendType.choropleth) { + const legend = l as Legend; + if (allMessages.includes(legend.note.text || '')) { + // We update the note of the legend + legend.note.text = LL() + .ClassificationPanel.classificationMethodLegendDescriptions[newMethod](); + } + } + }); + }), + ); +}; + function AestheticsSection(props: LayerDescription): JSX.Element { const { LL } = useI18nContext(); @@ -617,6 +646,8 @@ function makeSettingsDefaultPoint( (l: LayerDescription) => l.id === props.id, { rendererParameters: newParams }, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} @@ -713,6 +744,8 @@ function makeSettingsDefaultPoint( 'rendererParameters', { color: newParams }, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} @@ -1279,6 +1312,8 @@ function makeSettingsDefaultLine( (l: LayerDescription) => l.id === props.id, { rendererParameters: newParams }, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} @@ -1437,6 +1472,8 @@ function makeSettingsDefaultLine( 'color', newParams, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} @@ -1511,6 +1548,8 @@ function makeSettingsDefaultLine( (l: LayerDescription) => l.id === props.id, { rendererParameters: newParams }, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} @@ -1831,6 +1870,8 @@ function makeSettingsDefaultPolygon( (l: LayerDescription) => l.id === props.id, { rendererParameters: newParams }, ); + + updateLegendNote(props.id, newParams.method, LL); }, }); }} diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index 415e423d..113ca35f 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -1368,6 +1368,7 @@ const en = { pretty: 'Classified using the "pretty breaks" method', geometricProgression: 'Classified using a geometric progression', arithmeticProgression: 'Classified using an arithmetic progression', + nestedMeans: 'Classified using nested means', headTail: 'Classified using the head/tail break method', manual: 'Classified manually', }, diff --git a/src/i18n/fr/index.ts b/src/i18n/fr/index.ts index 343444cf..65cd21bc 100644 --- a/src/i18n/fr/index.ts +++ b/src/i18n/fr/index.ts @@ -1368,6 +1368,7 @@ const fr = { pretty: 'Discrétisation avec la méthode "pretty breaks"', geometricProgression: 'Discrétisation avec une progression géométrique', arithmeticProgression: 'Discrétisation avec une progression arithmétique', + nestedMeans: 'Discrétisation en moyennes emboitées', headTail: 'Discrétisation avec la méthode "head/tail"', manual: 'Discrétisation manuelle', }, diff --git a/src/i18n/i18n-types.ts b/src/i18n/i18n-types.ts index 7d1a695a..cb94eccd 100644 --- a/src/i18n/i18n-types.ts +++ b/src/i18n/i18n-types.ts @@ -5395,6 +5395,10 @@ type RootTranslation = { * C​l​a​s​s​i​f​i​e​d​ ​u​s​i​n​g​ ​a​n​ ​a​r​i​t​h​m​e​t​i​c​ ​p​r​o​g​r​e​s​s​i​o​n */ arithmeticProgression: string + /** + * C​l​a​s​s​i​f​i​e​d​ ​u​s​i​n​g​ ​n​e​s​t​e​d​ ​m​e​a​n​s + */ + nestedMeans: string /** * C​l​a​s​s​i​f​i​e​d​ ​u​s​i​n​g​ ​t​h​e​ ​h​e​a​d​/​t​a​i​l​ ​b​r​e​a​k​ ​m​e​t​h​o​d */ @@ -11191,6 +11195,10 @@ export type TranslationFunctions = { * Classified using an arithmetic progression */ arithmeticProgression: () => LocalizedString + /** + * Classified using nested means + */ + nestedMeans: () => LocalizedString /** * Classified using the head/tail break method */