Some d3-scaleordinal exemple not working using d3@5

Hi,
I’m trying to reproduce the exemple of Map for range and domain in Observable documentation (https://observablehq.com/@d3/d3-scaleordinal) :

atoms = new Map([["C", 12], ["H", 1], ["O", 16]])
colors = new Map([["C", "black"], ["H", "white"], ["O", "blue"]])

m = d3.scaleOrdinal()
  .domain(atoms.keys())
  .range(colors.values())

m("C")

Using d3 = require("d3-scale@3", "d3-scale-chromatic@1", "d3-shape@1", "d3-array@2") it works, but in my observable notebook i use d3@5 and this exemple return “undefined”

What is the equivalent of this exemple in d3@5 ?

the newest versions accept Map Iterators as inputs, if you’re using d3@5 you can try this

    m = d3
      .scaleOrdinal()
      .domain([...atoms.keys()])
      .range([...colors.values()])
1 Like