UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

178 lines (168 loc) 6.66 kB
import {ColumnContext as $gIgo1$ColumnContext} from "./column-components.fa405a9f.js"; import {UUIDComponent as $78cda86e161567e8$export$748c8bb116429550} from "./column-components.e19a4b4d.js"; import {scaleLinear as $gIgo1$scaleLinear} from "d3-scale"; import {useContext as $gIgo1$useContext, createElement as $gIgo1$createElement} from "react"; import $gIgo1$macrostrathyper from "@macrostrat/hyper"; import {path as $gIgo1$path} from "d3-path"; function $012d8e35d5f97275$export$dfee4a5d7e261765(props) { const { scale: scale, divisions: divisions } = (0, $gIgo1$useContext)((0, $gIgo1$ColumnContext)); const { offsetLeft: offsetLeft = -90, lineWidth: lineWidth = 50, onClick: onClick } = props; const floodingSurfaces = divisions.filter((d)=>d.flooding_surface_order != null); if (!floodingSurfaces.length) return null; return (0, $gIgo1$macrostrathyper)("g.flooding-surface", null, floodingSurfaces.map(function(d) { const y = scale(d.bottom); const x = offsetLeft; return (0, $gIgo1$macrostrathyper)("line.flooding-surface", { transform: `translate(${x} ${y})`, onClick: onClick, key: d.id, strokeWidth: (6 - Math.abs(d.flooding_surface_order)) * 0.75, stroke: d.flooding_surface_order >= 0 ? "#ccc" : "#fcc", x1: 0, x2: lineWidth }); })); } function $012d8e35d5f97275$var$range(start, end) { if (start === end) return [ start ]; return [ start, ...$012d8e35d5f97275$var$range(start + 1, end) ]; } class $012d8e35d5f97275$export$c83cb676dc28c80d extends (0, $78cda86e161567e8$export$748c8bb116429550) { constructor(props){ super(props); this.renderSurfaces = this.renderSurfaces.bind(this); } static{ this.contextType = (0, $gIgo1$ColumnContext); } static{ this.defaultProps = { offsetLeft: -90, lineWidth: 50, order: 2 }; } render() { let { offsetLeft: offsetLeft, lineWidth: lineWidth, order: order, orders: orders, minOrder: minOrder, maxOrder: maxOrder } = this.props; const { scale: scale, zoom: zoom, divisions: divisions } = this.context; if (orders == null && minOrder != null && maxOrder != null) orders = $012d8e35d5f97275$var$range(minOrder, maxOrder); const [bottom, top] = scale.range(); if (orders == null && order != null) orders = [ order ]; orders.reverse(); const _ = (0, $gIgo1$path)(); const zigZagLine = function(x0, x1, y, nzigs = 5, a = 2) { //_.moveTo(start...) const xs = (0, $gIgo1$scaleLinear)().domain([ 0, nzigs ]).range([ x0, x1 ]); _.lineTo(x0, y); for(let i = 0, end = nzigs, asc = 0 <= end; asc ? i < end : i > end; asc ? i++ : i--){ const x_ = xs(i); let y_ = y; if (i % 2 === 1) y_ += a; _.lineTo(x_, y_); } return _.lineTo(x1, y); }; const btm = bottom - top; _.moveTo(-lineWidth, 0); zigZagLine(-lineWidth, lineWidth, btm, 16, 3); zigZagLine(lineWidth, -lineWidth, 0, 16, 3); _.closePath(); return (0, $gIgo1$macrostrathyper)("g.triangle-bars", {}, [ (0, $gIgo1$macrostrathyper)("defs", [ (0, $gIgo1$createElement)("clipPath", { id: this.UUID }, [ (0, $gIgo1$macrostrathyper)("path", { d: _.toString(), key: this.UUID + "-path" }) ]) ]), orders.map(this.renderSurfaces) ]); } renderSurfaces(order, index) { let d, i; const { scale: scale, zoom: zoom, divisions: divisions } = this.context; const { offsetLeft: offsetLeft, lineWidth: lineWidth } = this.props; if (!divisions.length) return null; const w = lineWidth / 2; const ol = offsetLeft + lineWidth * 2 + 5; const __ = []; for(i = 0; i < divisions.length; i++){ d = divisions[i]; const { surface_type: surface_type, surface_order: surface_order } = d; if (surface_type == null || surface_order == null) continue; if (!(surface_order <= order)) continue; const height = scale(d.bottom); if (surface_type === "mfs") __.push([ "mfs", height ]); if (surface_type === "sb") { if (__.length === 0) { __.push([ "sb", height ]); continue; } const sz = __.length - 1; if (__[sz][0] === "sb") __[sz][1] = height; else __.push([ "sb", height ]); } } if (!__.length) return null; const _ = (0, $gIgo1$path)(); let basalMFS = null; let sequenceBoundary = null; for(i = 0; i < __.length; i++){ const top = __[i]; if (top[0] === "mfs" && basalMFS != null) { _.moveTo(0, basalMFS[1]); if (sequenceBoundary != null) { _.lineTo(w, sequenceBoundary[1]); _.lineTo(0, top[1]); _.lineTo(-w, sequenceBoundary[1]); _.closePath(); } else { _.lineTo(w, top[1]); _.lineTo(-w, top[1]); _.closePath(); } sequenceBoundary = null; basalMFS = null; } if (top[0] === "mfs") basalMFS = top; else if (top[0] === "sb") sequenceBoundary = top; } return (0, $gIgo1$macrostrathyper)(`g.level-${order}`, { clipPath: `url(#${this.UUID})`, transform: `translate(${-lineWidth * (2 + index) + ol})`, key: this.UUID + "-" + order }, [ (0, $gIgo1$macrostrathyper)("path", { d: _.toString(), key: this.UUID + "-" + order }) ]); } } export {$012d8e35d5f97275$export$dfee4a5d7e261765 as FloodingSurface, $012d8e35d5f97275$export$c83cb676dc28c80d as TriangleBars}; //# sourceMappingURL=column-components.1b525ec1.js.map