diff --git a/package-lock.json b/package-lock.json index c06a617..76c28a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@equinor/videx-wellog", - "version": "0.10.7", + "version": "0.10.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@equinor/videx-wellog", - "version": "0.10.7", + "version": "0.10.8", "license": "MIT", "dependencies": { "@equinor/videx-math": "^1.1.0", diff --git a/package.json b/package.json index 933eab7..11c2a9e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": false, "name": "@equinor/videx-wellog", - "version": "0.10.7", + "version": "0.10.8", "license": "MIT", "description": "Visualisation components for wellbore log data", "repository": "https://github.com/equinor/videx-wellog", diff --git a/src/utils/legend-helper.ts b/src/utils/legend-helper.ts index b807a48..e663360 100644 --- a/src/utils/legend-helper.ts +++ b/src/utils/legend-helper.ts @@ -17,6 +17,13 @@ export interface LegendBounds { export type LegendOnUpdateFunction = (elm: Element, bounds: LegendBounds, track: Track) => void; +interface BasicVerticalLinkLabelConfig { + label: string; + abbr: string; + onClick: () => void; + title?: string; +} + export interface LegendConfig { elementType: string, getLegendRows(track: Track) : number, @@ -48,7 +55,7 @@ export default class LegendHelper { /** * Renders a simple rotated text label that is scaled to fit bounds */ - static renderBasicVerticalSvgLabel(g: D3Selection, bounds: LegendBounds, label: string, abbr: string, horizontal: boolean = false) : void { + static renderBasicVerticalSvgLabel(g: D3Selection, bounds: LegendBounds, label: string, abbr: string, horizontal: boolean = false) : D3Selection { const { width, height, left = 0, top = 0 } = bounds; const y = top + height * 0.9; @@ -71,6 +78,7 @@ export default class LegendHelper { if (bbox.width > height * 0.8) { lbl.text(abbr || label); } + return lbl; } /** @@ -91,4 +99,35 @@ export default class LegendHelper { }; return LegendHelper.basicLegendSvgConfig(() => 3, onLegendUpdate); } + + /** + * Convenience function for creating a legend config object for + * a clickable rotated label legend. + */ + static basicVerticalLinkLabel({ label, abbr, onClick, title = null }:BasicVerticalLinkLabelConfig) : LegendConfig { + const onLegendUpdate: LegendOnUpdateFunction = (elm, bounds, track) => { + const g = select(elm); + g.selectAll('*').remove(); + const labelGroup = g.append('g') + .style('fill', '#0000EE') + .style('text-decoration', 'underline') + .style('cursor', 'pointer'); + + labelGroup.append('title').text(title); + + const labelElement = LegendHelper.renderBasicVerticalSvgLabel( + labelGroup, + bounds, + label || track.options.label, + abbr || track.options.abbr, + track.options.horizontal, + ); + + if (onClick && typeof onClick === 'function') { + labelElement + .on('click', onClick); + } + }; + return LegendHelper.basicLegendSvgConfig(() => 3, onLegendUpdate); + } }