MCPcopy Index your code
hub / github.com/plotly/plotly.js / getFormatObj

Function getFormatObj

src/plots/plots.js:649–690  ·  view source on GitHub ↗

* getFormatObj: use _context to get the format object from locale. * Used to get d3.locale argument object and extraFormat argument object * * Regarding d3.locale argument : * decimal and thousands can be overridden later by layout.separators * grouping and currency are not presently used by ou

(gd, formatKeys)

Source from the content-addressed store, hash-verified

647 * @returns {object} d3.locale format object
648 */
649function getFormatObj(gd, formatKeys) {
650 var locale = gd._context.locale;
651 if(!locale) locale = 'en-US';
652
653 var formatDone = false;
654 var formatObj = {};
655
656 function includeFormat(newFormat) {
657 var formatFinished = true;
658 for(var i = 0; i < formatKeys.length; i++) {
659 var formatKey = formatKeys[i];
660 if(!formatObj[formatKey]) {
661 if(newFormat[formatKey]) {
662 formatObj[formatKey] = newFormat[formatKey];
663 } else formatFinished = false;
664 }
665 }
666 if(formatFinished) formatDone = true;
667 }
668
669 // same as localize, look for format parts in each format spec in the chain
670 for(var i = 0; i < 2; i++) {
671 var locales = gd._context.locales;
672 for(var j = 0; j < 2; j++) {
673 var formatj = (locales[locale] || {}).format;
674 if(formatj) {
675 includeFormat(formatj);
676 if(formatDone) break;
677 }
678 locales = Registry.localeRegistry;
679 }
680
681 var baseLocale = locale.split('-')[0];
682 if(formatDone || baseLocale === locale) break;
683 locale = baseLocale;
684 }
685
686 // lastly pick out defaults from english (non-US, as DMY is so much more common)
687 if(!formatDone) includeFormat(Registry.localeRegistry.en.format);
688
689 return formatObj;
690}
691
692/**
693 * getFormatter: combine the final separators with the locale formatting object

Callers 1

plots.jsFile · 0.85

Calls 1

includeFormatFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…