Comments (4)
-
This will be slow for the common case where it does nothing. If we support this, we should special-case where the local’s numerals definition is null or undefined and have
formatNumeral
be the identity function. -
By defining numerals as a string, you’re limiting them to the basic multilingual plane because JavaScript strings are indexed as UTF-16 (or UCS-2?) characters. See JavaScript has a Unicode problem. You probably want to allow each numeral to be represented as a grapheme cluster instead, or in other words, define numerals as an array of strings rather than a string of characters. Admittedly this might be overkill but I don’t see any harm in adopting the more general representation.
-
Shouldn’t the padding and valuePrefix also be included in the substitution? I’m not sure if zero-padding is typically used in other locales but I think it’d be weird to mix the ASCII zero (
0
) with other numerals. -
You probably want to optimize your
formatNumeral
implementation using string.replace like so:
function numeralReplacer(numerals) {
function replace(i) {
return numerals[+i];
}
return function(string) {
return string.replace(/[0-9]/g, replace);
};
}
var numeralIndia = numeralReplacer(["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]);
numeralIndia("1,234.56"); // "۱,۲۳۴.۵۶"
More generally, I worry that this little library won‘t do enough to support other locales, and it might be better to encourage people to use a different, more full-featured, library such as jQuery Globalize. Globalize appears to support this feature already, for instance.
from d3-format.
Ok, I agree with you, we can
- Add numerals at needed locale files only.
-
Add a condition before calling numeralReplacer function to check if there is numerals value or not
-
If numerals not equal null, we can safely call numeralReplacer.
And for Arabic locales, zero padding will not be used but I haven`t problem to include it if we take into our consideration the other numeral system.
More generally, I worry that this little library won‘t do enough to support other locales, and it might be better to encourage people to use a different, more full-featured, library such as jQuery Globalize. Globalize appears to support this feature already, for instance.
Supporting Arabic/Indic numerals in D3.format will be very important for us at IBM, as a Globalization team at IBM Egypt one of our tasks is supporting the open source technologies that IBM products use with globalize and bidi features to full fill its gap in Arabic area.
And as D3 is used by tools that IBM products use, we need to support it with the missing bidi features like Arabic locales, Arabic/indic numeral system, hijri calendar for date formatting, which are considered very important for Arabic countries to meet their expectations in visualizing their data with Arabic/Indic numerals and their dates at hijri date format and to achieve that we highly need to support the numeral system here and hijri calendar at D3.time and arabic locales at d3.time.format.
All of these features when compaining with each others will produce understandable and readable data for arabic users.
from d3-format.
And as D3 is used by tools that IBM products use, we need to support it with the missing bidi features like Arabic locales, Arabic/indic numeral system, hijri calendar for date formatting, …
Yes. My point was only that you can use D3 with other number and date formatters. The d3-format and d3-time-format are provided by default, but there’s no reason you can’t also (or instead) use jQuery Globalize, Moment, or another library, passing in the appropriate function to axis.tickFormat or wherever else you need localization.
Anyway, the numeral replacer seems easy enough.
from d3-format.
Fixed in #41; released in 1.1.0. Thank you!
from d3-format.
Related Issues (20)
- import conflict with 3.0.0 update HOT 7
- Error with jest in version 3.0.0 HOT 1
- `"c"` format does not work as expected HOT 4
- Hot reload is complaining about named functions in nextjs HOT 4
- Using the locale .json files directly is not possible anymore HOT 1
- Add any string suffix to number. HOT 1
- Pick locale based on users browser automatically rather than fetching the locale definitions HOT 2
- Missing d3-format.min.js HOT 3
- Undefined Import in Next.js HOT 1
- I am using d3 in nextJs 7.0.x , it is giving error Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Home\Wildlife-Insights\node_modules\d3\package.json. HOT 1
- Using custom units in d3-format HOT 3
- Is it possible to support locale zh-TW? HOT 3
- formatPrefix will sometimes not perform rounding HOT 5
- Should functions be named across `d3-*` ? HOT 4
- Unit is generated outside parenthesis for negative numbers
- zh-TW is not supported HOT 2
- Specify type `g` decimal to exponential break point
- formatPrefix vs format handling of parentheses
- The minus sign generated by d3.format not compatible with SVG HOT 1
- d3 format transfer minus(-) to ascii 8722 code HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-format.