@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
139 lines (130 loc) • 4.96 kB
JavaScript
import {AssetPathContext as $hLPki$AssetPathContext, ColumnContext as $hLPki$ColumnContext} from "./column-components.fa405a9f.js";
import {UUIDComponent as $78cda86e161567e8$export$748c8bb116429550} from "./column-components.e19a4b4d.js";
import {useContext as $hLPki$useContext, Component as $hLPki$Component} from "react";
import $hLPki$macrostrathyper from "@macrostrat/hyper";
import $hLPki$classnames from "classnames";
const $273a9b4317745b8c$var$symbolIndex = {
"Hummocky cross-stratified": "hcs.svg",
"Trough cross-stratified": "tcs.svg",
"Dessication cracks": "dessication-cracks.svg",
Ooids: "ooids.svg",
"Domal stromatolites": "domal-stromatolites.svg",
"Digitate stromatolites": "digitate-stromatolites.svg"
};
const $273a9b4317745b8c$var$Symbol = function(props) {
const { symbol: symbol, width: width, height: height, UUID: UUID } = props;
const { resolveSymbol: resolveSymbol } = (0, $hLPki$useContext)((0, $hLPki$AssetPathContext));
const id = `${UUID}-${symbol}`;
const symbolSize = {
width: width
};
const href = resolveSymbol($273a9b4317745b8c$var$symbolIndex[symbol]);
return (0, $hLPki$macrostrathyper)("symbol", {
id: id,
key: id,
...symbolSize
}, [
(0, $hLPki$macrostrathyper)("image", {
href: href,
x: 0,
y: 0,
...symbolSize
})
]);
};
const $273a9b4317745b8c$var$SymbolDefs = function(props) {
const { patterns: patterns, ...rest } = props;
const ids = [];
return (0, $hLPki$macrostrathyper)("defs", patterns.map(function(sym) {
const { symbol: symbol } = sym;
if (ids.includes(symbol)) return null;
ids.push(symbol);
return (0, $hLPki$macrostrathyper)($273a9b4317745b8c$var$Symbol, {
symbol: symbol,
...rest
});
}));
};
class $273a9b4317745b8c$export$9e9de4642374fdfb extends (0, $78cda86e161567e8$export$748c8bb116429550) {
constructor(props){
super(props);
this.renderSymbol = this.renderSymbol.bind(this);
}
static{
this.contextType = (0, $hLPki$ColumnContext);
}
static{
this.defaultProps = {
width: 30,
left: 0
};
}
render() {
const { scale: scale, pixelHeight: pixelHeight, zoom: zoom } = this.context;
const { left: left, width: width } = this.props;
let { symbols: symbols } = this.props;
const patterns = symbols.filter((x, i, arr)=>arr.indexOf(x) === i);
let transform = null;
if (left != null) transform = `translate(${left})`;
symbols = symbols.filter((d)=>d.symbol_min_zoom < zoom).map(this.renderSymbol);
const x = 0;
const y = 0;
return (0, $hLPki$macrostrathyper)("g.symbol-column", {
transform: transform
}, [
(0, $hLPki$macrostrathyper)($273a9b4317745b8c$var$SymbolDefs, {
width: width,
patterns: patterns,
UUID: this.UUID
}),
(0, $hLPki$macrostrathyper)("rect.symbol-column-area", {
width: width,
height: pixelHeight
}),
(0, $hLPki$macrostrathyper)("g.symbols", symbols)
]);
}
renderSymbol(d) {
const { scale: scale, pixelHeight: pixelHeight } = this.context;
const { symbol: symbol, id: id, height: height } = d;
const className = (0, $hLPki$classnames)({
symbol: symbol
}, "symbol");
const { width: width } = this.props;
const y = scale(height) - width / 2;
if (y < 0 || y > pixelHeight) return null;
const href = `#${this.UUID}-${symbol}`;
return (0, $hLPki$macrostrathyper)("use", {
className: className,
y: y,
x: 0,
width: width,
xlinkHref: href,
key: id
});
}
}
class $273a9b4317745b8c$export$b0d2f3fc21b599a7 extends (0, $hLPki$Component) {
static{
this.contextType = (0, $hLPki$AssetPathContext);
}
render() {
const { resolveSymbol: resolveSymbol } = this.context;
const arr = [];
for(let name in $273a9b4317745b8c$var$symbolIndex){
const symbol = $273a9b4317745b8c$var$symbolIndex[name];
const sym = (0, $hLPki$macrostrathyper)("div", {
key: name
}, [
(0, $hLPki$macrostrathyper)("img", {
src: resolveSymbol(symbol)
}),
(0, $hLPki$macrostrathyper)("span.label", name)
]);
arr.push(sym);
}
return (0, $hLPki$macrostrathyper)("div.symbol-legend", arr);
}
}
export {$273a9b4317745b8c$export$9e9de4642374fdfb as SymbolColumn, $273a9b4317745b8c$export$b0d2f3fc21b599a7 as SymbolLegend};
//# sourceMappingURL=column-components.d19de64a.js.map