observablehq

Return value in non-function Javascript code block

浪子不回头ぞ 提交于 2019-12-04 05:22:40
问题 I'm trying to work out what's going on in Mike Bostock's Box Plot example from the D3 gallery. Here's the code inside an Observable notebook: https://observablehq.com/@d3/box-plot In it there's a code block that does not appear to be a function definition but that has a return value: chart = { const svg = d3.select(DOM.svg(width, height)); const g = svg.append("g") .selectAll("g") .data(bins) .join("g"); // [...] return svg.node(); } What does return do or mean when it is not in a function

“Uncaught ReferenceError: DOM is not defined” d3.select(DOM.svg(500, 50))

柔情痞子 提交于 2019-12-04 04:12:32
问题 I understand this line of D3 code which adds an SVG element to the body of an HTML page, and stores a reference to the new element in the variable 'svg': var svg = d3.select('body').append('svg').attr('width', 500).attr('height', 50); It is used, for example, in Scott Murray's book Interactive Data Visualization for the Web, 2nd Edition here. More recently I've seen this pattern: const svg = d3.select(DOM.svg(500, 50)); (e.g. in this example or this tutorial). I'd like to work out what this