d3 / d3-scale-chromatic

Sequential, diverging and categorical color scales.
https://d3js.org/d3-scale-chromatic
Other
801 stars 106 forks source link

does it support es6 import? #14

Closed zhuyinjing closed 6 years ago

zhuyinjing commented 6 years ago

hey . i use Vue.js in my project. and i want to use d3-scale-chromatic in my project. i try

`import 'd3-color'

import 'd3-interpolate'

import 'd3-scale-chromatic'`

and when i console.log(d3.interpolateYlGn(0)) it shows error __WEBPACK_IMPORTED_MODULE_0_d3__.interpolateYlGn is not a function what's wrong with my code? thanks a lot!!!

Ledragon commented 6 years ago
import * as d3Color from 'd3-color'
import * as d3Interpolate from 'd3-interpolate'
import * as d3ScaleChromatic from 'd3-scale-chromatic'

Also, here is a reference for creating your own bundle. Try using StackOverflow for that kind of questions ;-)

colinmegill commented 6 years ago

Hey all - thanks for a great module. Not seeing the recommended ES6 pattern in the README, I checked for closed issues on a whim and found this.

FWIW, I think this is worth adding after the npm install instructions there, along with possibly an explanation of why it works like that / why those packages are also required.

curran commented 6 years ago

I believe the preferred method would look something like this:

import { schemeBlues } from 'd3-scale-chromatic';

Any of the API methods of the form d3.x from this package can be imported as import { x } from 'd3-scale-chromatic'.

colinmegill commented 6 years ago

Way better, thank you @curran