@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.21 → 2.2.0-next.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +113 -56
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +49 -21
  4. package/dist/automation/automation-tank/automation-tank.d.ts.map +1 -1
  5. package/dist/automation/automation-tank/automation-tank.js +2 -1
  6. package/dist/automation/automation-tank/automation-tank.js.map +1 -1
  7. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts +4 -2
  8. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts.map +1 -1
  9. package/dist/building-blocks/bar-horizontal/bar-horizontal.js +12 -6
  10. package/dist/building-blocks/bar-horizontal/bar-horizontal.js.map +1 -1
  11. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts +4 -2
  12. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts.map +1 -1
  13. package/dist/building-blocks/bar-vertical/bar-vertical.js +12 -6
  14. package/dist/building-blocks/bar-vertical/bar-vertical.js.map +1 -1
  15. package/dist/building-blocks/external-scale/external-scale.d.ts +21 -3
  16. package/dist/building-blocks/external-scale/external-scale.d.ts.map +1 -1
  17. package/dist/building-blocks/external-scale/external-scale.js +40 -17
  18. package/dist/building-blocks/external-scale/external-scale.js.map +1 -1
  19. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts +4 -2
  20. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts.map +1 -1
  21. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js +14 -6
  22. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js.map +1 -1
  23. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts +4 -2
  24. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts.map +1 -1
  25. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js +14 -6
  26. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js.map +1 -1
  27. package/dist/svghelpers/advice-linear.d.ts +7 -0
  28. package/dist/svghelpers/advice-linear.d.ts.map +1 -1
  29. package/dist/svghelpers/advice-linear.js +14 -10
  30. package/dist/svghelpers/advice-linear.js.map +1 -1
  31. package/dist/svghelpers/advice-patterns.d.ts +2 -2
  32. package/dist/svghelpers/advice-patterns.d.ts.map +1 -1
  33. package/dist/svghelpers/advice-patterns.js +6 -4
  34. package/dist/svghelpers/advice-patterns.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/automation/automation-tank/automation-tank.ts +4 -0
  37. package/src/building-blocks/bar-horizontal/bar-horizontal-fixed-aspect.spec.ts +50 -0
  38. package/src/building-blocks/bar-horizontal/bar-horizontal.stories.ts +6 -0
  39. package/src/building-blocks/bar-horizontal/bar-horizontal.ts +22 -9
  40. package/src/building-blocks/bar-vertical/bar-vertical-dimensions.spec.ts +36 -0
  41. package/src/building-blocks/bar-vertical/bar-vertical-fixed-aspect.spec.ts +49 -0
  42. package/src/building-blocks/bar-vertical/bar-vertical.stories.ts +6 -0
  43. package/src/building-blocks/bar-vertical/bar-vertical.ts +22 -9
  44. package/src/building-blocks/external-scale/external-scale.spec.ts +151 -0
  45. package/src/building-blocks/external-scale/external-scale.stories.ts +6 -0
  46. package/src/building-blocks/external-scale/external-scale.ts +86 -40
  47. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.spec.ts +55 -0
  48. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.stories.ts +2 -0
  49. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.ts +24 -9
  50. package/src/navigation-instruments/gauge-trend/gauge-trend.stories.ts +25 -0
  51. package/src/navigation-instruments/gauge-vertical/gauge-vertical.spec.ts +55 -0
  52. package/src/navigation-instruments/gauge-vertical/gauge-vertical.stories.ts +2 -0
  53. package/src/navigation-instruments/gauge-vertical/gauge-vertical.ts +24 -9
  54. package/src/svghelpers/advice-linear.ts +25 -11
  55. package/src/svghelpers/advice-patterns.ts +13 -5
