Skip to content

Commit

Permalink
Change legend note about classification when classification method ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
mthh committed Oct 22, 2024
1 parent e885483 commit f0f89af
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/components/Modals/LayerSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -79,7 +77,7 @@ import {
type GeoJSONFeature,
type ProportionalSymbolSingleColorParameters,
type LayerDescriptionCategoricalPictogram,
type CategoricalPictogramParameters, type ID3Element,
type CategoricalPictogramParameters, ClassificationMethod,
} from '../../global.d';

// Styles
Expand Down Expand Up @@ -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<TranslationFunctions>,
) => {
// 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();

Expand Down Expand Up @@ -617,6 +646,8 @@ function makeSettingsDefaultPoint(
(l: LayerDescription) => l.id === props.id,
{ rendererParameters: newParams },
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down Expand Up @@ -713,6 +744,8 @@ function makeSettingsDefaultPoint(
'rendererParameters',
{ color: newParams },
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down Expand Up @@ -1279,6 +1312,8 @@ function makeSettingsDefaultLine(
(l: LayerDescription) => l.id === props.id,
{ rendererParameters: newParams },
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down Expand Up @@ -1437,6 +1472,8 @@ function makeSettingsDefaultLine(
'color',
newParams,
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down Expand Up @@ -1511,6 +1548,8 @@ function makeSettingsDefaultLine(
(l: LayerDescription) => l.id === props.id,
{ rendererParameters: newParams },
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down Expand Up @@ -1831,6 +1870,8 @@ function makeSettingsDefaultPolygon(
(l: LayerDescription) => l.id === props.id,
{ rendererParameters: newParams },
);

updateLegendNote(props.id, newParams.method, LL);
},
});
}}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
1 change: 1 addition & 0 deletions src/i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit f0f89af

Please sign in to comment.