@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
3 lines (2 loc) • 3.1 kB
JavaScript
import"./column-components.298cc9f3.js";import"./column-components.7c8d9782.js";import{scaleLinear as e}from"d3-scale";import{useContext as t,createElement as r}from"react";import n from"@macrostrat/hyper";import{path as o}from"d3-path";function l(e,t,r,n){Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0})}var i=globalThis,s={},a={},u=i.parcelRequirea149;null==u&&((u=function(e){if(e in s)return s[e].exports;if(e in a){var t=a[e];delete a[e];var r={id:e,exports:{}};return s[e]=r,t.call(r.exports,r,r.exports),r.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){a[e]=t},i.parcelRequirea149=u),u.register;var c={};l(c,"FloodingSurface",()=>h),l(c,"TriangleBars",()=>p);var f=u("aVUB5"),d=u("ig5HY");function h(e){let{scale:r,divisions:o}=t(f.ColumnContext),{offsetLeft:l=-90,lineWidth:i=50,onClick:s}=e,a=o.filter(e=>null!=e.flooding_surface_order);return a.length?n("g.flooding-surface",null,a.map(function(e){let t=r(e.bottom);return n("line.flooding-surface",{transform:`translate(${l} ${t})`,onClick:s,key:e.id,strokeWidth:(6-Math.abs(e.flooding_surface_order))*.75,stroke:e.flooding_surface_order>=0?"#ccc":"#fcc",x1:0,x2:i})})):null}class p extends d.UUIDComponent{constructor(e){super(e),this.renderSurfaces=this.renderSurfaces.bind(this)}static #e=this.contextType=f.ColumnContext;static #t=this.defaultProps={offsetLeft:-90,lineWidth:50,order:2};render(){let{offsetLeft:t,lineWidth:l,order:i,orders:s,minOrder:a,maxOrder:u}=this.props,{scale:c,zoom:f,divisions:d}=this.context;null==s&&null!=a&&null!=u&&(s=function e(t,r){return t===r?[t]:[t,...e(t+1,r)]}(a,u));let[h,p]=c.range();null==s&&null!=i&&(s=[i]),s.reverse();let m=o(),g=function(t,r,n,o=5,l=2){let i=e().domain([0,o]).range([t,r]);m.lineTo(t,n);for(let e=0,t=0<=o;t?e<o:e>o;t?e++:e--){let t=i(e),r=n;e%2==1&&(r+=l),m.lineTo(t,r)}return m.lineTo(r,n)};return m.moveTo(-l,0),g(-l,l,h-p,16,3),g(l,-l,0,16,3),m.closePath(),n("g.triangle-bars",{},[n("defs",[r("clipPath",{id:this.UUID},[n("path",{d:m.toString(),key:this.UUID+"-path"})])]),s.map(this.renderSurfaces)])}renderSurfaces(e,t){let r,l,{scale:i,zoom:s,divisions:a}=this.context,{offsetLeft:u,lineWidth:c}=this.props;if(!a.length)return null;let f=c/2,d=[];for(l=0;l<a.length;l++){let{surface_type:t,surface_order:n}=r=a[l];if(null==t||null==n||!(n<=e))continue;let o=i(r.bottom);if("mfs"===t&&d.push(["mfs",o]),"sb"===t){if(0===d.length){d.push(["sb",o]);continue}let e=d.length-1;"sb"===d[e][0]?d[e][1]=o:d.push(["sb",o])}}if(!d.length)return null;let h=o(),p=null,m=null;for(l=0;l<d.length;l++){let e=d[l];"mfs"===e[0]&&null!=p&&(h.moveTo(0,p[1]),null!=m?(h.lineTo(f,m[1]),h.lineTo(0,e[1]),h.lineTo(-f,m[1])):(h.lineTo(f,e[1]),h.lineTo(-f,e[1])),h.closePath(),m=null,p=null),"mfs"===e[0]?p=e:"sb"===e[0]&&(m=e)}return n(`g.level-${e}`,{clipPath:`url(#${this.UUID})`,transform:`translate(${-c*(2+t)+(u+2*c+5)})`,key:this.UUID+"-"+e},[n("path",{d:h.toString(),key:this.UUID+"-"+e})])}}export{h as FloodingSurface,p as TriangleBars};
//# sourceMappingURL=column-components.c7977243.js.map