Published
Edited
Nov 28, 2019
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
failure = {
const svg = selection.create('svg')

const foreignObject = svg.append('foreignObject')
.attr('width', width)
.attr('height', height);

const canvas = foreignObject.append('canvas')

const node = canvas.node().nodeName
const constructor = canvas.node().constructor.name
try {
const context = canvas.node().getContext('2d')
context.fillStyle = 'blue';
context.fillRect(0, 0, width, height);
} catch (error) {
return { svg, node, constructor, error };
}
}
Insert cell
failure.svg.node()
Insert cell
Insert cell
success = {
const svg = selection.create('svg')

const foreignObject = svg.append('foreignObject')
.attr('width', width)
.attr('height', height);

const canvas = foreignObject.node().appendChild(document.createElement('canvas'));

const node = canvas.nodeName
const constructor = canvas.constructor.name

const context = canvas.getContext('2d')

context.fillStyle = 'blue';
context.fillRect(0, 0, width, height);

return { svg, node, constructor };
}
Insert cell
success.svg.node()
Insert cell
Insert cell
nonIssue = {
const div = selection.create('div')

const canvas = div.append('canvas')

const context = canvas.node().getContext('2d')

// Debugging
const node = canvas.node().nodeName
const constructor = canvas.node().constructor.name

context.fillStyle = 'blue';
context.fillRect(0, 0, width, height);

return { div, node, constructor };
}
Insert cell
nonIssue.div.node()
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more