UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

84 lines (75 loc) 2.87 kB
import $f5b828bbb980a05d$export$2e2bcd8739ae039 from "./column-components.e1d11b63.js"; import {useColumn as $i30LL$useColumn} from "./column-components.fa405a9f.js"; import {useRef as $i30LL$useRef, useEffect as $i30LL$useEffect} from "react"; import {select as $i30LL$select} from "d3-selection"; import {axisLeft as $i30LL$axisLeft} from "d3-axis"; const $b4e0040440f6983c$var$__d3axisKeys = [ "ticks", "tickArguments", "tickValues", "tickFormat", "tickSize", "tickSizeInner", "tickSizeOuter", "tickPadding" ]; function $b4e0040440f6983c$export$59643c0aa17d0c6f(props) { const { scale: scale } = (0, $i30LL$useColumn)(); return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($b4e0040440f6983c$export$25ce20521d0ab97d, { scale: scale, ...props }); } function $b4e0040440f6983c$export$25ce20521d0ab97d(props) { const { showLabel: showLabel, className: className, showDomain: showDomain = true, tickSpacing: tickSpacing = 60, scale: scale } = props; const range = scale.range(); const pixelHeight = Math.abs(range[0] - range[1]); let tickValues = undefined; if (pixelHeight < 3 * tickSpacing || scale.ticks(2).length < 2) { // Push ticks towards extrema const t0 = scale.ticks(4); tickValues = [ t0[0], t0[t0.length - 1] ]; } const defaultProps = { ticks: Math.max(Math.round(pixelHeight / tickSpacing), 2), // Suppress domain endpoints tickSizeOuter: 0, tickValues: tickValues }; const ref = (0, $i30LL$useRef)(null); const axisRef = (0, $i30LL$useRef)((0, $i30LL$axisLeft)()); const deps = $b4e0040440f6983c$var$__d3axisKeys.map((k)=>props[k]); (0, $i30LL$useEffect)(()=>{ const el = ref.current; if (!el) return; axisRef.current.scale(scale); for (let k of $b4e0040440f6983c$var$__d3axisKeys){ const val = props[k] ?? defaultProps[k]; if (val == null) continue; axisRef.current[k](val); } const ax = (0, $i30LL$select)(el).call(axisRef.current); if (!showDomain) ax.select(".domain").remove(); ax.selectAll(".tick text").each(function(d) { if (!(showLabel?.(d) ?? true)) (0, $i30LL$select)(this).attr("visibility", "hidden"); }); return ()=>{ (0, $i30LL$select)(el).selectAll("*").remove(); }; }, [ scale, ref.current, showDomain, showLabel, ...deps ]); return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g.y.axis.column-axis", { className: className, ref: ref }); } export {$b4e0040440f6983c$export$59643c0aa17d0c6f as ColumnAxis, $b4e0040440f6983c$export$25ce20521d0ab97d as AgeAxis}; //# sourceMappingURL=column-components.1606addb.js.map