Public
Edited
Feb 13, 2023
16 stars
Insert cell
Insert cell
{
const app = new PIXI.Application({
antialias: true,
transparent: true,
width,
height: 200,
resolution: devicePixelRatio || 1
});
invalidation.then(() => app.destroy(true, true));

const context = new PIXI.Graphics();
app.stage.addChild(context);

let v = 150;
const data = Array.from({ length: width / 20 }, (_, i) => [
10 + i * 20,
(v += 25 * (Math.random() - .55))
]);

const area = d3
.area()
.y0(199)
.context(context);

const line = d3.line().context(context);

context.clear();

context.lineStyle(.5);
context.beginFill(0xeeeeee);
area(data);
context.endFill();

context.lineStyle(2);
line.curve(d3.curveBasis)(data);

context.lineStyle(1);
context.beginFill(0xee7777);
line.curve(curvePoints(3))(data);
context.endFill();

return Object.assign(app.view, { style: `width: ${width}px` });
}
Insert cell
Insert cell
{
const context = contextPixi(width, height, invalidation);

const path = d3.geoPath(projection).context(context);

// Rectangle
context.clear();

context.lineStyle(1, 0x000000, 1);
context.beginFill(0xfefee2);
path(land); // almost!
context.endFill();

context.lineStyle(3, 0x000000, 1);
path({ type: "Sphere" });
context.endFill();

return context.canvas;
}
Insert cell
PIXI = import("https://cdn.jsdelivr.net/npm/pixi.js@6.5.9/+esm")
Insert cell
contextPixi = (width, height, invalidation, resolution) => {
if (!invalidation) throw new Error("please pass an invalidation method");

const app = new PIXI.Application({
antialias: true,
transparent: true,
width,
height,
resolution: resolution || devicePixelRatio || 1
});
invalidation.then(() => app.destroy(true, true));

const context = new PIXI.Graphics();
app.stage.addChild(context);

app.view.style = `width: ${width}px`;
context.canvas = app.view;
return context;
}
Insert cell
projection = d3.geoBertin1953().fitSize([width, height], { type: "Sphere" })
Insert cell
height = width * 0.6
Insert cell
d3 = require("d3@7", "d3-geo-projection@4")
Insert cell
land = d3.json(
"https://unpkg.com/visionscarto-world-atlas@0.0.6/world/110m_land.geojson"
)
Insert cell
import { curvePoints } from "5c4650cfb7214d6c"
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