How to use the d3-format.formatLocale function in d3-format

To help you get started, we’ve selected a few d3-format examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orbiting / styleguide / src / components / Chart / utils.js View on Github external
}
  return newRef => {
    ref = newRef
    if (ref) {
      window.addEventListener('resize', update)
      // raf needed to wait for glamor css styles
      rafHandle = window.requestAnimationFrame(update)
    } else {
      window.removeEventListener('resize', update)
      window.cancelAnimationFrame(rafHandle)
    }
  }
}

const thousandSeparator = '\u2019'
const swissNumbers = formatLocale({
  decimal: ',',
  thousands: thousandSeparator,
  grouping: [3],
  currency: ['CHF\u00a0', '']
})

const formatPow = (tLabel, baseValue) => {
  const decimalFormat = swissNumbers.format('.0f')
  let [n] = decimalFormat(baseValue).split('.')
  let scale = value => value
  let suffix = ''
  if (n.length > 9) {
    scale = value => value / Math.pow(10, 9)
    suffix = tLabel(' Mrd.')
  } else if (n.length > 6) {
    scale = value => value / Math.pow(10, 6)
github DefinitelyTyped / DefinitelyTyped / d3-format / d3-format-tests.ts View on Github external
localeDef = {
  decimal: "\u066b",
  thousands: "\u066c",
  grouping: [3],
  currency: ["", ""],
  numerals : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"]
}

let decimal: string = localeDef.decimal;
let thousands: string = localeDef.thousands;
let grouping: Array = localeDef.grouping;
let currency: [string, string] = localeDef.currency;
let numerals: string[] | undefined = localeDef.numerals;

localeObj = d3Format.formatLocale(localeDef);

localeObj = d3Format.formatDefaultLocale(localeDef);

let formatFactory: (specifier: string) => ((n: number) => string) = localeObj.format;
let formatPrefixFactory: (specifier: string, value: number) => ((n: number) => string) = localeObj.formatPrefix;
github DefinitelyTyped / DefinitelyTyped / types / d3-format / d3-format-tests.ts View on Github external
localeDef = {
  decimal: "\u066b",
  thousands: "\u066c",
  grouping: [3],
  currency: ["", ""],
  percent : "\u202f%"
};

let decimal: string = localeDef.decimal;
let thousands: string = localeDef.thousands;
let grouping: number[] = localeDef.grouping;
let currency: [string, string] = localeDef.currency;
let numerals: string[] | undefined = localeDef.numerals;
let percent: string | undefined = localeDef.percent;

localeObj = d3Format.formatLocale(localeDef);

localeObj = d3Format.formatDefaultLocale(localeDef);

let formatFactory: (specifier: string) => ((n: number) => string) = localeObj.format;
let formatPrefixFactory: (specifier: string, value: number) => ((n: number) => string) = localeObj.formatPrefix;
github susielu / d3-legend / src / symbol.js View on Github external
legend.locale = function(_) {
    if (!arguments.length) return locale
    locale = formatLocale(_)
    return legend
  }
github qlik-oss / picasso.js / packages / picasso.js / src / core / formatter / d3 / numberFormat.js View on Github external
format.locale = function localeFn(settings) {
    locale = formatLocale(settings);
    d3format = locale.format(pattern);

    return this;
  };
github alleyinteractive / simplechart / app / utils / createFormatter.js View on Github external
function buildD3Format(settings) {
  const locale = formatLocale(
    getLocaleSettings(parseInt(settings.locale, 10))
  );
  return locale.format(buildD3FormatSpecifier(settings));
}
github orbiting / mdast / packages / template-newsletter / src / web / RepublikShareholder.js View on Github external
import React from 'react'
import {css} from 'glamor'
import {formatLocale} from 'd3-format'

import {groupped, total, totalChf, colors} from './RepublikShareholder.data'

const nbspNumbers = formatLocale({
  decimal: ',',
  thousands: '\u00a0',
  grouping: [3],
  currency: ['CHF\u00a0', '']
})
const countFormat = nbspNumbers.format(',.0f')
const percentFormat = nbspNumbers.format(' 05.1%')

const PADDING = 20

const styles = {
  num: css({
    textAlign: 'right !important',
    fontFeatureSettings: '"tnum" 1, "kern" 1'
  }),
  table: css({
github orbiting / republik-frontend / components / Shareholder / Sunburst.js View on Github external
import React from 'react'
import { css } from 'glamor'

import { formatLocale } from 'd3-format'
import { arc } from 'd3-shape'
import { partition } from 'd3-hierarchy'
import { ascending, descending } from 'd3-array'

import { groupped, total, colors } from './data'

import { fontFamilies } from '@project-r/styleguide'

const nbspNumbers = formatLocale({
  decimal: ',',
  thousands: '\u00a0',
  grouping: [3],
  currency: ['CHF\u00a0', '']
})
const percentFormat = nbspNumbers.format('.1%')

const styles = {
  container: css({
    position: 'relative',
    height: 0,
    width: '100%',
    paddingBottom: '100%'
  }),
  svg: css({
    fontFamily: fontFamilies.sansSerifRegular,
github susielu / d3-legend / indexRollupNext.js View on Github external
legend.locale = function (_) {
    if (!arguments.length) return locale;
    locale = formatLocale(_);
    return legend;
  };