1

Following Mike Bostock's great tutorial on command-line cartography, when trying to produce a choropleth, I receive a TypeError saying that d3.scaleSequential is not a function. I imagine it is just not being exposed? But I don't know how to deal with that through the CLI...?

Error Traceback:

TypeError: d3.scaleSequential is not a function
    at evalmachine.:1:26
    at Interface. (/usr/local/lib/node_modules/ndjson-cli/ndjson-map:45:14)
    at emitOne (events.js:77:13)
    at Interface.emit (events.js:169:7)
    at Interface._onLine (readline.js:210:10)
    at Interface. (readline.js:340:12)
    at Array.forEach (native)
    at Interface._normalWrite (readline.js:339:11)
    at ReadStream.ondata (readline.js:86:10)
    at emitOne (events.js:77:13)

I have all of the needed libraries installed and updated through npm, so that isn't the issue..any thoughts on how to debug this would be greatly appreciated.

Currently Installed:

  • d3@4.9.1
  • d3-geo-projection@2.1.2
  • d3-scale@1.0.6
  • d3-scale-chromatic@1.1.1

Sample Code

The code is copied pretty much straight from the tutorial and this is the first step that doesn't work..

ndjson-map -r d3 \
  '(d.properties.fill = d3.scaleSequential(d3.interpolateViridis).domain([0, 4000])(d.properties.density), d)' \
   ca-albers-color.ndjson
David Hagan
  • 1,156
  • 12
  • 23
  • 2
    What version of D3 are you using? – Gerardo Furtado Jun 05 '17 at 11:50
  • I had a similar error when I tried to shift from the full d3.v4 to the individual libraries (d3.scaleOrdinal was the one I was missing). I haven't got round to troubleshooting it yet, but I'll be back if I figure it out. – Oliver Houston Jun 05 '17 at 12:21
  • I think you need to install the scale functions separately - `npm install -g d3-scale` – madebydavid Jun 05 '17 at 13:08
  • @madebydavid `d3.scaleSequential()` is part of the default bundle. – Gerardo Furtado Jun 05 '17 at 13:32
  • @madebydavid Just updated with versions...oops – David Hagan Jun 05 '17 at 16:30
  • Can you add some code to show how it's being called? – anbnyc Jun 05 '17 at 16:46
  • @anbnyc Added the sample code. – David Hagan Jun 05 '17 at 16:48
  • I'd try changing it temporarily to a different type of scale to make sure that `d3` is loaded correctly. At least then you can rule that out...it looks like you're calling the function correctly, though I think you need a `>` in front of the file name on the next line. – anbnyc Jun 05 '17 at 16:56
  • @anbnyc It appears that's the issue. I changed it to another scale and see the same missing function TypeError. Is there a reason `-r d3` wouldn't work? – David Hagan Jun 05 '17 at 17:08
  • I think it's related to this: https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package. Workaround is to just `npm install` in the local folder. – anbnyc Jun 05 '17 at 17:11

1 Answers1

1

When you are using the CLI, d3 needs to be accessible to node.js, so you should npm install -g d3 (global), or in the directory from which you're running the command line scripts, npm install d3.

UPDATE: If you use the global approach, you may need to link the package (https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/) or set your NODE_PATH variable to have access to the folder where global modules are installed.

anbnyc
  • 911
  • 6
  • 13