mirror of
https://github.com/d3/d3.git
synced 2025-12-08 19:46:24 +00:00
28 lines
648 B
JavaScript
28 lines
648 B
JavaScript
// https://github.com/observablehq/stdlib/
|
|
|
|
var count = 0;
|
|
|
|
export function uid(name) {
|
|
return new Id("O-" + (name == null ? "" : name + "-") + ++count);
|
|
}
|
|
|
|
function Id(id) {
|
|
this.id = id;
|
|
this.href = new URL(`#${id}`, location) + "";
|
|
}
|
|
|
|
Id.prototype.toString = function () {
|
|
return "url(" + this.href + ")";
|
|
};
|
|
|
|
export function context2d(width, height, dpi) {
|
|
if (dpi == null) dpi = devicePixelRatio;
|
|
var canvas = document.createElement("canvas");
|
|
canvas.width = width * dpi;
|
|
canvas.height = height * dpi;
|
|
canvas.style.width = width + "px";
|
|
var context = canvas.getContext("2d");
|
|
context.scale(dpi, dpi);
|
|
return context;
|
|
}
|