Change decimal and thousands separator
FabianSchmick opened this issue · comments
Subject of the issue
In the Chart, the decimal (.
) and thousands separator (,
) follow the norm for most English-speaking countries. But there are many countries in the world where this is swapped. See: https://en.wikipedia.org/wiki/Decimal_separator#Conventions_worldwide
Expected behaviour
Define the decimal and thousands separator as an option for L.control.elevation
or look for L.setLocale('de');
in the leaflet-elevation
code for the current ones.
![Bildschirmfoto 2023-09-04 um 09 23 09](https://private-user-images.githubusercontent.com/17527958/265385677-b9be73dd-de20-47e3-b122-9bc23617219e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyMzc5NDEsIm5iZiI6MTcyMjIzNzY0MSwicGF0aCI6Ii8xNzUyNzk1OC8yNjUzODU2NzctYjliZTczZGQtZGUyMC00N2UzLWIxMjItOWJjMjM2MTcyMTllLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI5VDA3MjA0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAzMGUxMTZiZjBjN2NmMjhlZTRkZGFlZDBiOGY4OTI4NGVkY2E2MmZkMjM5Mjg3ZWM2YWExZGMzODk3MzVkMGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.t8lyBjLSiHmFaJ3kB_L3S5z04jwdtdPJUSQc9iV7lxU)
Actual behaviour
![Bildschirmfoto 2023-09-04 um 09 22 01](https://private-user-images.githubusercontent.com/17527958/265385655-f1b6f835-0356-418d-94e8-8ac18ea72df0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyMzc5NDEsIm5iZiI6MTcyMjIzNzY0MSwicGF0aCI6Ii8xNzUyNzk1OC8yNjUzODU2NTUtZjFiNmY4MzUtMDM1Ni00MThkLTk0ZTgtOGFjMThlYTcyZGYwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI5VDA3MjA0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc4NzFhZTE5MTNjOWYxMTNhYTM4MGU3YWQyMDFlNzkzNGVmYzJjZDMxMmIwYmQxMjY1MDg2YjlmZTBhMGI2YjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.5NKlVMluqa9mnre9IAVl0DtR_-lptX3AhlLApABkJbA)
Hi Fabian,
if i'm not mistaken it's the user's browser that chooses the preferred number convention.
Here the affected portions of code:
leaflet-elevation/src/handlers/altitude.js
Lines 54 to 59 in ea15556
leaflet-elevation/src/handlers/distance.js
Lines 33 to 37 in ea15556
leaflet-elevation/src/utils.js
Lines 150 to 153 in ea15556
👋 Raruto
I think for the tooltip, we need to add .toLocaleString()
, then the browser can choose the preferred number convention. (But this function call does not exist yet)
tooltip: {
...
chart: (item) => L._("y: ") + _.round(item[opts.yAttr], opts.decimalsY).toLocaleString() + " " + altitude.label,
marker: (item) => _.round(item[opts.yAttr], opts.decimalsY).toLocaleString() + " " + altitude.label,
...
},
But for the y-axis I don't know. Maybe this is more complex as this is dynamic.
I found the solution for the y-axis. In the d3-docs you can use the following method-call do define the separators:
import * as L from 'leaflet';
import * as d3 from 'd3';
global.d3 = d3;
...
import '@raruto/leaflet-elevation/dist/leaflet-elevation';
...
d3.formatDefaultLocale({
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0€"]
})
@FabianSchmick ref: #271 (comment)
this function call does not exist yet
In such cases you can write your own custom handlers (starting from the default ones)
Below is a fairly detailed example:
leaflet-elevation/examples/leaflet-elevation_extended-ui.html
Lines 255 to 271 in ea15556
If you think you have a relatively simple solution to set up, feel free to pitch a PR to that effect.
I'll close here for now.
👋 Raruto