@@ -1 +1 @@
1
- {"version":3,"file":"advice-linear.js","names":[],"sources":["../../src/svghelpers/advice-linear.ts"],"sourcesContent":["/**\n * The linear advice renderer, shared by the external scale, the thruster\n * column and the linear instrument scales: a band along a main axis at a\n * fixed perpendicular offset, a point marker on the band centreline, and the\n * area between the limit lines across a bar. What a band looks like comes\n * from `advice.ts`; the caller maps its values to main-axis coordinates and\n * says where the band sits.\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {\n ADVICE_ALERT_CORNER_RADIUS,\n ADVICE_AREA_DASH,\n ADVICE_BAND_THICKNESS,\n ADVICE_CAP_INSET,\n ADVICE_POINT_DOT_DIAMETER,\n ADVICE_POINT_TICK,\n AdviceCap,\n ADVICE_STRIPE,\n AdviceCategory,\n AdviceState,\n adviceCaps,\n adviceStyle,\n asResolvedAdvice,\n isGoToCategory,\n type AdviceInput,\n type ResolvedAdvice,\n ADVICE_ICON_SIZE_LINEAR,\n} from './advice.js';\nimport {dotPattern, hairlinePattern, stripePattern} from './advice-patterns.js';\nimport {renderAdviceIcon} from './advice-icons.js';\n\n/** Where a band sits: its range along the main axis and its near edge across it. */\nexport interface LinearAdviceBandOptions {\n /** The main axis is y (a vertical scale) rather than x. */\n vertical: boolean;\n /** Main-axis coordinate of the advice's `min`. */\n mainStart: number;\n /** Main-axis coordinate of the advice's `max`. */\n mainEnd: number;\n /** The band's edge with the lower perpendicular coordinate; it extends `thickness` from there. */\n perpStart: number;\n thickness?: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; only a hatched band uses it. */\n maskId: string;\n /** The band is drawn under a reflection, so the hatch is mirrored back. */\n mirrorPattern?: boolean;\n}\n\nconst point = (vertical: boolean, main: number, perp: number) =>\n vertical ? `${perp} ${main}` : `${main} ${perp}`;\n\n/**\n * The band outline, one cap per end. The cap at the lower main-axis\n * coordinate is the advice's start cap when `mainStart <= mainEnd`, as on a\n * horizontal scale, and its end cap otherwise, as on a vertical scale whose\n * values grow upward.\n */\nfunction bandPath(o: LinearAdviceBandOptions, advice: ResolvedAdvice) {\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const caps = adviceCaps(advice);\n const ascending = o.mainStart <= o.mainEnd;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const capLo = ascending ? caps.start : caps.end;\n const capHi = ascending ? caps.end : caps.start;\n const edgeLo = capLo === AdviceCap.pill ? lo + ADVICE_CAP_INSET : lo;\n const edgeHi = capHi === AdviceCap.pill ? hi - ADVICE_CAP_INSET : hi;\n const radius = (cap: AdviceCap) =>\n cap === AdviceCap.pill\n ? t / 2\n : cap === AdviceCap.square\n ? ADVICE_ALERT_CORNER_RADIUS\n : 0;\n const rLo = radius(capLo);\n const rHi = radius(capHi);\n if (edgeHi - edgeLo < rLo + rHi) return null;\n const p0 = o.perpStart;\n const p1 = o.perpStart + t;\n const v = o.vertical;\n const sw = v ? 0 : 1;\n const P = (main: number, perp: number) => point(v, main, perp);\n const cap = (\n main: number,\n r: number,\n c: AdviceCap,\n from: number,\n to: number,\n dir: 1 | -1\n ) => {\n // `dir` is +1 at the high end, -1 at the low end; the cap bulges that way.\n if (c === AdviceCap.pill) {\n return `A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n if (c === AdviceCap.square) {\n const inward = from < to ? 1 : -1;\n return `A ${r} ${r} 0 0 ${sw} ${P(main, from + inward * r)} L ${P(main, to - inward * r)} A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n return `L ${P(main, from)} L ${P(main, to)}`;\n };\n return [\n `M ${P(edgeLo + rLo, p0)}`,\n `L ${P(edgeHi - rHi, p0)}`,\n cap(edgeHi, rHi, capHi, p0, p1, 1),\n `L ${P(edgeLo + rLo, p1)}`,\n cap(edgeLo, rLo, capLo, p1, p0, -1),\n 'Z',\n ].join(' ');\n}\n\n/** One advice band. `nothing` when the range is too short for its caps. */\nexport function renderLinearAdviceBand(\n o: LinearAdviceBandOptions\n): SVGTemplateResult | typeof nothing {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const d = bandPath(o, advice);\n if (d === null) return nothing;\n if (style.pattern === 'none') {\n return svg`<path d=${d} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const patternId = `${o.maskId}-pattern`;\n const mirrored = o.mirrorPattern ?? false;\n const pattern =\n style.pattern === 'hairline'\n ? hairlinePattern(patternId, style.patternColor, mirrored)\n : stripePattern(\n patternId,\n style.patternColor,\n ADVICE_STRIPE.width,\n mirrored\n );\n const cover = o.vertical\n ? svg`<rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=${style.fill}/><rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=\"url(#${patternId})\"/>`\n : svg`<rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=${style.fill}/><rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=\"url(#${patternId})\"/>`;\n return svg`\n <defs>\n ${pattern}\n <mask id=${o.maskId} maskUnits=\"userSpaceOnUse\" x=\"-4096\" y=\"-4096\" width=\"8192\" height=\"8192\">\n <path d=${d} fill=\"white\"/>\n </mask>\n </defs>\n <g mask=\"url(#${o.maskId})\">${cover}</g>\n <path d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where a point marker sits: on the band centreline at its value. */\nexport interface LinearAdvicePointOptions {\n vertical: boolean;\n /** Main-axis coordinate of the advice's `value`. */\n main: number;\n /** Perpendicular coordinate of the band centreline. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n}\n\n/**\n * A point advice: a dot for a go-to category, a thick tick across the band\n * for a no-go one. The caution point takes the tick-mark primary colour while\n * triggered, never the caution yellow.\n */\nexport function renderLinearAdvicePoint(\n o: LinearAdvicePointOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const cx = o.vertical ? o.perpCenter : o.main;\n const cy = o.vertical ? o.main : o.perpCenter;\n if (isGoToCategory(advice.category)) {\n return svg`<circle cx=${cx} cy=${cy} r=${ADVICE_POINT_DOT_DIAMETER / 2} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const grey =\n advice.category === AdviceCategory.caution\n ? advice.state === AdviceState.triggered\n ? 'var(--instrument-tick-mark-primary-color)'\n : style.stroke\n : undefined;\n const {length, thickness, radius} = ADVICE_POINT_TICK;\n const w = o.vertical ? length : thickness;\n const h = o.vertical ? thickness : length;\n return svg`<rect x=${cx - w / 2} y=${cy - h / 2} width=${w} height=${h} rx=${radius} fill=${grey ?? style.fill} stroke=${grey ?? style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where an area sits: the advice's range along the main axis, the bar across it. */\nexport interface LinearAdviceAreaOptions {\n vertical: boolean;\n mainStart: number;\n mainEnd: number;\n perpStart: number;\n perpEnd: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; the pattern tile's id. */\n patternId: string;\n}\n\n/**\n * The area layer across a bar: the category's tint or pattern between the\n * limits and the limit lines in the category's dash; for a point one line.\n */\nexport function renderLinearAdviceArea(\n o: LinearAdviceAreaOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const v = o.vertical;\n const dash =\n style.areaOutline === 'dotted'\n ? ADVICE_AREA_DASH.dotted\n : style.areaOutline === 'dashed'\n ? ADVICE_AREA_DASH.dashed\n : undefined;\n const line = (main: number) => {\n const d = `M ${point(v, main, o.perpStart)} L ${point(v, main, o.perpEnd)}`;\n return svg`\n ${\n dash\n ? svg`<path d=${d} fill=\"none\" stroke=\"var(--instrument-frame-primary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n : nothing\n }\n <path d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" stroke-dasharray=${dash ?? nothing} vector-effect=\"non-scaling-stroke\"/>`;\n };\n if (advice.point) return line(o.mainStart);\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const pLo = Math.min(o.perpStart, o.perpEnd);\n const pHi = Math.max(o.perpStart, o.perpEnd);\n const rect = (fill: string) =>\n v\n ? svg`<rect x=${pLo} y=${lo} width=${pHi - pLo} height=${hi - lo} fill=${fill}/>`\n : svg`<rect x=${lo} y=${pLo} width=${hi - lo} height=${pHi - pLo} fill=${fill}/>`;\n const pattern =\n style.areaPattern === 'dots'\n ? dotPattern(o.patternId, style.stroke)\n : style.areaPattern === 'hairline'\n ? hairlinePattern(o.patternId, style.stroke)\n : nothing;\n return svg`\n ${pattern}\n ${style.areaFill === 'none' ? nothing : rect(style.areaFill)}\n ${pattern === nothing ? nothing : rect(`url(#${o.patternId})`)}\n ${line(o.mainStart)} ${line(o.mainEnd)}`;\n}\n\n/** Where an icon sits: the advice's midpoint along the main axis, the label column across it. */\nexport interface LinearAdviceIconOptions {\n vertical: boolean;\n /** Main-axis coordinates of the advice's `min` and `max`; a point gives the same value twice. */\n mainStart: number;\n mainEnd: number;\n /** Perpendicular coordinate of the icon box's centre. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n size?: number;\n /** Unique in the document; the glyph's own ids are prefixed with it. */\n id?: string;\n}\n\n/** The category's icon beside the band, centred on the range, in the responsive size. */\nexport function renderLinearAdviceIcon(\n o: LinearAdviceIconOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const main = (o.mainStart + o.mainEnd) / 2;\n return renderAdviceIcon({\n category: advice.category,\n state: advice.state,\n x: o.vertical ? o.perpCenter : main,\n y: o.vertical ? main : o.perpCenter,\n size: o.size ?? ADVICE_ICON_SIZE_LINEAR,\n id: o.id,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoDA,IAAM,SAAS,UAAmB,MAAc,SAC9C,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG;;;;;;;AAQ5C,SAAS,SAAS,GAA4B,QAAwB;CACpE,MAAM,IAAI,EAAE,aAAA;CACZ,MAAM,OAAO,WAAW,MAAM;CAC9B,MAAM,YAAY,EAAE,aAAa,EAAE;CACnC,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,QAAQ,YAAY,KAAK,QAAQ,KAAK;CAC5C,MAAM,QAAQ,YAAY,KAAK,MAAM,KAAK;CAC1C,MAAM,SAAS,UAAU,UAAU,OAAO,KAAA,IAAwB;CAClE,MAAM,SAAS,UAAU,UAAU,OAAO,KAAA,IAAwB;CAClE,MAAM,UAAU,QACd,QAAQ,UAAU,OACd,IAAI,IACJ,QAAQ,UAAU,SAAA,IAEhB;CACR,MAAM,MAAM,OAAO,KAAK;CACxB,MAAM,MAAM,OAAO,KAAK;CACxB,IAAI,SAAS,SAAS,MAAM,KAAK,OAAO;CACxC,MAAM,KAAK,EAAE;CACb,MAAM,KAAK,EAAE,YAAY;CACzB,MAAM,IAAI,EAAE;CACZ,MAAM,KAAK,IAAI,IAAI;CACnB,MAAM,KAAK,MAAc,SAAiB,MAAM,GAAG,MAAM,IAAI;CAC7D,MAAM,OACJ,MACA,GACA,GACA,MACA,IACA,QACG;EAEH,IAAI,MAAM,UAAU,MAClB,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,EAAE,OAAO,MAAM,GAAG,EAAE;EAEtD,IAAI,MAAM,UAAU,QAAQ;GAC1B,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iBAAiB,EAAE,MAAM;CACxC,MAAM,QAAQ,EAAE,YAAY,EAAE,WAAW;CACzC,OAAO,iBAAiB;EACtB,UAAU,OAAO;EACjB,OAAO,OAAO;EACd,GAAG,EAAE,WAAW,EAAE,aAAa;EAC/B,GAAG,EAAE,WAAW,OAAO,EAAE;EACzB,MAAM,EAAE,QAAA;EACR,IAAI,EAAE;CACR,CAAC;AACH"}
1
+ {"version":3,"file":"advice-linear.js","names":[],"sources":["../../src/svghelpers/advice-linear.ts"],"sourcesContent":["/**\n * The linear advice renderer, shared by the external scale, the thruster\n * column and the linear instrument scales: a band along a main axis at a\n * fixed perpendicular offset, a point marker on the band centreline, and the\n * area between the limit lines across a bar. What a band looks like comes\n * from `advice.ts`; the caller maps its values to main-axis coordinates and\n * says where the band sits.\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {\n ADVICE_ALERT_CORNER_RADIUS,\n ADVICE_AREA_DASH,\n ADVICE_BAND_THICKNESS,\n ADVICE_CAP_INSET,\n ADVICE_POINT_DOT_DIAMETER,\n ADVICE_POINT_TICK,\n AdviceCap,\n ADVICE_STRIPE,\n AdviceCategory,\n AdviceState,\n adviceCaps,\n adviceStyle,\n asResolvedAdvice,\n isGoToCategory,\n type AdviceInput,\n type ResolvedAdvice,\n ADVICE_ICON_SIZE_LINEAR,\n} from './advice.js';\nimport {dotPattern, hairlinePattern, stripePattern} from './advice-patterns.js';\nimport {renderAdviceIcon} from './advice-icons.js';\n\n/** Where a band sits: its range along the main axis and its near edge across it. */\nexport interface LinearAdviceBandOptions {\n /** The main axis is y (a vertical scale) rather than x. */\n vertical: boolean;\n /** Main-axis coordinate of the advice's `min`. */\n mainStart: number;\n /** Main-axis coordinate of the advice's `max`. */\n mainEnd: number;\n /** The band's edge with the lower perpendicular coordinate; it extends `thickness` from there. */\n perpStart: number;\n thickness?: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; only a hatched band uses it. */\n maskId: string;\n /** The band is drawn under a reflection, so the hatch is mirrored back. */\n mirrorPattern?: boolean;\n /**\n * ViewBox units per CSS pixel when the band is pixel-fixed inside a scaled\n * drawing: the hatch tile is enlarged by it so the stripes keep their pitch.\n */\n unitsPerPx?: number;\n}\n\nconst point = (vertical: boolean, main: number, perp: number) =>\n vertical ? `${perp} ${main}` : `${main} ${perp}`;\n\n/**\n * The band outline, one cap per end. The cap at the lower main-axis\n * coordinate is the advice's start cap when `mainStart <= mainEnd`, as on a\n * horizontal scale, and its end cap otherwise, as on a vertical scale whose\n * values grow upward.\n */\nfunction bandPath(o: LinearAdviceBandOptions, advice: ResolvedAdvice) {\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const caps = adviceCaps(advice);\n const ascending = o.mainStart <= o.mainEnd;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const capLo = ascending ? caps.start : caps.end;\n const capHi = ascending ? caps.end : caps.start;\n // The caps are pixel geometry like the band: a scaled drawing holds them\n // in the band's own units.\n const u = o.unitsPerPx ?? 1;\n const inset = ADVICE_CAP_INSET * u;\n const edgeLo = capLo === AdviceCap.pill ? lo + inset : lo;\n const edgeHi = capHi === AdviceCap.pill ? hi - inset : hi;\n const radius = (cap: AdviceCap) =>\n cap === AdviceCap.pill\n ? t / 2\n : cap === AdviceCap.square\n ? ADVICE_ALERT_CORNER_RADIUS * u\n : 0;\n const rLo = radius(capLo);\n const rHi = radius(capHi);\n if (edgeHi - edgeLo < rLo + rHi) return null;\n const p0 = o.perpStart;\n const p1 = o.perpStart + t;\n const v = o.vertical;\n const sw = v ? 0 : 1;\n const P = (main: number, perp: number) => point(v, main, perp);\n const cap = (\n main: number,\n r: number,\n c: AdviceCap,\n from: number,\n to: number,\n dir: 1 | -1\n ) => {\n // `dir` is +1 at the high end, -1 at the low end; the cap bulges that way.\n if (c === AdviceCap.pill) {\n return `A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n if (c === AdviceCap.square) {\n const inward = from < to ? 1 : -1;\n return `A ${r} ${r} 0 0 ${sw} ${P(main, from + inward * r)} L ${P(main, to - inward * r)} A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n return `L ${P(main, from)} L ${P(main, to)}`;\n };\n return [\n `M ${P(edgeLo + rLo, p0)}`,\n `L ${P(edgeHi - rHi, p0)}`,\n cap(edgeHi, rHi, capHi, p0, p1, 1),\n `L ${P(edgeLo + rLo, p1)}`,\n cap(edgeLo, rLo, capLo, p1, p0, -1),\n 'Z',\n ].join(' ');\n}\n\n/** One advice band. `nothing` when the range is too short for its caps. */\nexport function renderLinearAdviceBand(\n o: LinearAdviceBandOptions\n): SVGTemplateResult | typeof nothing {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const d = bandPath(o, advice);\n if (d === null) return nothing;\n if (style.pattern === 'none') {\n return svg`<path class=\"advice-band\" d=${d} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const patternId = `${o.maskId}-pattern`;\n const mirrored = o.mirrorPattern ?? false;\n const unitsPerPx = o.unitsPerPx ?? 1;\n const pattern =\n style.pattern === 'hairline'\n ? hairlinePattern(patternId, style.patternColor, mirrored, unitsPerPx)\n : stripePattern(\n patternId,\n style.patternColor,\n ADVICE_STRIPE.width,\n mirrored,\n unitsPerPx\n );\n const cover = o.vertical\n ? svg`<rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=${style.fill}/><rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=\"url(#${patternId})\"/>`\n : svg`<rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=${style.fill}/><rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=\"url(#${patternId})\"/>`;\n return svg`\n <defs>\n ${pattern}\n <mask id=${o.maskId} maskUnits=\"userSpaceOnUse\" x=\"-4096\" y=\"-4096\" width=\"8192\" height=\"8192\">\n <path d=${d} fill=\"white\"/>\n </mask>\n </defs>\n <g mask=\"url(#${o.maskId})\">${cover}</g>\n <path class=\"advice-band\" d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where a point marker sits: on the band centreline at its value. */\nexport interface LinearAdvicePointOptions {\n vertical: boolean;\n /** Main-axis coordinate of the advice's `value`. */\n main: number;\n /** Perpendicular coordinate of the band centreline. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n /** ViewBox units per CSS pixel when the marker is pixel-fixed inside a scaled drawing. */\n unitsPerPx?: number;\n}\n\n/**\n * A point advice: a dot for a go-to category, a thick tick across the band\n * for a no-go one. The caution point takes the tick-mark primary colour while\n * triggered, never the caution yellow.\n */\nexport function renderLinearAdvicePoint(\n o: LinearAdvicePointOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const cx = o.vertical ? o.perpCenter : o.main;\n const cy = o.vertical ? o.main : o.perpCenter;\n const u = o.unitsPerPx ?? 1;\n if (isGoToCategory(advice.category)) {\n return svg`<circle cx=${cx} cy=${cy} r=${(ADVICE_POINT_DOT_DIAMETER / 2) * u} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const grey =\n advice.category === AdviceCategory.caution\n ? advice.state === AdviceState.triggered\n ? 'var(--instrument-tick-mark-primary-color)'\n : style.stroke\n : undefined;\n const {length, thickness, radius} = ADVICE_POINT_TICK;\n const w = (o.vertical ? length : thickness) * u;\n const h = (o.vertical ? thickness : length) * u;\n return svg`<rect x=${cx - w / 2} y=${cy - h / 2} width=${w} height=${h} rx=${radius * u} fill=${grey ?? style.fill} stroke=${grey ?? style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where an area sits: the advice's range along the main axis, the bar across it. */\nexport interface LinearAdviceAreaOptions {\n vertical: boolean;\n mainStart: number;\n mainEnd: number;\n perpStart: number;\n perpEnd: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; the pattern tile's id. */\n patternId: string;\n}\n\n/**\n * The area layer across a bar: the category's tint or pattern between the\n * limits and the limit lines in the category's dash; for a point one line.\n */\nexport function renderLinearAdviceArea(\n o: LinearAdviceAreaOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const v = o.vertical;\n const dash =\n style.areaOutline === 'dotted'\n ? ADVICE_AREA_DASH.dotted\n : style.areaOutline === 'dashed'\n ? ADVICE_AREA_DASH.dashed\n : undefined;\n const line = (main: number) => {\n const d = `M ${point(v, main, o.perpStart)} L ${point(v, main, o.perpEnd)}`;\n return svg`\n ${\n dash\n ? svg`<path d=${d} fill=\"none\" stroke=\"var(--instrument-frame-primary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n : nothing\n }\n <path d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" stroke-dasharray=${dash ?? nothing} vector-effect=\"non-scaling-stroke\"/>`;\n };\n if (advice.point) return line(o.mainStart);\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const pLo = Math.min(o.perpStart, o.perpEnd);\n const pHi = Math.max(o.perpStart, o.perpEnd);\n const rect = (fill: string) =>\n v\n ? svg`<rect x=${pLo} y=${lo} width=${pHi - pLo} height=${hi - lo} fill=${fill}/>`\n : svg`<rect x=${lo} y=${pLo} width=${hi - lo} height=${pHi - pLo} fill=${fill}/>`;\n const pattern =\n style.areaPattern === 'dots'\n ? dotPattern(o.patternId, style.stroke)\n : style.areaPattern === 'hairline'\n ? hairlinePattern(o.patternId, style.stroke)\n : nothing;\n return svg`\n ${pattern}\n ${style.areaFill === 'none' ? nothing : rect(style.areaFill)}\n ${pattern === nothing ? nothing : rect(`url(#${o.patternId})`)}\n ${line(o.mainStart)} ${line(o.mainEnd)}`;\n}\n\n/** Where an icon sits: the advice's midpoint along the main axis, the label column across it. */\nexport interface LinearAdviceIconOptions {\n vertical: boolean;\n /** Main-axis coordinates of the advice's `min` and `max`; a point gives the same value twice. */\n mainStart: number;\n mainEnd: number;\n /** Perpendicular coordinate of the icon box's centre. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n size?: number;\n /** Unique in the document; the glyph's own ids are prefixed with it. */\n id?: string;\n}\n\n/** The category's icon beside the band, centred on the range, in the responsive size. */\nexport function renderLinearAdviceIcon(\n o: LinearAdviceIconOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const main = (o.mainStart + o.mainEnd) / 2;\n return renderAdviceIcon({\n category: advice.category,\n state: advice.state,\n x: o.vertical ? o.perpCenter : main,\n y: o.vertical ? main : o.perpCenter,\n size: o.size ?? ADVICE_ICON_SIZE_LINEAR,\n id: o.id,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyDA,IAAM,SAAS,UAAmB,MAAc,SAC9C,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG;;;;;;;AAQ5C,SAAS,SAAS,GAA4B,QAAwB;CACpE,MAAM,IAAI,EAAE,aAAA;CACZ,MAAM,OAAO,WAAW,MAAM;CAC9B,MAAM,YAAY,EAAE,aAAa,EAAE;CACnC,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,QAAQ,YAAY,KAAK,QAAQ,KAAK;CAC5C,MAAM,QAAQ,YAAY,KAAK,MAAM,KAAK;CAG1C,MAAM,IAAI,EAAE,cAAc;CAC1B,MAAM,QAAA,IAA2B;CACjC,MAAM,SAAS,UAAU,UAAU,OAAO,KAAK,QAAQ;CACv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,MAAM,MAAM,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC3C,MAAM,MAAM,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC3C,MAAM,QAAQ,SACZ,IACI,GAAG,WAAW,IAAI,KAAK,GAAG,SAAS,MAAM,IAAI,UAAU,KAAK,GAAG,QAAQ,KAAK,MAC5E,GAAG,WAAW,GAAG,KAAK,IAAI,SAAS,KAAK,GAAG,UAAU,MAAM,IAAI,QAAQ,KAAK;CAClF,MAAM,UACJ,MAAM,gBAAgB,SAClB,WAAW,EAAE,WAAW,MAAM,MAAM,IACpC,MAAM,gBAAgB,aACpB,gBAAgB,EAAE,WAAW,MAAM,MAAM,IACzC;CACR,OAAO,GAAG;MACN,QAAQ;MACR,MAAM,aAAa,SAAS,UAAU,KAAK,MAAM,QAAQ,EAAE;MAC3D,YAAY,UAAU,UAAU,KAAK,QAAQ,EAAE,UAAU,EAAE,EAAE;MAC7D,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,OAAO;AACzC;;AAiBA,SAAgB,uBACd,GACmB;CACnB,MAAM,SAAS,iBAAiB,EAAE,MAAM;CACxC,MAAM,QAAQ,EAAE,YAAY,EAAE,WAAW;CACzC,OAAO,iBAAiB;EACtB,UAAU,OAAO;EACjB,OAAO,OAAO;EACd,GAAG,EAAE,WAAW,EAAE,aAAa;EAC/B,GAAG,EAAE,WAAW,OAAO,EAAE;EACzB,MAAM,EAAE,QAAA;EACR,IAAI,EAAE;CACR,CAAC;AACH"}
@@ -6,9 +6,9 @@ import { SVGTemplateResult } from 'lit';
6
6
  * tile whose side is the pitch along the axis, with the two half lines at the
7
7
  * opposite corners completing the neighbours.
8
8
  */
9
- export declare function stripePattern(id: string, color: string, width?: number, mirrored?: boolean): SVGTemplateResult;
9
+ export declare function stripePattern(id: string, color: string, width?: number, mirrored?: boolean, unitsPerPx?: number): SVGTemplateResult;
10
10
  /** The exclusion hatch: the stripe tile as a hairline. */
11
- export declare function hairlinePattern(id: string, color: string, mirrored?: boolean): SVGTemplateResult;
11
+ export declare function hairlinePattern(id: string, color: string, mirrored?: boolean, unitsPerPx?: number): SVGTemplateResult;
12
12
  /** The alarm lattice: square dots on a grid, every other row shifted by half a pitch. */
13
13
  export declare function dotPattern(id: string, color: string): SVGTemplateResult;
14
14
  //# sourceMappingURL=advice-patterns.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advice-patterns.d.ts","sourceRoot":"","sources":["../../src/svghelpers/advice-patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAe,KAAK,iBAAiB,EAAC,MAAM,KAAK,CAAC;AAKzD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAA4B,EACnC,QAAQ,UAAQ,GACf,iBAAiB,CAQnB;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,QAAQ,UAAQ,GACf,iBAAiB,CAEnB;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAOvE"}
1
+ {"version":3,"file":"advice-patterns.d.ts","sourceRoot":"","sources":["../../src/svghelpers/advice-patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAe,KAAK,iBAAiB,EAAC,MAAM,KAAK,CAAC;AAKzD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAA4B,EACnC,QAAQ,UAAQ,EAChB,UAAU,SAAI,GACb,iBAAiB,CAcnB;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,QAAQ,UAAQ,EAChB,UAAU,SAAI,GACb,iBAAiB,CAEnB;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAOvE"}
@@ -20,15 +20,17 @@ var STRIPE_TILE = ADVICE_STRIPE.pitch * Math.SQRT2;
20
20
  * tile whose side is the pitch along the axis, with the two half lines at the
21
21
  * opposite corners completing the neighbours.
22
22
  */
23
- function stripePattern(id, color, width = ADVICE_STRIPE.width, mirrored = false) {
23
+ function stripePattern(id, color, width = ADVICE_STRIPE.width, mirrored = false, unitsPerPx = 1) {
24
24
  const t = STRIPE_TILE;
25
- return svg`<pattern id=${id} patternUnits="userSpaceOnUse" width=${t} height=${t} patternTransform=${mirrored ? "scale(-1 1)" : nothing}>
25
+ const transforms = [mirrored ? "scale(-1 1)" : "", unitsPerPx !== 1 ? `scale(${unitsPerPx})` : ""].filter(Boolean);
26
+ const transform = transforms.length ? transforms.join(" ") : nothing;
27
+ return svg`<pattern id=${id} patternUnits="userSpaceOnUse" width=${t} height=${t} patternTransform=${transform}>
26
28
  <path d="M 0 0 L ${t} ${t} M ${t / 2} ${-t / 2} L ${3 * t / 2} ${t / 2} M ${-t / 2} ${t / 2} L ${t / 2} ${3 * t / 2}" stroke=${color} stroke-width=${width} stroke-linecap="square"/>
27
29
  </pattern>`;
28
30
  }
29
31
  /** The exclusion hatch: the stripe tile as a hairline. */
30
- function hairlinePattern(id, color, mirrored = false) {
31
- return stripePattern(id, color, ADVICE_HAIRLINE_WIDTH, mirrored);
32
+ function hairlinePattern(id, color, mirrored = false, unitsPerPx = 1) {
33
+ return stripePattern(id, color, ADVICE_HAIRLINE_WIDTH, mirrored, unitsPerPx);
32
34
  }
33
35
  /** The alarm lattice: square dots on a grid, every other row shifted by half a pitch. */
34
36
  function dotPattern(id, color) {
@@ -1 +1 @@
1
- {"version":3,"file":"advice-patterns.js","names":[],"sources":["../../src/svghelpers/advice-patterns.ts"],"sourcesContent":["/**\n * The SVG pattern tiles the advice bands and areas are filled with: the\n * caution stripe, the exclusion hairline and the alarm dot lattice, at the\n * geometry `advice.ts` fixes. Each tile is in user space so it reads the same\n * at any band length; the caller references it by id.\n *\n * TODO(designer): the tiles are drawn at every size, as every set draws\n * them; the size below which a hatch stops reading is not decided (#1062).\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {ADVICE_DOT, ADVICE_HAIRLINE_WIDTH, ADVICE_STRIPE} from './advice.js';\n\nconst STRIPE_TILE = ADVICE_STRIPE.pitch * Math.SQRT2;\n\n/**\n * Parallel 45° lines from top-left to bottom-right, `width` units wide on\n * the design's pitch; a hairline when `width` is\n * {@link ADVICE_HAIRLINE_WIDTH}. The line runs corner to corner of a square\n * tile whose side is the pitch along the axis, with the two half lines at the\n * opposite corners completing the neighbours.\n */\nexport function stripePattern(\n id: string,\n color: string,\n width: number = ADVICE_STRIPE.width,\n mirrored = false\n): SVGTemplateResult {\n const t = STRIPE_TILE;\n // A group drawn under a reflection shows the stripe sloping the other way;\n // mirroring the tile back keeps every band on the same slope.\n const transform = mirrored ? 'scale(-1 1)' : nothing;\n return svg`<pattern id=${id} patternUnits=\"userSpaceOnUse\" width=${t} height=${t} patternTransform=${transform}>\n <path d=\"M 0 0 L ${t} ${t} M ${t / 2} ${-t / 2} L ${(3 * t) / 2} ${t / 2} M ${-t / 2} ${t / 2} L ${t / 2} ${(3 * t) / 2}\" stroke=${color} stroke-width=${width} stroke-linecap=\"square\"/>\n </pattern>`;\n}\n\n/** The exclusion hatch: the stripe tile as a hairline. */\nexport function hairlinePattern(\n id: string,\n color: string,\n mirrored = false\n): SVGTemplateResult {\n return stripePattern(id, color, ADVICE_HAIRLINE_WIDTH, mirrored);\n}\n\n/** The alarm lattice: square dots on a grid, every other row shifted by half a pitch. */\nexport function dotPattern(id: string, color: string): SVGTemplateResult {\n const {size, pitch, rowOffset} = ADVICE_DOT;\n const inset = (pitch / 2 - size) / 2;\n return svg`<pattern id=${id} patternUnits=\"userSpaceOnUse\" width=${pitch} height=${pitch}>\n <rect x=${inset} y=${inset} width=${size} height=${size} fill=${color}/>\n <rect x=${inset + rowOffset} y=${inset + pitch / 2} width=${size} height=${size} fill=${color}/>\n </pattern>`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAM,cAAc,cAAc,QAAQ,KAAK;;;;;;;;AAS/C,SAAgB,cACd,IACA,OACA,QAAgB,cAAc,OAC9B,WAAW,OACQ;CACnB,MAAM,IAAI;CAIV,OAAO,GAAG,eAAe,GAAG,uCAAuC,EAAE,UAAU,EAAE,oBAD/D,WAAW,gBAAgB,QACkE;uBAC1F,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAM,IAAI,IAAK,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,GAAI,IAAI,IAAK,EAAE,WAAW,MAAM,gBAAgB,MAAM;;AAEnK;;AAGA,SAAgB,gBACd,IACA,OACA,WAAW,OACQ;CACnB,OAAO,cAAc,IAAI,OAAO,uBAAuB,QAAQ;AACjE;;AAGA,SAAgB,WAAW,IAAY,OAAkC;CACvE,MAAM,EAAC,MAAM,OAAO,cAAa;CACjC,MAAM,SAAS,QAAQ,IAAI,QAAQ;CACnC,OAAO,GAAG,eAAe,GAAG,uCAAuC,MAAM,UAAU,MAAM;cAC7E,MAAM,KAAK,MAAM,SAAS,KAAK,UAAU,KAAK,QAAQ,MAAM;cAC5D,QAAQ,UAAU,KAAK,QAAQ,QAAQ,EAAE,SAAS,KAAK,UAAU,KAAK,QAAQ,MAAM;;AAElG"}
1
+ {"version":3,"file":"advice-patterns.js","names":[],"sources":["../../src/svghelpers/advice-patterns.ts"],"sourcesContent":["/**\n * The SVG pattern tiles the advice bands and areas are filled with: the\n * caution stripe, the exclusion hairline and the alarm dot lattice, at the\n * geometry `advice.ts` fixes. Each tile is in user space so it reads the same\n * at any band length; the caller references it by id.\n *\n * TODO(designer): the tiles are drawn at every size, as every set draws\n * them; the size below which a hatch stops reading is not decided (#1062).\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {ADVICE_DOT, ADVICE_HAIRLINE_WIDTH, ADVICE_STRIPE} from './advice.js';\n\nconst STRIPE_TILE = ADVICE_STRIPE.pitch * Math.SQRT2;\n\n/**\n * Parallel 45° lines from top-left to bottom-right, `width` units wide on\n * the design's pitch; a hairline when `width` is\n * {@link ADVICE_HAIRLINE_WIDTH}. The line runs corner to corner of a square\n * tile whose side is the pitch along the axis, with the two half lines at the\n * opposite corners completing the neighbours.\n */\nexport function stripePattern(\n id: string,\n color: string,\n width: number = ADVICE_STRIPE.width,\n mirrored = false,\n unitsPerPx = 1\n): SVGTemplateResult {\n const t = STRIPE_TILE;\n // A group drawn under a reflection shows the stripe sloping the other way;\n // mirroring the tile back keeps every band on the same slope. A band that\n // is pixel-fixed inside a scaled drawing enlarges the tile by the same\n // factor, so the stripes keep the design pitch on screen.\n const transforms = [\n mirrored ? 'scale(-1 1)' : '',\n unitsPerPx !== 1 ? `scale(${unitsPerPx})` : '',\n ].filter(Boolean);\n const transform = transforms.length ? transforms.join(' ') : nothing;\n return svg`<pattern id=${id} patternUnits=\"userSpaceOnUse\" width=${t} height=${t} patternTransform=${transform}>\n <path d=\"M 0 0 L ${t} ${t} M ${t / 2} ${-t / 2} L ${(3 * t) / 2} ${t / 2} M ${-t / 2} ${t / 2} L ${t / 2} ${(3 * t) / 2}\" stroke=${color} stroke-width=${width} stroke-linecap=\"square\"/>\n </pattern>`;\n}\n\n/** The exclusion hatch: the stripe tile as a hairline. */\nexport function hairlinePattern(\n id: string,\n color: string,\n mirrored = false,\n unitsPerPx = 1\n): SVGTemplateResult {\n return stripePattern(id, color, ADVICE_HAIRLINE_WIDTH, mirrored, unitsPerPx);\n}\n\n/** The alarm lattice: square dots on a grid, every other row shifted by half a pitch. */\nexport function dotPattern(id: string, color: string): SVGTemplateResult {\n const {size, pitch, rowOffset} = ADVICE_DOT;\n const inset = (pitch / 2 - size) / 2;\n return svg`<pattern id=${id} patternUnits=\"userSpaceOnUse\" width=${pitch} height=${pitch}>\n <rect x=${inset} y=${inset} width=${size} height=${size} fill=${color}/>\n <rect x=${inset + rowOffset} y=${inset + pitch / 2} width=${size} height=${size} fill=${color}/>\n </pattern>`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAM,cAAc,cAAc,QAAQ,KAAK;;;;;;;;AAS/C,SAAgB,cACd,IACA,OACA,QAAgB,cAAc,OAC9B,WAAW,OACX,aAAa,GACM;CACnB,MAAM,IAAI;CAKV,MAAM,aAAa,CACjB,WAAW,gBAAgB,IAC3B,eAAe,IAAI,SAAS,WAAW,KAAK,EAC9C,CAAC,CAAC,OAAO,OAAO;CAChB,MAAM,YAAY,WAAW,SAAS,WAAW,KAAK,GAAG,IAAI;CAC7D,OAAO,GAAG,eAAe,GAAG,uCAAuC,EAAE,UAAU,EAAE,oBAAoB,UAAU;uBAC1F,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAM,IAAI,IAAK,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,GAAI,IAAI,IAAK,EAAE,WAAW,MAAM,gBAAgB,MAAM;;AAEnK;;AAGA,SAAgB,gBACd,IACA,OACA,WAAW,OACX,aAAa,GACM;CACnB,OAAO,cAAc,IAAI,OAAO,uBAAuB,UAAU,UAAU;AAC7E;;AAGA,SAAgB,WAAW,IAAY,OAAkC;CACvE,MAAM,EAAC,MAAM,OAAO,cAAa;CACjC,MAAM,SAAS,QAAQ,IAAI,QAAQ;CACnC,OAAO,GAAG,eAAe,GAAG,uCAAuC,MAAM,UAAU,MAAM;cAC7E,MAAM,KAAK,MAAM,SAAS,KAAK,UAAU,KAAK,QAAQ,MAAM;cAC5D,QAAQ,UAAU,KAAK,QAAQ,QAAQ,EAAE,SAAS,KAAK,UAAU,KAAK,QAAQ,MAAM;;AAElG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents-full-bundle",
3
- "version": "2.2.0-next.21",
3
+ "version": "2.2.0-next.22",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -819,6 +819,10 @@ export class ObcAutomationTank extends AdviceMixin(SetpointMixin(LitElement)) {
819
819
  this.hasAdvice && !!this.advices?.some((a) => a.showIcon),
820
820
  advicePosition: AdvicePosition.inner,
821
821
  hasSetpoint: hasSetpointMarker,
822
+ // The advice column is pixels; in viewBox units it is those pixels
823
+ // over the cell's own scale.
824
+ fixedAspectRatioScale:
825
+ Math.max(1, this._cellHeight) / SCALE_REFERENCE_SIZE,
822
826
  });
823
827
  const safeCellHeight = Math.max(1, this._cellHeight);
824
828
  const viewBoxCross =
@@ -20,6 +20,13 @@ const svgOf = (el: Element) => el.querySelector('svg')!;
20
20
  const scaleOf = (el: Element) =>
21
21
  parseFloat(svgOf(el).style.getPropertyValue('--scale'));
22
22
 
23
+ /** The painted thickness of the first advice band, in CSS px. */
24
+ const pillPx = (el: Element) => {
25
+ const svg = svgOf(el);
26
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
27
+ return +(band.getBBox().height * svg.getScreenCTM()!.a).toFixed(2);
28
+ };
29
+
23
30
  /** Bar, ticks and labels with no setpoint: 48 + 24 + 60 = 132 thick. */
24
31
  async function mount(boxStyle: string): Promise<ObcBarHorizontal> {
25
32
  const screen = render(
@@ -99,4 +106,47 @@ describe('obc-bar-horizontal fixed aspect ratio', () => {
99
106
  await until(() => Math.abs(scaleOf(el) - 60 / 264) < 1e-3);
100
107
  await until(() => reports[reports.length - 1] === 60);
101
108
  });
109
+
110
+ it('keeps the advice pill at 8 px and its column at 16 px at every scale', async () => {
111
+ const mountWithAdvice = async (boxStyle: string) => {
112
+ const screen = render(
113
+ html`<div style=${boxStyle}>
114
+ <obc-bar-horizontal
115
+ style="flex: 1"
116
+ .minValue=${0}
117
+ .maxValue=${100}
118
+ .value=${40}
119
+ .hasBar=${true}
120
+ .hasScale=${false}
121
+ .showLabels=${false}
122
+ .barThickness=${48}
123
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
124
+ .fixedAspectRatio=${true}
125
+ ></obc-bar-horizontal>
126
+ </div>`
127
+ );
128
+ const el = screen.container.querySelector(
129
+ 'obc-bar-horizontal'
130
+ ) as ObcBarHorizontal;
131
+ await el.updateComplete;
132
+ const reports: number[] = [];
133
+ el.addEventListener('scale-dimensions-changed', (e) =>
134
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
135
+ );
136
+ return {el, reports};
137
+ };
138
+ // 300 px of height has room: the width decides, 48 × 1.5625 + 16 = 91
139
+ const tall = await mountWithAdvice(
140
+ 'display: block; width: 600px; height: 300px'
141
+ );
142
+ await until(() => tall.reports[tall.reports.length - 1] === 91);
143
+ expect(pillPx(tall.el)).toBeCloseTo(8, 1);
144
+ // 60 px of height: (60 - 16) / 48 is the scale the bar can still have
145
+ const short = await mountWithAdvice(
146
+ 'display: flex; width: 600px; height: 60px'
147
+ );
148
+ await until(() => Math.abs(scaleOf(short.el) - (60 - 16) / 48) < 1e-3);
149
+ await until(() => short.reports[short.reports.length - 1] === 60);
150
+ expect(pillPx(short.el)).toBeCloseTo(8, 1);
151
+ });
102
152
  });
@@ -1063,6 +1063,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1063
1063
  barNormal.fillMode = FillMode.fill;
1064
1064
  barNormal.priority = Priority.regular;
1065
1065
  barNormal.primaryTickmarkInterval = 20;
1066
+ barNormal.advices = [
1067
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1068
+ ];
1066
1069
  barNormal.fixedAspectRatio = false;
1067
1070
  barNormal.style.cssText = 'flex: 1; height: 100%;';
1068
1071
 
@@ -1092,6 +1095,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1092
1095
  barFixed.fillMode = FillMode.fill;
1093
1096
  barFixed.priority = Priority.enhanced;
1094
1097
  barFixed.primaryTickmarkInterval = 20;
1098
+ barFixed.advices = [
1099
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1100
+ ];
1095
1101
  barFixed.fixedAspectRatio = true;
1096
1102
  barFixed.style.cssText = 'flex: 1; height: 100%;';
1097
1103
 
@@ -12,7 +12,10 @@ import {
12
12
  } from '../../navigation-instruments/types.js';
13
13
  import {AdviceMixin} from '../../svghelpers/advice-mixin.js';
14
14
  import {nextAdviceMaskId} from '../../svghelpers/advice.js';
15
- import type {ExternalScaleConfig} from '../external-scale/external-scale.js';
15
+ import type {
16
+ ExternalScaleConfig,
17
+ ExternalScaleLayoutConfig,
18
+ } from '../external-scale/external-scale.js';
16
19
  import {
17
20
  computeExternalScaleViewBox,
18
21
  computeFixedAspectRatioScale,
@@ -167,8 +170,17 @@ export class ObcBarHorizontal extends AdviceMixin(
167
170
  @state()
168
171
  private _scale = 1;
169
172
 
170
- /** The drawing's height in viewBox units, kept from the last render for the scale measurement. */
171
- private _viewBoxThickness = 0;
173
+ /** The last render's layout inputs, for the scale measurement. */
174
+ private _layoutConfig?: ExternalScaleLayoutConfig;
175
+
176
+ /** The drawing's height in viewBox units at a scale: the advice column is pixels, so it depends on it. */
177
+ private _thicknessAt = (scale: number): number =>
178
+ this._layoutConfig
179
+ ? computeExternalScaleLayout({
180
+ ...this._layoutConfig,
181
+ fixedAspectRatioScale: scale,
182
+ }).thickness
183
+ : 0;
172
184
 
173
185
  // ResizeController automatically subscribes/unsubscribes based on component lifecycle
174
186
  // @ts-expect-error - Controller is used for side effects, not accessed directly
@@ -184,7 +196,7 @@ export class ObcBarHorizontal extends AdviceMixin(
184
196
  containerMainAxisSize: entry.contentRect.width,
185
197
  containerCrossAxisSize: entry.contentRect.height,
186
198
  scaleReferenceSize: this.scaleReferenceSize,
187
- viewBoxThickness: this._viewBoxThickness,
199
+ viewBoxThickness: this._thicknessAt,
188
200
  });
189
201
 
190
202
  // Report scaled dimensions to parent chart
@@ -315,14 +327,14 @@ export class ObcBarHorizontal extends AdviceMixin(
315
327
  adviceEmphasis: this.adviceEmphasis,
316
328
  adviceMaskPrefix: this._adviceMaskPrefix,
317
329
  fixedAspectRatio: this.fixedAspectRatio,
330
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
318
331
  instrumentMode: this.instrumentMode,
319
332
  highlightCurrentValue: this.highlightCurrentValue,
320
333
  };
321
334
 
322
- const layout = computeExternalScaleLayout(
323
- toExternalScaleLayoutConfig(config)
324
- );
325
- this._viewBoxThickness = layout.thickness;
335
+ const layoutConfig = toExternalScaleLayoutConfig(config);
336
+ const layout = computeExternalScaleLayout(layoutConfig);
337
+ this._layoutConfig = layoutConfig;
326
338
 
327
339
  const parts = renderExternalScale(config);
328
340
 
@@ -441,6 +453,7 @@ export class ObcBarHorizontal extends AdviceMixin(
441
453
  this.setpoint !== undefined ||
442
454
  this.newSetpoint !== undefined ||
443
455
  this.departingNewSetpoint !== undefined,
456
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
444
457
  });
445
458
 
446
459
  // When fixedAspectRatio=true, the SVG scales proportionally via preserveAspectRatio="meet".
@@ -524,7 +537,7 @@ export class ObcBarHorizontal extends AdviceMixin(
524
537
  containerMainAxisSize: width,
525
538
  containerCrossAxisSize: height,
526
539
  scaleReferenceSize: this.scaleReferenceSize,
527
- viewBoxThickness: this._viewBoxThickness,
540
+ viewBoxThickness: this._thicknessAt,
528
541
  });
529
542
  return true;
530
543
  }
@@ -74,3 +74,39 @@ describe('scale-dimensions-changed', () => {
74
74
  expect(leaked).toBe(0);
75
75
  });
76
76
  });
77
+
78
+ /** The bar fills its cell exactly; the advice column beside it is 16 px at every cell size. */
79
+ describe('automation-tank bar mode advice column', () => {
80
+ it('keeps the pill at 8 px and no gutter at two cell sizes', async () => {
81
+ for (const [w, h] of [
82
+ [140, 320],
83
+ [280, 640],
84
+ ]) {
85
+ const screen = render(
86
+ html`<obc-automation-tank
87
+ style="display: block; width: ${w}px; height: ${h}px"
88
+ .chartMode=${'bar'}
89
+ .value=${40}
90
+ .max=${100}
91
+ .hasAdvice=${true}
92
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
93
+ ></obc-automation-tank>`
94
+ );
95
+ const tank = screen.container.querySelector(
96
+ 'obc-automation-tank'
97
+ ) as ObcAutomationTank;
98
+ await tank.updateComplete;
99
+ const bar = await tankBar(tank);
100
+ await bar.updateComplete;
101
+ for (let i = 0; i < 20; i++) await frame();
102
+ const svg = bar.querySelector('svg')!;
103
+ const scale = svg.getScreenCTM()!.a;
104
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
105
+ expect(+(band.getBBox().width * scale).toFixed(1)).toBeCloseTo(8, 1);
106
+ // the viewBox is sized to the cell: the painted width is the cell's
107
+ expect(
108
+ Math.abs(svg.viewBox.baseVal.width * scale - bar.clientWidth)
109
+ ).toBeLessThan(1.5);
110
+ }
111
+ });
112
+ });
@@ -20,6 +20,13 @@ const svgOf = (el: Element) => el.querySelector('svg')!;
20
20
  const scaleOf = (el: Element) =>
21
21
  parseFloat(svgOf(el).style.getPropertyValue('--scale'));
22
22
 
23
+ /** The painted thickness of the first advice band, in CSS px. */
24
+ const pillPx = (el: Element) => {
25
+ const svg = svgOf(el);
26
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
27
+ return +(band.getBBox().width * svg.getScreenCTM()!.a).toFixed(2);
28
+ };
29
+
23
30
  /** Bar, ticks and labels with no setpoint: 48 + 24 + 60 = 132 thick. */
24
31
  async function mount(boxStyle: string): Promise<ObcBarVertical> {
25
32
  const screen = render(
@@ -98,4 +105,46 @@ describe('obc-bar-vertical fixed aspect ratio', () => {
98
105
  await until(() => Math.abs(scaleOf(el) - 80 / 264) < 1e-3);
99
106
  await until(() => reports[reports.length - 1] === 80);
100
107
  });
108
+
109
+ it('keeps the advice pill at 8 px and its column at 16 px at every scale', async () => {
110
+ const mountWithAdvice = async (boxStyle: string) => {
111
+ const screen = render(
112
+ html`<div style=${boxStyle}>
113
+ <obc-bar-vertical
114
+ .minValue=${0}
115
+ .maxValue=${100}
116
+ .value=${40}
117
+ .hasBar=${true}
118
+ .hasScale=${false}
119
+ .showLabels=${false}
120
+ .barThickness=${48}
121
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
122
+ .fixedAspectRatio=${true}
123
+ ></obc-bar-vertical>
124
+ </div>`
125
+ );
126
+ const el = screen.container.querySelector(
127
+ 'obc-bar-vertical'
128
+ ) as ObcBarVertical;
129
+ await el.updateComplete;
130
+ const reports: number[] = [];
131
+ el.addEventListener('scale-dimensions-changed', (e) =>
132
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
133
+ );
134
+ return {el, reports};
135
+ };
136
+ // 400 px of width has room: the height decides, 48 × 1.5625 + 16 = 91
137
+ const wide = await mountWithAdvice(
138
+ 'display: block; width: 400px; height: 600px'
139
+ );
140
+ await until(() => wide.reports[wide.reports.length - 1] === 91);
141
+ expect(pillPx(wide.el)).toBeCloseTo(8, 1);
142
+ // 60 px of width: (60 - 16) / 48 is the scale the bar can still have
143
+ const narrow = await mountWithAdvice(
144
+ 'display: block; width: 60px; height: 600px'
145
+ );
146
+ await until(() => Math.abs(scaleOf(narrow.el) - (60 - 16) / 48) < 1e-3);
147
+ await until(() => narrow.reports[narrow.reports.length - 1] === 60);
148
+ expect(pillPx(narrow.el)).toBeCloseTo(8, 1);
149
+ });
101
150
  });
@@ -1259,6 +1259,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1259
1259
  barNormal.fillMode = FillMode.fill;
1260
1260
  barNormal.priority = Priority.regular;
1261
1261
  barNormal.primaryTickmarkInterval = 20;
1262
+ barNormal.advices = [
1263
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1264
+ ];
1262
1265
  barNormal.fixedAspectRatio = false;
1263
1266
  barNormal.style.cssText = 'flex: 1; width: 100%;';
1264
1267
 
@@ -1288,6 +1291,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1288
1291
  barFixed.fillMode = FillMode.fill;
1289
1292
  barFixed.priority = Priority.enhanced;
1290
1293
  barFixed.primaryTickmarkInterval = 20;
1294
+ barFixed.advices = [
1295
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1296
+ ];
1291
1297
  barFixed.fixedAspectRatio = true;
1292
1298
  barFixed.style.cssText = 'flex: 1; width: 100%;';
1293
1299
 
@@ -12,7 +12,10 @@ import {
12
12
  } from '../../navigation-instruments/types.js';
13
13
  import {AdviceMixin} from '../../svghelpers/advice-mixin.js';
14
14
  import {nextAdviceMaskId} from '../../svghelpers/advice.js';
15
- import type {ExternalScaleConfig} from '../external-scale/external-scale.js';
15
+ import type {
16
+ ExternalScaleConfig,
17
+ ExternalScaleLayoutConfig,
18
+ } from '../external-scale/external-scale.js';
16
19
  import {
17
20
  computeExternalScaleViewBox,
18
21
  computeFixedAspectRatioScale,
@@ -156,8 +159,17 @@ export class ObcBarVertical extends AdviceMixin(
156
159
  @state()
157
160
  private _scale = 1;
158
161
 
159
- /** The drawing's width in viewBox units, kept from the last render for the scale measurement. */
160
- private _viewBoxThickness = 0;
162
+ /** The last render's layout inputs, for the scale measurement. */
163
+ private _layoutConfig?: ExternalScaleLayoutConfig;
164
+
165
+ /** The drawing's width in viewBox units at a scale: the advice column is pixels, so it depends on it. */
166
+ private _thicknessAt = (scale: number): number =>
167
+ this._layoutConfig
168
+ ? computeExternalScaleLayout({
169
+ ...this._layoutConfig,
170
+ fixedAspectRatioScale: scale,
171
+ }).thickness
172
+ : 0;
161
173
 
162
174
  // ResizeController automatically subscribes/unsubscribes based on component lifecycle
163
175
  // @ts-expect-error - Controller is used for side effects, not accessed directly
@@ -173,7 +185,7 @@ export class ObcBarVertical extends AdviceMixin(
173
185
  containerMainAxisSize: entry.contentRect.height,
174
186
  containerCrossAxisSize: entry.contentRect.width,
175
187
  scaleReferenceSize: this.scaleReferenceSize,
176
- viewBoxThickness: this._viewBoxThickness,
188
+ viewBoxThickness: this._thicknessAt,
177
189
  });
178
190
 
179
191
  // Report scaled dimensions to parent chart
@@ -304,14 +316,14 @@ export class ObcBarVertical extends AdviceMixin(
304
316
  adviceEmphasis: this.adviceEmphasis,
305
317
  adviceMaskPrefix: this._adviceMaskPrefix,
306
318
  fixedAspectRatio: this.fixedAspectRatio,
319
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
307
320
  instrumentMode: this.instrumentMode,
308
321
  highlightCurrentValue: this.highlightCurrentValue,
309
322
  };
310
323
 
311
- const layout = computeExternalScaleLayout(
312
- toExternalScaleLayoutConfig(config)
313
- );
314
- this._viewBoxThickness = layout.thickness;
324
+ const layoutConfig = toExternalScaleLayoutConfig(config);
325
+ const layout = computeExternalScaleLayout(layoutConfig);
326
+ this._layoutConfig = layoutConfig;
315
327
 
316
328
  const parts = renderExternalScale(config);
317
329
 
@@ -430,6 +442,7 @@ export class ObcBarVertical extends AdviceMixin(
430
442
  this.setpoint !== undefined ||
431
443
  this.newSetpoint !== undefined ||
432
444
  this.departingNewSetpoint !== undefined,
445
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
433
446
  });
434
447
 
435
448
  // When fixedAspectRatio=true, the SVG scales proportionally via preserveAspectRatio="meet".
@@ -513,7 +526,7 @@ export class ObcBarVertical extends AdviceMixin(
513
526
  containerMainAxisSize: height,
514
527
  containerCrossAxisSize: width,
515
528
  scaleReferenceSize: this.scaleReferenceSize,
516
- viewBoxThickness: this._viewBoxThickness,
529
+ viewBoxThickness: this._thicknessAt,
517
530
  });
518
531
  return true;
519
532
  }