UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

63 lines (56 loc) 2.34 kB
import {useColumnLayout as $1Ub8P$useColumnLayout} from "./column-components.0ccab336.js"; import {scaleLinear as $1Ub8P$scaleLinear, scaleOrdinal as $1Ub8P$scaleOrdinal} from "d3-scale"; import $1Ub8P$macrostrathyper from "@macrostrat/hyper"; const $5716f15771204739$export$1091bccbbb82a54e = [ "ms", "s", "vf", "f", "m", "c", "vc", "p" ]; const $5716f15771204739$export$84fd9e10d6f56aa2 = function(range) { /** A basic grainsize scale that will work in many situations */ const scale = (0, $1Ub8P$scaleLinear)().domain([ 0, $5716f15771204739$export$1091bccbbb82a54e.length - 1 ]).range(range); const tickPositions = $5716f15771204739$export$1091bccbbb82a54e.map((d, i)=>scale(i)); return (0, $1Ub8P$scaleOrdinal)().domain($5716f15771204739$export$1091bccbbb82a54e).range(tickPositions); }; function $5716f15771204739$export$ebb327f2f5689a1c({ height: height = 20 }) { const { grainsizeScale: gs, pixelHeight: pixelHeight } = (0, $1Ub8P$useColumnLayout)(); if (gs == null) throw "GrainsizeAxis must be a child of a GrainsizeScaleProvider"; const sizes = gs.domain(); // check length of sizes and rotate labels if necessary let strlen = sizes.reduce((acc, d)=>acc + d.length, 0) / sizes.length; let className = ""; if (strlen > 2) className = "rotated"; return (0, $1Ub8P$macrostrathyper)("g.grainsize.axis", { className: className }, sizes.map((d)=>{ return (0, $1Ub8P$macrostrathyper)("g.tick", { transform: `translate(${gs(d)} 0)`, key: d }, [ (0, $1Ub8P$macrostrathyper)("text.top", { y: 0 }, d), (0, $1Ub8P$macrostrathyper)("text.bottom", { y: pixelHeight, style: { transformOrigin: `0 ${pixelHeight}px` } }, d), (0, $1Ub8P$macrostrathyper)("line", { y1: 0, x1: 0, x2: 0, y2: pixelHeight }) ]); })); } export {$5716f15771204739$export$1091bccbbb82a54e as grainSizes, $5716f15771204739$export$84fd9e10d6f56aa2 as createGrainsizeScale, $5716f15771204739$export$ebb327f2f5689a1c as GrainsizeAxis}; //# sourceMappingURL=column-components.60e5c989.js.map