@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
89 lines (79 loc) • 2.83 kB
JavaScript
import {ColumnContext as $iomY5$ColumnContext} from "./column-components.0ccab336.js";
import $iomY5$macrostrathyper from "@macrostrat/hyper";
import {useContext as $iomY5$useContext} from "react";
import $iomY5$classnames from "classnames";
import $iomY5$uibox from "ui-box";
import {path as $iomY5$path} from "d3-path";
function $d16be394456cbec0$export$32a0ad71237b9760(props) {
const { offsetTop: offsetTop, absolutePosition: absolutePosition, className: className, ...rest } = props;
const { pixelsPerMeter: pixelsPerMeter, zoom: zoom } = (0, $iomY5$useContext)((0, $iomY5$ColumnContext));
const marginTop = offsetTop * pixelsPerMeter * zoom;
let pos = {
marginTop: marginTop
};
if (absolutePosition) pos = {
position: "absolute",
top: marginTop
};
return (0, $iomY5$macrostrathyper)((0, $iomY5$uibox), {
className: (0, $iomY5$classnames)("column-box", className),
...pos,
...rest
});
}
function $d16be394456cbec0$export$3043bd3cc20d22a5(x, y, width, height, top, bottom) {
const d = (0, $iomY5$path)();
const x1 = x + width;
// Start path at the top
d.moveTo(x, y);
if (top) $d16be394456cbec0$export$2cf300d53db8f1c(d, x, x1, y);
else d.lineTo(x1, y);
const yBottom = y + height;
d.lineTo(x1, yBottom);
// Draw the bottom
if (bottom) $d16be394456cbec0$export$2cf300d53db8f1c(d, x1, x, yBottom);
else d.lineTo(x, yBottom);
// Draw the left edge
d.closePath();
// Now render the path;
return d.toString();
}
function $d16be394456cbec0$export$2cf300d53db8f1c(d, x0, x1, y) {
const zigZagWidth = 10;
const zigZagHeight = 4;
const deltaX = x1 - x0;
const width = Math.abs(deltaX);
const nZigZags = Math.floor(width / zigZagWidth - 0.5);
const _zigZagWidth = width / (nZigZags + 0.5);
let dy = zigZagHeight / 2;
// Each zig-zag consists of a short outward motion
let dx = _zigZagWidth / 4;
let cx = x0;
let cy = y;
if (deltaX < 0) {
dx = -dx;
dy = -dy;
}
const doZigZag = (last = false)=>{
cx += dx;
cy -= dy;
d.lineTo(cx, cy);
let scalar = last ? 1 : 2;
cx += dx * scalar;
cy += dy * scalar;
d.lineTo(cx, cy);
cx += dx;
cy -= dy;
};
d.lineTo(x0, y);
// Move to the offset
//d.lineTo(cx, y);
// Draw the zig-zags
for(let i = 0; i < nZigZags; i++)doZigZag();
// Draw the last half zig-zag
doZigZag(true);
// Draw to the edge
d.lineTo(x1, y);
}
export {$d16be394456cbec0$export$32a0ad71237b9760 as ColumnBox, $d16be394456cbec0$export$3043bd3cc20d22a5 as zigZagBoxPath, $d16be394456cbec0$export$2cf300d53db8f1c as drawZigZagAtConstantHeight};
//# sourceMappingURL=column-components.343c1972.js.map