@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
1 lines • 2.3 kB
Source Map (JSON)
{"version":3,"file":"height-range.cjs","sources":["../../src/notes/height-range.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport h from \"../hyper\";\nimport { NoteLayoutContext } from \"./layout\";\n\ninterface HeightRangeAnnotationProps {\n height: number;\n top_height?: number;\n offsetX?: number;\n color?: string;\n lineInset?: number;\n circleRadius?: number;\n}\n\nfunction HeightRangeAnnotation(props: HeightRangeAnnotationProps) {\n const { scale } = useContext(NoteLayoutContext);\n const {\n height,\n top_height,\n offsetX = 0,\n color,\n lineInset = 1,\n circleRadius = 2,\n ...rest\n } = props;\n\n const bottomHeight = scale(height);\n let pxHeight = 0;\n if (top_height != null) {\n pxHeight = Math.abs(scale(top_height) - bottomHeight);\n }\n const topHeight = bottomHeight - pxHeight;\n\n /* Use a value slightly greater than the circle diameter as the cutoff\n to switch between line and circle, to account for a circle's greater\n visual weight than the equivalent line height\n */\n const isLine = pxHeight > 3 * Math.max(lineInset, circleRadius);\n\n const transform = `translate(${offsetX},${topHeight})`;\n\n return h(\"g.height-range\", { transform, ...rest }, [\n h.if(isLine)(\"line\", {\n x1: 0,\n x2: 0,\n y1: lineInset,\n y2: pxHeight - lineInset,\n }),\n h.if(!isLine)(\"circle\", {\n r: circleRadius,\n transform: `translate(0,${pxHeight / 2})`,\n }),\n ]);\n}\n\nexport { HeightRangeAnnotation };\n"],"names":["useContext","NoteLayoutContext","h"],"mappings":";;;;;AAaA,SAAS,sBAAsB,OAAmC;AAChE,QAAM,EAAE,MAAA,IAAUA,MAAAA,WAAWC,wBAAiB;AAC9C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,GAAG;AAAA,EAAA,IACD;AAEJ,QAAM,eAAe,MAAM,MAAM;AACjC,MAAI,WAAW;AACf,MAAI,cAAc,MAAM;AACtB,eAAW,KAAK,IAAI,MAAM,UAAU,IAAI,YAAY;AAAA,EACtD;AACA,QAAM,YAAY,eAAe;AAMjC,QAAM,SAAS,WAAW,IAAI,KAAK,IAAI,WAAW,YAAY;AAE9D,QAAM,YAAY,aAAa,OAAO,IAAI,SAAS;AAEnD,SAAOC,MAAE,kBAAkB,EAAE,WAAW,GAAG,QAAQ;AAAA,IACjDA,MAAE,GAAG,MAAM,EAAE,QAAQ;AAAA,MACnB,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI,WAAW;AAAA,IAAA,CAChB;AAAA,IACDA,MAAE,GAAG,CAAC,MAAM,EAAE,UAAU;AAAA,MACtB,GAAG;AAAA,MACH,WAAW,eAAe,WAAW,CAAC;AAAA,IAAA,CACvC;AAAA,EAAA,CACF;AACH;;"}