Published
Edited
Sep 28, 2021
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getCanvasSizeFromPreset("a4", 96, "landscape")
Insert cell
getCanvasSizeFromPreset = (preset, ppiTarget, orientation) => {
let {dimensions, units, ppi} = getDimensionsFromPreset(preset, "px", ppiTarget);
let result = dimensions;
const highest = Math.max(result[0], result[1]);
const lowest = Math.min(result[0], result[1]);
const isLandscape = orientation === 'landscape';
const w = isLandscape ? highest : lowest;
const h = isLandscape ? lowest : highest;
return getCanvasSize(w, h, units, ppiTarget);
}
Insert cell
Insert cell
getCanvasSize = (w, h, units, ppi=72) => {
let size = realDimensions(w, h, units, ppi);
return size.map(Math.round);
}
Insert cell
realDimensions = (w, h, units, ppi) => {
let realW = convertDistance(w, units, 'px', ppi);
let realH = convertDistance(h, units, 'px', ppi);
return [realW, realH];
}
Insert cell
Insert cell
Insert cell
Insert cell
getDimensionsFromPreset("a4")
Insert cell
Insert cell
convertLength(210, 'mm', 'px', {pixelsPerInch: 300})
Insert cell
convertLength(210, 'mm', 'px')
Insert cell
convertDistance = (dimension, unitsFrom ='px', unitsTo = 'px', pixelsPerInch = 72) => {
return convertLength(dimension, unitsFrom, unitsTo, {
pixelsPerInch,
precision: 4,
roundPixel: true
})};
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more