@unovis/ts 1.4.3 → 1.4.4-beta.1

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.
@@ -140,6 +140,8 @@ class Crosshair extends XYComponentCore {
140
140
  const container = tooltip.getContainer() || this.container.node();
141
141
  const [x, y] = tooltip.isContainerBody() ? [event.clientX, event.clientY] : pointer(event, container);
142
142
  const content = config.template(this.datum, this.xScale.invert(this.x));
143
+ // Force set `followCursor` to `true` because we don't want Crosshair's tooltip to be hoverable
144
+ tooltip.config.followCursor = true;
143
145
  if (content)
144
146
  tooltip.show(content, { x, y });
145
147
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/crosshair/index.ts"],"sourcesContent":["import { Selection, pointer } from 'd3-selection'\nimport { easeLinear } from 'd3-ease'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { Tooltip } from 'components/tooltip'\n\n// Utils\nimport { isNumber, isArray, getNumber, clamp, getStackedValues, getNearest, isFunction } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Local Types\nimport { CrosshairAccessors, CrosshairCircle } from './types'\n\n// Config\nimport { CrosshairDefaultConfig, CrosshairConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfigInterface<Datum>> {\n static selectors = s\n clippable = true // Don't apply clipping path to this component. See XYContainer\n protected _defaultConfig = CrosshairDefaultConfig as CrosshairConfigInterface<Datum>\n public config: CrosshairConfigInterface<Datum> = this._defaultConfig\n container: Selection<SVGSVGElement, any, SVGSVGElement, any>\n line: Selection<SVGLineElement, any, SVGElement, any>\n x = 0\n datum: Datum\n datumIndex: number\n show = false\n private _animFrameId: number = null\n\n /** Tooltip component to be used by Crosshair if not provided by the config.\n * This property is supposed to be set externally by a container component like XYContainer. */\n public tooltip: Tooltip\n\n /** Accessors passed externally (e.g. from XYContainer) */\n private _accessors: CrosshairAccessors<Datum> = {\n x: undefined,\n y: undefined,\n yStacked: undefined,\n baseline: undefined,\n }\n\n public set accessors (accessors: CrosshairAccessors<Datum>) { this._accessors = accessors }\n public get accessors (): CrosshairAccessors<Datum> {\n const { config } = this\n\n const hasConfig = !!(config.x || config.y || config.yStacked)\n const x = hasConfig ? config.x : this._accessors.x\n const yAcc = hasConfig ? config.y : this._accessors.y\n const y = yAcc ? (isArray(yAcc) ? yAcc : [yAcc]) : undefined\n const yStacked = hasConfig ? config.yStacked : this._accessors.yStacked\n const baseline = config.baseline ?? this._accessors.baseline\n\n return { x, y, yStacked, baseline }\n }\n\n constructor (config?: CrosshairConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n\n this.g.style('opacity', this.show ? 1 : 0)\n this.line = this.g.append('line')\n .attr('class', s.line)\n }\n\n setContainer (containerSvg: Selection<SVGSVGElement, unknown, SVGSVGElement, unknown>): void {\n // Set up mousemove event for Crosshair\n this.container = containerSvg\n this.container.on('mousemove.crosshair', this._onMouseMove.bind(this))\n this.container.on('mouseout.crosshair', this._onMouseOut.bind(this))\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n if (config.snapToData && !this.datum) return\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n smartTransition(this.g, duration)\n .style('opacity', this.show ? 1 : 0)\n\n this.line\n .attr('y1', 0)\n .attr('y1', this._height)\n\n smartTransition(this.line, duration, easeLinear)\n .attr('x1', this.x)\n .attr('x2', this.x)\n\n const circleData = this.getCircleData()\n const circles = this.g\n .selectAll<SVGCircleElement, CrosshairCircle>('circle')\n .data(circleData, (d, i) => d.id ?? i)\n\n const circlesEnter = circles.enter()\n .append('circle')\n .attr('class', s.circle)\n .attr('r', 0)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .style('fill', d => d.color)\n .style('stroke', d => d.strokeColor)\n .style('stroke-width', d => d.strokeWidth)\n\n smartTransition(circlesEnter.merge(circles), duration, easeLinear)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .attr('r', 4)\n .style('opacity', d => d.opacity)\n .style('fill', d => d.color)\n .style('stroke', d => d.strokeColor)\n .style('stroke-width', d => d.strokeWidth)\n\n circles.exit().remove()\n }\n\n hide (): void {\n this._onMouseOut()\n }\n\n _onMouseMove (event: MouseEvent): void {\n const { config, datamodel, element } = this\n if (!this.accessors.x && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: X accessor function has not been configured. Please check if it\\'s present in the configuration object')\n }\n const [x] = pointer(event, element)\n const xRange = this.xScale.range()\n\n if (config.snapToData) {\n if (!this.accessors.y && !this.accessors.yStacked && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: Y accessors have not been configured. Please check if they\\'re present in the configuration object')\n }\n const scaleX = this.xScale\n const valueX = scaleX.invert(x) as number\n\n this.datum = getNearest(datamodel.data, valueX, this.accessors.x)\n this.datumIndex = datamodel.data.indexOf(this.datum)\n if (!this.datum) return\n\n this.x = clamp(Math.round(scaleX(getNumber(this.datum, this.accessors.x, this.datumIndex))), 0, this._width)\n\n // Show the crosshair only if it's in the chart range and not far from mouse pointer (if configured)\n this.show = (this.x >= 0) && (this.x <= this._width) && (!config.hideWhenFarFromPointer || (Math.abs(this.x - x) < config.hideWhenFarFromPointerDistance))\n } else {\n const tolerance = 2 // Show the crosshair when it is at least 2 pixels close to the chart area\n this.x = clamp(x, xRange[0], xRange[1])\n this.show = (x >= (xRange[0] - tolerance)) && (x <= (xRange[1] + tolerance))\n }\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n\n if (this.show) this._showTooltip(event)\n else this._hideTooltip()\n }\n\n _onMouseOut (): void {\n this.show = false\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n this._hideTooltip()\n }\n\n _showTooltip (event: MouseEvent): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n if (!tooltip) return\n\n const container = tooltip.getContainer() || this.container.node()\n const [x, y] = tooltip.isContainerBody() ? [event.clientX, event.clientY] : pointer(event, container)\n const content = config.template(this.datum, this.xScale.invert(this.x))\n if (content) tooltip.show(content, { x, y })\n }\n\n _hideTooltip (): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n tooltip?.hide()\n }\n\n // We don't want Crosshair to be be taken in to account in domain calculations\n getYDataExtent (): number[] {\n return [undefined, undefined]\n }\n\n private getCircleData (): CrosshairCircle[] {\n const { config, datamodel: { data } } = this\n\n if (isFunction(config.getCircles)) return config.getCircles(this.xScale.invert(this.x), data, this.yScale)\n\n if (config.snapToData && this.datum) {\n const yAccessors = this.accessors.y ?? []\n const yStackedAccessors = this.accessors.yStacked ?? []\n const baselineValue = getNumber(this.datum, this.accessors.baseline, this.datumIndex) || 0\n const stackedValues: CrosshairCircle[] = getStackedValues(this.datum, this.datumIndex, ...yStackedAccessors)\n .map((value, index, arr) => ({\n y: this.yScale(value + baselineValue),\n opacity: isNumber(getNumber(this.datum, yStackedAccessors[index])) ? 1 : 0,\n color: getColor(this.datum, config.color, index),\n strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,\n strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,\n }))\n\n const regularValues: CrosshairCircle[] = yAccessors\n .map((a, index) => {\n const value = getNumber(this.datum, a)\n return {\n y: this.yScale(value),\n opacity: isNumber(value) ? 1 : 0,\n color: getColor(this.datum, config.color, stackedValues.length + index),\n strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,\n strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,\n }\n })\n\n return stackedValues.concat(regularValues)\n }\n\n return []\n }\n}\n"],"names":["s.line","s.circle","s"],"mappings":";;;;;;;;;;AAqBM,MAAO,SAAiB,SAAQ,eAAuD,CAAA;AAuC3F,IAAA,WAAA,CAAa,MAAwC,EAAA;AACnD,QAAA,KAAK,EAAE,CAAA;AAtCT,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,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS;AAC/F,aAAA,CAAC,CAAC,CAAA;YAEL,MAAM,aAAa,GAAsB,UAAU;AAChD,iBAAA,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAI;gBAChB,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO;AACL,oBAAA,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;AACrB,oBAAA,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,oBAAA,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC;oBACvE,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS;oBAC7F,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS;iBAC/F,CAAA;AACH,aAAC,CAAC,CAAA;AAEJ,YAAA,OAAO,aAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;AAC3C,SAAA;AAED,QAAA,OAAO,EAAE,CAAA;KACV;;AA7MM,SAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/crosshair/index.ts"],"sourcesContent":["import { Selection, pointer } from 'd3-selection'\nimport { easeLinear } from 'd3-ease'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { Tooltip } from 'components/tooltip'\n\n// Utils\nimport { isNumber, isArray, getNumber, clamp, getStackedValues, getNearest, isFunction } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Local Types\nimport { CrosshairAccessors, CrosshairCircle } from './types'\n\n// Config\nimport { CrosshairDefaultConfig, CrosshairConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfigInterface<Datum>> {\n static selectors = s\n clippable = true // Don't apply clipping path to this component. See XYContainer\n protected _defaultConfig = CrosshairDefaultConfig as CrosshairConfigInterface<Datum>\n public config: CrosshairConfigInterface<Datum> = this._defaultConfig\n container: Selection<SVGSVGElement, any, SVGSVGElement, any>\n line: Selection<SVGLineElement, any, SVGElement, any>\n x = 0\n datum: Datum\n datumIndex: number\n show = false\n private _animFrameId: number = null\n\n /** Tooltip component to be used by Crosshair if not provided by the config.\n * This property is supposed to be set externally by a container component like XYContainer. */\n public tooltip: Tooltip\n\n /** Accessors passed externally (e.g. from XYContainer) */\n private _accessors: CrosshairAccessors<Datum> = {\n x: undefined,\n y: undefined,\n yStacked: undefined,\n baseline: undefined,\n }\n\n public set accessors (accessors: CrosshairAccessors<Datum>) { this._accessors = accessors }\n public get accessors (): CrosshairAccessors<Datum> {\n const { config } = this\n\n const hasConfig = !!(config.x || config.y || config.yStacked)\n const x = hasConfig ? config.x : this._accessors.x\n const yAcc = hasConfig ? config.y : this._accessors.y\n const y = yAcc ? (isArray(yAcc) ? yAcc : [yAcc]) : undefined\n const yStacked = hasConfig ? config.yStacked : this._accessors.yStacked\n const baseline = config.baseline ?? this._accessors.baseline\n\n return { x, y, yStacked, baseline }\n }\n\n constructor (config?: CrosshairConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n\n this.g.style('opacity', this.show ? 1 : 0)\n this.line = this.g.append('line')\n .attr('class', s.line)\n }\n\n setContainer (containerSvg: Selection<SVGSVGElement, unknown, SVGSVGElement, unknown>): void {\n // Set up mousemove event for Crosshair\n this.container = containerSvg\n this.container.on('mousemove.crosshair', this._onMouseMove.bind(this))\n this.container.on('mouseout.crosshair', this._onMouseOut.bind(this))\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n if (config.snapToData && !this.datum) return\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n smartTransition(this.g, duration)\n .style('opacity', this.show ? 1 : 0)\n\n this.line\n .attr('y1', 0)\n .attr('y1', this._height)\n\n smartTransition(this.line, duration, easeLinear)\n .attr('x1', this.x)\n .attr('x2', this.x)\n\n const circleData = this.getCircleData()\n const circles = this.g\n .selectAll<SVGCircleElement, CrosshairCircle>('circle')\n .data(circleData, (d, i) => d.id ?? i)\n\n const circlesEnter = circles.enter()\n .append('circle')\n .attr('class', s.circle)\n .attr('r', 0)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .style('fill', d => d.color)\n .style('stroke', d => d.strokeColor)\n .style('stroke-width', d => d.strokeWidth)\n\n smartTransition(circlesEnter.merge(circles), duration, easeLinear)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .attr('r', 4)\n .style('opacity', d => d.opacity)\n .style('fill', d => d.color)\n .style('stroke', d => d.strokeColor)\n .style('stroke-width', d => d.strokeWidth)\n\n circles.exit().remove()\n }\n\n hide (): void {\n this._onMouseOut()\n }\n\n _onMouseMove (event: MouseEvent): void {\n const { config, datamodel, element } = this\n if (!this.accessors.x && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: X accessor function has not been configured. Please check if it\\'s present in the configuration object')\n }\n const [x] = pointer(event, element)\n const xRange = this.xScale.range()\n\n if (config.snapToData) {\n if (!this.accessors.y && !this.accessors.yStacked && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: Y accessors have not been configured. Please check if they\\'re present in the configuration object')\n }\n const scaleX = this.xScale\n const valueX = scaleX.invert(x) as number\n\n this.datum = getNearest(datamodel.data, valueX, this.accessors.x)\n this.datumIndex = datamodel.data.indexOf(this.datum)\n if (!this.datum) return\n\n this.x = clamp(Math.round(scaleX(getNumber(this.datum, this.accessors.x, this.datumIndex))), 0, this._width)\n\n // Show the crosshair only if it's in the chart range and not far from mouse pointer (if configured)\n this.show = (this.x >= 0) && (this.x <= this._width) && (!config.hideWhenFarFromPointer || (Math.abs(this.x - x) < config.hideWhenFarFromPointerDistance))\n } else {\n const tolerance = 2 // Show the crosshair when it is at least 2 pixels close to the chart area\n this.x = clamp(x, xRange[0], xRange[1])\n this.show = (x >= (xRange[0] - tolerance)) && (x <= (xRange[1] + tolerance))\n }\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n\n if (this.show) this._showTooltip(event)\n else this._hideTooltip()\n }\n\n _onMouseOut (): void {\n this.show = false\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n this._hideTooltip()\n }\n\n _showTooltip (event: MouseEvent): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n if (!tooltip) return\n\n const container = tooltip.getContainer() || this.container.node()\n const [x, y] = tooltip.isContainerBody() ? [event.clientX, event.clientY] : pointer(event, container)\n const content = config.template(this.datum, this.xScale.invert(this.x))\n // Force set `followCursor` to `true` because we don't want Crosshair's tooltip to be hoverable\n tooltip.config.followCursor = true\n if (content) tooltip.show(content, { x, y })\n }\n\n _hideTooltip (): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n tooltip?.hide()\n }\n\n // We don't want Crosshair to be be taken in to account in domain calculations\n getYDataExtent (): number[] {\n return [undefined, undefined]\n }\n\n private getCircleData (): CrosshairCircle[] {\n const { config, datamodel: { data } } = this\n\n if (isFunction(config.getCircles)) return config.getCircles(this.xScale.invert(this.x), data, this.yScale)\n\n if (config.snapToData && this.datum) {\n const yAccessors = this.accessors.y ?? []\n const yStackedAccessors = this.accessors.yStacked ?? []\n const baselineValue = getNumber(this.datum, this.accessors.baseline, this.datumIndex) || 0\n const stackedValues: CrosshairCircle[] = getStackedValues(this.datum, this.datumIndex, ...yStackedAccessors)\n .map((value, index, arr) => ({\n y: this.yScale(value + baselineValue),\n opacity: isNumber(getNumber(this.datum, yStackedAccessors[index])) ? 1 : 0,\n color: getColor(this.datum, config.color, index),\n strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,\n strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,\n }))\n\n const regularValues: CrosshairCircle[] = yAccessors\n .map((a, index) => {\n const value = getNumber(this.datum, a)\n return {\n y: this.yScale(value),\n opacity: isNumber(value) ? 1 : 0,\n color: getColor(this.datum, config.color, stackedValues.length + index),\n strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,\n strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,\n }\n })\n\n return stackedValues.concat(regularValues)\n }\n\n return []\n }\n}\n"],"names":["s.line","s.circle","s"],"mappings":";;;;;;;;;;AAqBM,MAAO,SAAiB,SAAQ,eAAuD,CAAA;AAuC3F,IAAA,WAAA,CAAa,MAAwC,EAAA;AACnD,QAAA,KAAK,EAAE,CAAA;AAtCT,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAA;QACN,IAAc,CAAA,cAAA,GAAG,sBAAyD,CAAA;AAC7E,QAAA,IAAA,CAAA,MAAM,GAAoC,IAAI,CAAC,cAAc,CAAA;QAGpE,IAAC,CAAA,CAAA,GAAG,CAAC,CAAA;QAGL,IAAI,CAAA,IAAA,GAAG,KAAK,CAAA;QACJ,IAAY,CAAA,YAAA,GAAW,IAAI,CAAA;;AAO3B,QAAA,IAAA,CAAA,UAAU,GAA8B;AAC9C,YAAA,CAAC,EAAE,SAAS;AACZ,YAAA,CAAC,EAAE,SAAS;AACZ,YAAA,QAAQ,EAAE,SAAS;AACnB,YAAA,QAAQ,EAAE,SAAS;SACpB,CAAA;AAkBC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAElC,QAAA,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE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G,KAAK,CAAC;oBACvE,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS;oBAC7F,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS;iBAC/F,CAAA;AACH,aAAC,CAAC,CAAA;AAEJ,YAAA,OAAO,aAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;AAC3C,SAAA;AAED,QAAA,OAAO,EAAE,CAAA;KACV;;AA/MM,SAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
@@ -5,13 +5,23 @@ export interface TooltipConfigInterface {
5
5
  components?: ComponentCore<unknown>[];
6
6
  /** Container to where the Tooltip component should be inserted. Default: `undefined` */
7
7
  container?: HTMLElement;
8
+ /** Follow the mouse cursor. If `true`, the tooltip can't be hovered over
9
+ * even when `allowHover` is set to `true`. Default: `true` */
10
+ followCursor?: boolean;
11
+ /** Allow the tooltip to be hovered over and interacted with when `followCursor` is set to `false`.
12
+ * Default: `true` */
13
+ allowHover?: boolean;
8
14
  /** Horizontal placement of the tooltip. Default: `Position.Auto` */
9
15
  horizontalPlacement?: Position | string | undefined;
10
- /** Horizontal shift of the tooltip in pixels. Default: `0` */
16
+ /** Horizontal shift of the tooltip in pixels. Works only with
17
+ * `horizontalPlacement` set to `Position.Left` or `Position.Right`.
18
+ * Default: `0` */
11
19
  horizontalShift?: number;
12
20
  /** Vertical placement of the tooltip. Default: `Position.Top` */
13
21
  verticalPlacement?: Position | string | undefined;
14
- /** Vertical shift of the tooltip in pixels. Default: `0` */
22
+ /** Vertical shift of the tooltip in pixels. Works only with
23
+ * `verticalPlacement` set to `Position.Top` or `Position.Bottom`.
24
+ * Default: `0` */
15
25
  verticalShift?: number;
16
26
  /** Defines the content of the tooltip and hovering over which elements should trigger it.
17
27
  * An object containing properties in the following format:
@@ -29,7 +39,7 @@ export interface TooltipConfigInterface {
29
39
  * ```
30
40
  */
31
41
  triggers?: {
32
- [selector: string]: ((data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null) | undefined | null;
42
+ [selector: string]: ((data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null | void) | undefined | null;
33
43
  };
34
44
  /** Custom DOM attributes for the tooltip. Useful when you need to refer to a specific tooltip instance
35
45
  * by using a CSS selector. Attributes configuration object has the following structure:
@@ -50,5 +60,7 @@ export interface TooltipConfigInterface {
50
60
  attributes?: {
51
61
  [attr: string]: string | number | boolean;
52
62
  };
63
+ /** Custom class name for the tooltip. Default: `undefined` */
64
+ className?: string;
53
65
  }
54
66
  export declare const TooltipDefaultConfig: TooltipConfigInterface;
@@ -4,12 +4,15 @@ import { Position } from '../../types/position.js';
4
4
  const TooltipDefaultConfig = {
5
5
  components: [],
6
6
  container: undefined,
7
+ followCursor: true,
8
+ allowHover: true,
7
9
  horizontalPlacement: Position.Auto,
8
10
  horizontalShift: 0,
9
11
  verticalPlacement: Position.Top,
10
12
  verticalShift: 0,
11
13
  attributes: {},
12
14
  triggers: {},
15
+ className: undefined,
13
16
  };
14
17
 
15
18
  export { TooltipDefaultConfig };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/tooltip/config.ts"],"sourcesContent":["/* eslint-disable no-irregular-whitespace */\nimport { ComponentCore } from 'core/component'\n\n// Types\nimport { Position } from 'types/position'\n\nexport interface TooltipConfigInterface {\n /** An array of visualization components to interact with. Default: `[]` */\n components?: ComponentCore<unknown>[];\n /** Container to where the Tooltip component should be inserted. Default: `undefined` */\n container?: HTMLElement;\n /** Horizontal placement of the tooltip. Default: `Position.Auto` */\n horizontalPlacement?: Position | string | undefined;\n /** Horizontal shift of the tooltip in pixels. Default: `0` */\n horizontalShift?: number;\n /** Vertical placement of the tooltip. Default: `Position.Top` */\n verticalPlacement?: Position | string | undefined;\n /** Vertical shift of the tooltip in pixels. Default: `0` */\n verticalShift?: number;\n /** Defines the content of the tooltip and hovering over which elements should trigger it.\n * An object containing properties in the following format:\n *\n * ```\n * {\n *  [selectorString]: (d: unknown) => string | HTMLElement\n * }\n * ```\n * e.g.:\n * ```\n * {\n *  [Area.selectors.area]: (d: AreaDatum[]) => `<div>${d.value.toString()}</div>\n * }\n * ```\n */\n triggers?: {\n [selector: string]: ((data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null) | undefined | null;\n };\n /** Custom DOM attributes for the tooltip. Useful when you need to refer to a specific tooltip instance\n * by using a CSS selector. Attributes configuration object has the following structure:\n *\n * ```\n * {\n *  [attributeName]: attribute value\n * }\n * ```\n * e.g.:\n * ```\n * {\n *  'type': 'area-tooltip',\n *  'value': 42\n * }\n * ```\n */\n attributes?: { [attr: string]: string | number | boolean };\n}\n\nexport const TooltipDefaultConfig: TooltipConfigInterface = {\n components: [],\n container: undefined,\n horizontalPlacement: Position.Auto,\n horizontalShift: 0,\n verticalPlacement: Position.Top,\n verticalShift: 0,\n attributes: {},\n triggers: {},\n}\n\n"],"names":[],"mappings":";;AAGA;AAqDa,MAAA,oBAAoB,GAA2B;AAC1D,IAAA,UAAU,EAAE,EAAE;AACd,IAAA,SAAS,EAAE,SAAS;IACpB,mBAAmB,EAAE,QAAQ,CAAC,IAAI;AAClC,IAAA,eAAe,EAAE,CAAC;IAClB,iBAAiB,EAAE,QAAQ,CAAC,GAAG;AAC/B,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,UAAU,EAAE,EAAE;AACd,IAAA,QAAQ,EAAE,EAAE;;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/tooltip/config.ts"],"sourcesContent":["/* eslint-disable no-irregular-whitespace */\nimport { ComponentCore } from 'core/component'\n\n// Types\nimport { Position } from 'types/position'\n\nexport interface TooltipConfigInterface {\n /** An array of visualization components to interact with. Default: `[]` */\n components?: ComponentCore<unknown>[];\n /** Container to where the Tooltip component should be inserted. Default: `undefined` */\n container?: HTMLElement;\n /** Follow the mouse cursor. If `true`, the tooltip can't be hovered over\n * even when `allowHover` is set to `true`. Default: `true` */\n followCursor?: boolean;\n /** Allow the tooltip to be hovered over and interacted with when `followCursor` is set to `false`.\n * Default: `true` */\n allowHover?: boolean;\n /** Horizontal placement of the tooltip. Default: `Position.Auto` */\n horizontalPlacement?: Position | string | undefined;\n /** Horizontal shift of the tooltip in pixels. Works only with\n * `horizontalPlacement` set to `Position.Left` or `Position.Right`.\n * Default: `0` */\n horizontalShift?: number;\n /** Vertical placement of the tooltip. Default: `Position.Top` */\n verticalPlacement?: Position | string | undefined;\n /** Vertical shift of the tooltip in pixels. Works only with\n * `verticalPlacement` set to `Position.Top` or `Position.Bottom`.\n * Default: `0` */\n verticalShift?: number;\n /** Defines the content of the tooltip and hovering over which elements should trigger it.\n * An object containing properties in the following format:\n *\n * ```\n * {\n *  [selectorString]: (d: unknown) => string | HTMLElement\n * }\n * ```\n * e.g.:\n * ```\n * {\n *  [Area.selectors.area]: (d: AreaDatum[]) => `<div>${d.value.toString()}</div>\n * }\n * ```\n */\n triggers?: {\n [selector: string]: ((data: any, i: number, elements: (HTMLElement | SVGElement)[]) => string | HTMLElement | undefined | null | void) | undefined | null;\n };\n /** Custom DOM attributes for the tooltip. Useful when you need to refer to a specific tooltip instance\n * by using a CSS selector. Attributes configuration object has the following structure:\n *\n * ```\n * {\n *  [attributeName]: attribute value\n * }\n * ```\n * e.g.:\n * ```\n * {\n *  'type': 'area-tooltip',\n *  'value': 42\n * }\n * ```\n */\n attributes?: { [attr: string]: string | number | boolean };\n /** Custom class name for the tooltip. Default: `undefined` */\n className?: string;\n}\n\nexport const TooltipDefaultConfig: TooltipConfigInterface = {\n components: [],\n container: undefined,\n followCursor: true,\n allowHover: true,\n horizontalPlacement: Position.Auto,\n horizontalShift: 0,\n verticalPlacement: Position.Top,\n verticalShift: 0,\n attributes: {},\n triggers: {},\n className: undefined,\n}\n\n"],"names":[],"mappings":";;AAGA;AAiEa,MAAA,oBAAoB,GAA2B;AAC1D,IAAA,UAAU,EAAE,EAAE;AACd,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,QAAQ,CAAC,IAAI;AAClC,IAAA,eAAe,EAAE,CAAC;IAClB,iBAAiB,EAAE,QAAQ,CAAC,GAAG;AAC/B,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,UAAU,EAAE,EAAE;AACd,IAAA,QAAQ,EAAE,EAAE;AACZ,IAAA,SAAS,EAAE,SAAS;;;;;"}
@@ -14,6 +14,9 @@ export declare class Tooltip {
14
14
  private _setContainerPositionThrottled;
15
15
  private _isShown;
16
16
  private _container;
17
+ private _mutationObserver;
18
+ private _hoveredElement;
19
+ private _position;
17
20
  constructor(config?: TooltipConfigInterface);
18
21
  setConfig(config: TooltipConfigInterface): void;
19
22
  setContainer(container: HTMLElement): void;
@@ -21,16 +24,24 @@ export declare class Tooltip {
21
24
  hasContainer(): boolean;
22
25
  setComponents(components: ComponentCore<unknown>[]): void;
23
26
  update(): void;
24
- show(html: string | HTMLElement, pos: {
27
+ /** Show the tooltip by providing content and position */
28
+ show(html: string | HTMLElement | null | void, pos: {
25
29
  x: number;
26
30
  y: number;
27
31
  }): void;
32
+ /** Hide the tooltip */
28
33
  hide(): void;
34
+ /** Simply displays the tooltip with its previous content on position */
35
+ display(): void;
29
36
  place(pos: {
30
37
  x: number;
31
38
  y: number;
32
39
  }): void;
40
+ placeByElement(hoveredElement: SVGElement | HTMLElement): void;
33
41
  isContainerBody(): boolean;
42
+ render(html: string | HTMLElement | null | void): void;
43
+ private _applyPosition;
44
+ private _constraintPosToContainer;
34
45
  private _setContainerPosition;
35
46
  private _setUpEvents;
36
47
  private _setUpAttributes;
@@ -3,7 +3,7 @@ import { Position } from '../../types/position.js';
3
3
  import { throttle, merge } from '../../utils/data.js';
4
4
  import { TooltipDefaultConfig } from './config.js';
5
5
  import * as style from './style.js';
6
- import { tooltip, hidden, show, positionFixed } from './style.js';
6
+ import { root, show, hidden, nonInteractive, positionFixed } from './style.js';
7
7
 
8
8
  class Tooltip {
9
9
  constructor(config = {}) {
@@ -13,10 +13,24 @@ class Tooltip {
13
13
  this._setContainerPositionThrottled = throttle(this._setContainerPosition, 500);
14
14
  this._isShown = false;
15
15
  this.element = document.createElement('div');
16
- this.div = select(this.element)
17
- .attr('class', tooltip);
16
+ this.div = select(this.element).attr('class', root);
18
17
  this.setConfig(config);
19
18
  this.components = this.config.components;
19
+ // Set up MutationObserver to automatically re-position the tooltip
20
+ // if the content has been dynamically changed
21
+ this._mutationObserver = new MutationObserver(() => {
22
+ if (!this._isShown)
23
+ return;
24
+ // Handle changes to the content of this.div
25
+ // Add your logic here
26
+ if (!this.config.followCursor && this._hoveredElement) {
27
+ this.placeByElement(this._hoveredElement);
28
+ }
29
+ else if (this._position) {
30
+ this.place({ x: this._position[0], y: this._position[1] });
31
+ }
32
+ });
33
+ this._mutationObserver.observe(this.div.node(), { childList: true, subtree: true });
20
34
  }
21
35
  setConfig(config) {
22
36
  var _a;
@@ -48,23 +62,15 @@ class Tooltip {
48
62
  return;
49
63
  this._setUpEventsThrottled();
50
64
  }
65
+ /** Show the tooltip by providing content and position */
51
66
  show(html, pos) {
52
- if (html instanceof HTMLElement) {
53
- const node = this.div.select(':first-child').node();
54
- if (node !== html)
55
- this.div.html('').append(() => html);
56
- }
57
- else {
58
- this.div.html(html);
59
- }
60
- this.div
61
- .classed(hidden, false)
62
- .classed(show, true);
63
- this._isShown = true;
67
+ this.render(html);
64
68
  this.place(pos);
65
69
  }
70
+ /** Hide the tooltip */
66
71
  hide() {
67
- this.div.classed(show, false)
72
+ this.div
73
+ .classed(show, false) // The `show` class triggers the opacity transition
68
74
  .on('transitionend', () => {
69
75
  // We hide the element once the transition completes
70
76
  // This ensures container overflow will not occur when the window is resized
@@ -72,54 +78,153 @@ class Tooltip {
72
78
  });
73
79
  this._isShown = false;
74
80
  }
81
+ /** Simply displays the tooltip with its previous content on position */
82
+ display() {
83
+ this.div
84
+ .classed(hidden, false) // The `hidden` class sets `display: none;`
85
+ .classed(show, true); // The `show` class triggers the opacity transition
86
+ this._isShown = true;
87
+ }
75
88
  place(pos) {
89
+ this._position = [pos.x, pos.y];
76
90
  if (!this.hasContainer()) {
77
91
  console.warn('Unovis | Tooltip: Container was not set or is not initialized yet');
78
92
  return;
79
93
  }
80
94
  const { config } = this;
81
- const isContainerBody = this.isContainerBody();
82
- const width = this.element.offsetWidth;
83
- const height = this.element.offsetHeight;
84
- const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight;
85
- const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth;
95
+ const tooltipWidth = this.element.offsetWidth;
96
+ const tooltipHeight = this.element.offsetHeight;
86
97
  const horizontalPlacement = config.horizontalPlacement === Position.Auto
87
- ? (pos.x > containerWidth / 2 ? Position.Left : Position.Right)
98
+ ? Position.Center
88
99
  : config.horizontalPlacement;
89
100
  const verticalPlacement = config.verticalPlacement === Position.Auto
90
- ? (pos.y > containerHeight / 2 ? Position.Top : Position.Bottom)
101
+ ? ((pos.y - tooltipHeight) < 0 ? Position.Bottom : Position.Top)
91
102
  : config.verticalPlacement;
92
- // dx and dy variables shift the tooltip from the default position (above the cursor, centred horizontally)
103
+ // Todo: Get rid of the hardcoded margin in version 2.0
104
+ // Can be simply replaced with `verticalShift` and `horizontalShift`
105
+ // but it'll be a breaking change
93
106
  const margin = 5;
94
- const dx = horizontalPlacement === Position.Left ? -width - margin - config.horizontalShift
95
- : horizontalPlacement === Position.Center ? -width / 2
107
+ const translateX = horizontalPlacement === Position.Left ? -tooltipWidth - margin - config.horizontalShift
108
+ : horizontalPlacement === Position.Center ? -tooltipWidth / 2
96
109
  : margin + config.horizontalShift;
97
- const dy = verticalPlacement === Position.Bottom ? height + margin + config.verticalShift
98
- : verticalPlacement === Position.Center ? height / 2
99
- : -margin - config.verticalShift;
100
- // Constraint to container
101
- const paddingX = 10;
102
- const hitRight = pos.x > (containerWidth - width - dx - paddingX);
103
- const hitLeft = pos.x < -dx + paddingX;
104
- const constraintX = hitRight ? (containerWidth - width - dx) - pos.x - paddingX
105
- : hitLeft ? -dx - pos.x + paddingX : 0;
106
- const paddingY = 10;
107
- const hitBottom = pos.y > (containerHeight - dy - paddingY);
108
- const hitTop = pos.y < (height - dy + paddingY);
109
- const constraintY = hitBottom ? containerHeight - dy - pos.y - paddingY
110
- : hitTop ? height - dy - pos.y + paddingY : 0;
111
- // Placing
112
- // If the container size is smaller than the the tooltip size we just stick the tooltip to the top / left
113
- const x = containerWidth < width ? 0 : pos.x + constraintX + dx;
114
- const y = containerHeight < height ? height : pos.y + constraintY + dy;
110
+ const translateY = verticalPlacement === Position.Bottom ? margin + config.verticalShift
111
+ : verticalPlacement === Position.Center ? -tooltipHeight / 2
112
+ : -margin - config.verticalShift - tooltipHeight;
113
+ // translateX and translateY variables shift the tooltip from the default position (above the cursor, centred horizontally)
114
+ const [top, left] = this._constraintPosToContainer(pos.x + translateX, pos.y + translateY, tooltipWidth, tooltipHeight);
115
+ this._applyPosition(top, left, tooltipHeight);
116
+ }
117
+ placeByElement(hoveredElement) {
118
+ const { config } = this;
119
+ // Store the hovered element and the event for future reference,
120
+ // i.e. to re-position the tooltip if the content has been changed
121
+ // by something else and it was captured by the MutationObserver
122
+ this._hoveredElement = hoveredElement;
123
+ // Todo: Get rid of the hardcoded margin in version 2.0
124
+ // Can be simply replaced with `verticalShift` and `horizontalShift`
125
+ // but it'll be a breaking change
126
+ const margin = 5;
127
+ const tooltipWidth = this.element.offsetWidth;
128
+ const tooltipHeight = this.element.offsetHeight;
129
+ const isContainerBody = this.isContainerBody();
130
+ const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth;
131
+ const hoveredElementRect = hoveredElement.getBoundingClientRect();
132
+ // We use D3's point transformation to get the correct position of the element by pretending it's a pointer event
133
+ // See more: https://github.com/d3/d3-selection/blob/main/src/pointer.js
134
+ const elementPos = isContainerBody ? [hoveredElementRect.x, hoveredElementRect.y] : pointer({
135
+ clientX: hoveredElementRect.x,
136
+ clientY: hoveredElementRect.y,
137
+ pageX: hoveredElementRect.x,
138
+ pageY: hoveredElementRect.y,
139
+ }, this._container);
140
+ const horizontalPlacement = config.horizontalPlacement === Position.Auto
141
+ ? (elementPos[0] - tooltipWidth < 0 ? Position.Right
142
+ : elementPos[0] + tooltipWidth > containerWidth ? Position.Left : Position.Center)
143
+ : config.horizontalPlacement;
144
+ let translateX = 0;
145
+ switch (horizontalPlacement) {
146
+ case Position.Left:
147
+ translateX = -tooltipWidth - margin - config.horizontalShift;
148
+ break;
149
+ case Position.Right:
150
+ translateX = hoveredElementRect.width + margin + config.horizontalShift;
151
+ break;
152
+ case Position.Center:
153
+ default:
154
+ translateX = (-tooltipWidth + hoveredElementRect.width) / 2;
155
+ break;
156
+ }
157
+ const verticalPlacement = config.verticalPlacement === Position.Auto
158
+ ? (horizontalPlacement !== Position.Center ? Position.Center
159
+ : elementPos[1] - tooltipHeight < 0 ? Position.Bottom : Position.Top)
160
+ : config.verticalPlacement;
161
+ let translateY = -tooltipHeight;
162
+ switch (verticalPlacement) {
163
+ case Position.Center:
164
+ translateY += (tooltipHeight + hoveredElementRect.height) / 2;
165
+ break;
166
+ case Position.Bottom:
167
+ translateY += tooltipHeight + hoveredElementRect.height + margin + config.verticalShift;
168
+ break;
169
+ case Position.Top:
170
+ default:
171
+ translateY += -margin - config.verticalShift;
172
+ break;
173
+ }
174
+ const [top, left] = this._constraintPosToContainer(elementPos[0] + translateX, elementPos[1] + translateY, tooltipWidth, tooltipHeight);
175
+ this._applyPosition(top, left, tooltipHeight);
176
+ }
177
+ isContainerBody() {
178
+ return this._container === document.body;
179
+ }
180
+ render(html) {
181
+ var _a;
182
+ const { config, prevConfig } = this;
183
+ if (html instanceof HTMLElement) {
184
+ const node = this.div.select(':first-child').node();
185
+ if (node !== html)
186
+ this.div.html('').append(() => html);
187
+ }
188
+ else if (html) {
189
+ this.div.html(html);
190
+ }
191
+ this.div
192
+ .classed((_a = config.className) !== null && _a !== void 0 ? _a : '', Boolean(config.className))
193
+ .classed(nonInteractive, !config.allowHover || config.followCursor);
194
+ // Remove the previous class name if it was set
195
+ if ((prevConfig === null || prevConfig === void 0 ? void 0 : prevConfig.className) && prevConfig.className !== config.className) {
196
+ this.div.classed(prevConfig.className, false);
197
+ }
198
+ this.display();
199
+ }
200
+ _applyPosition(x, y, tooltipHeight) {
201
+ const isContainerBody = this.isContainerBody();
202
+ const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight;
115
203
  this.div
116
204
  .classed(positionFixed, isContainerBody)
117
- .style('top', isContainerBody ? `${y - height}px` : 'unset')
118
- .style('bottom', !isContainerBody ? `${containerHeight - y}px` : 'unset')
205
+ .style('top', isContainerBody ? `${y}px` : 'unset')
206
+ .style('bottom', !isContainerBody ? `${containerHeight - y - tooltipHeight}px` : 'unset')
119
207
  .style('left', `${x}px`);
120
208
  }
121
- isContainerBody() {
122
- return this._container === document.body;
209
+ _constraintPosToContainer(top, left, tooltipWidth, tooltipHeight) {
210
+ const isContainerBody = this.isContainerBody();
211
+ const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight;
212
+ const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth;
213
+ // // Constraint to container
214
+ const paddingX = 10;
215
+ const hitRight = top > (containerWidth - tooltipWidth - paddingX);
216
+ const hitLeft = top < paddingX;
217
+ const constrainedLeft = hitRight ? containerWidth - tooltipWidth - paddingX
218
+ : hitLeft ? paddingX : top;
219
+ const paddingY = 10;
220
+ const hitBottom = left > (containerHeight - tooltipHeight - paddingY);
221
+ const hitTop = left < paddingY;
222
+ const constrainedTop = hitBottom ? containerHeight - tooltipHeight - paddingY
223
+ : hitTop ? paddingY : left;
224
+ return [
225
+ containerWidth < tooltipWidth ? 0 : constrainedLeft,
226
+ containerHeight < tooltipHeight ? 0 : constrainedTop,
227
+ ];
123
228
  }
124
229
  _setContainerPosition() {
125
230
  var _a;
@@ -130,8 +235,7 @@ class Tooltip {
130
235
  }
131
236
  }
132
237
  _setUpEvents() {
133
- const { config: { triggers } } = this;
134
- const isContainerBody = this.isContainerBody();
238
+ const { config } = this;
135
239
  // We use the Event Delegation pattern to set up Tooltip events
136
240
  // Every component will have single `mousemove` and `mouseleave` event listener functions, where we'll check
137
241
  // the `path` of the event and trigger corresponding callbacks
@@ -139,11 +243,10 @@ class Tooltip {
139
243
  const selection = select(component.element);
140
244
  selection
141
245
  .on('mousemove.tooltip', (e) => {
142
- const [x, y] = isContainerBody ? [e.clientX, e.clientY] : pointer(e, this._container);
143
246
  const path = (e.composedPath && e.composedPath()) || e.path || [e.target];
144
247
  // Go through all of the configured triggers
145
- for (const className of Object.keys(triggers)) {
146
- const template = triggers[className];
248
+ for (const className of Object.keys(config.triggers)) {
249
+ const template = config.triggers[className];
147
250
  if (!template)
148
251
  continue; // Skip if the trigger is not configured
149
252
  const els = selection.selectAll(`.${className}`).nodes();
@@ -155,12 +258,24 @@ class Tooltip {
155
258
  const i = els.indexOf(el);
156
259
  const d = select(el).datum();
157
260
  const content = template(d, i, els);
158
- if (content)
159
- this.show(content, { x, y });
160
- else
261
+ const [x, y] = this.isContainerBody() ? [e.clientX, e.clientY] : pointer(e, this._container);
262
+ if (content === null) {
263
+ // If the content is `null`, we hide the tooltip
161
264
  this.hide();
162
- e.stopPropagation(); // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair
163
- return; // Stop looking for other matches
265
+ }
266
+ else {
267
+ // Otherwise we show the tooltip, but don't render the content if it's `undefined` or
268
+ // an empty string. This way we can allow it to work with things like `createPortal` in React
269
+ this.render(content);
270
+ if (config.followCursor)
271
+ this.place({ x, y });
272
+ else
273
+ this.placeByElement(el);
274
+ }
275
+ // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair
276
+ e.stopPropagation();
277
+ // Stop looking for other matches
278
+ return;
164
279
  }
165
280
  }
166
281
  }
@@ -175,6 +290,17 @@ class Tooltip {
175
290
  this.hide();
176
291
  });
177
292
  });
293
+ // Set up Tooltip hover
294
+ if (config.allowHover && !config.followCursor) {
295
+ this.div
296
+ .on('mouseenter.tooltip', this.display.bind(this))
297
+ .on('mouseleave.tooltip', this.hide.bind(this));
298
+ }
299
+ else {
300
+ this.div
301
+ .on('mouseenter.tooltip', null)
302
+ .on('mouseleave.tooltip', null);
303
+ }
178
304
  }
179
305
  _setUpAttributes() {
180
306
  const attributesMap = this.config.attributes;
@@ -186,6 +312,7 @@ class Tooltip {
186
312
  }
187
313
  destroy() {
188
314
  var _a;
315
+ this._mutationObserver.disconnect();
189
316
  (_a = this.div) === null || _a === void 0 ? void 0 : _a.remove();
190
317
  }
191
318
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/tooltip/index.ts"],"sourcesContent":["import { select, Selection, pointer } from 'd3-selection'\n\n// Core\nimport { ComponentCore } from 'core/component'\n\n// Types\nimport { Position } from 'types/position'\n\n// Utils\nimport { merge, throttle } from 'utils/data'\n\n// Config\nimport { TooltipDefaultConfig, TooltipConfigInterface } from './config'\n\n// Style\nimport * as s from './style'\n\nexport class Tooltip {\n element: HTMLElement\n div: Selection<HTMLElement, unknown, null, undefined>\n protected _defaultConfig = TooltipDefaultConfig as TooltipConfigInterface\n public config: TooltipConfigInterface = this._defaultConfig\n prevConfig: TooltipConfigInterface\n components: ComponentCore<unknown>[]\n static selectors = s\n private _setUpEventsThrottled = throttle(this._setUpEvents, 500)\n private _setContainerPositionThrottled = throttle(this._setContainerPosition, 500)\n private _isShown = false\n private _container: HTMLElement\n\n constructor (config: TooltipConfigInterface = {}) {\n this.element = document.createElement('div')\n this.div = select(this.element)\n .attr('class', s.tooltip)\n\n this.setConfig(config)\n this.components = this.config.components\n }\n\n public setConfig (config: TooltipConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n\n if (this.config.container && (this.config.container !== this.prevConfig?.container)) {\n this.setContainer(this.config.container)\n }\n\n this._setUpAttributes()\n }\n\n public setContainer (container: HTMLElement): void {\n this.element.parentNode?.removeChild(this.element)\n\n this._container = container\n this._container.appendChild(this.element)\n\n this._setContainerPositionThrottled()\n }\n\n public getContainer (): HTMLElement {\n return this._container\n }\n\n public hasContainer (): boolean {\n return !!this._container && this._container.isConnected\n }\n\n public setComponents (components: ComponentCore<unknown>[]): void {\n this.components = components\n }\n\n public update (): void {\n if (!this._container) return\n\n this._setUpEventsThrottled()\n }\n\n public show (html: string | HTMLElement, pos: { x: number; y: number }): void {\n if (html instanceof HTMLElement) {\n const node = this.div.select(':first-child').node()\n if (node !== html) this.div.html('').append(() => html)\n } else {\n this.div.html(html)\n }\n\n this.div\n .classed(s.hidden, false)\n .classed(s.show, true)\n\n this._isShown = true\n this.place(pos)\n }\n\n public hide (): void {\n this.div.classed(s.show, false)\n .on('transitionend', () => {\n // We hide the element once the transition completes\n // This ensures container overflow will not occur when the window is resized\n this.div.classed(s.hidden, !this._isShown)\n })\n\n this._isShown = false\n }\n\n public place (pos: { x: number; y: number }): void {\n if (!this.hasContainer()) {\n console.warn('Unovis | Tooltip: Container was not set or is not initialized yet')\n return\n }\n const { config } = this\n const isContainerBody = this.isContainerBody()\n const width = this.element.offsetWidth\n const height = this.element.offsetHeight\n const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight\n const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth\n\n const horizontalPlacement = config.horizontalPlacement === Position.Auto\n ? (pos.x > containerWidth / 2 ? Position.Left : Position.Right)\n : config.horizontalPlacement\n\n const verticalPlacement = config.verticalPlacement === Position.Auto\n ? (pos.y > containerHeight / 2 ? Position.Top : Position.Bottom)\n : config.verticalPlacement\n\n // dx and dy variables shift the tooltip from the default position (above the cursor, centred horizontally)\n const margin = 5\n const dx = horizontalPlacement === Position.Left ? -width - margin - config.horizontalShift\n : horizontalPlacement === Position.Center ? -width / 2\n : margin + config.horizontalShift\n const dy = verticalPlacement === Position.Bottom ? height + margin + config.verticalShift\n : verticalPlacement === Position.Center ? height / 2\n : -margin - config.verticalShift\n\n // Constraint to container\n const paddingX = 10\n const hitRight = pos.x > (containerWidth - width - dx - paddingX)\n const hitLeft = pos.x < -dx + paddingX\n const constraintX = hitRight ? (containerWidth - width - dx) - pos.x - paddingX\n : hitLeft ? -dx - pos.x + paddingX : 0\n\n const paddingY = 10\n const hitBottom = pos.y > (containerHeight - dy - paddingY)\n const hitTop = pos.y < (height - dy + paddingY)\n const constraintY = hitBottom ? containerHeight - dy - pos.y - paddingY\n : hitTop ? height - dy - pos.y + paddingY : 0\n\n // Placing\n // If the container size is smaller than the the tooltip size we just stick the tooltip to the top / left\n const x = containerWidth < width ? 0 : pos.x + constraintX + dx\n const y = containerHeight < height ? height : pos.y + constraintY + dy\n\n this.div\n .classed(s.positionFixed, isContainerBody)\n .style('top', isContainerBody ? `${y - height}px` : 'unset')\n .style('bottom', !isContainerBody ? `${containerHeight - y}px` : 'unset')\n .style('left', `${x}px`)\n }\n\n public isContainerBody (): boolean {\n return this._container === document.body\n }\n\n private _setContainerPosition (): void {\n // Tooltip position calculation relies on the parent position\n // If it's not set (static), we set it to `relative` (not a good practice)\n if (this._container !== document.body && getComputedStyle(this._container)?.position === 'static') {\n this._container.style.position = 'relative'\n }\n }\n\n private _setUpEvents (): void {\n const { config: { triggers } } = this\n const isContainerBody = this.isContainerBody()\n\n // We use the Event Delegation pattern to set up Tooltip events\n // Every component will have single `mousemove` and `mouseleave` event listener functions, where we'll check\n // the `path` of the event and trigger corresponding callbacks\n this.components.forEach(component => {\n const selection = select(component.element)\n selection\n .on('mousemove.tooltip', (e: MouseEvent) => {\n const [x, y] = isContainerBody ? [e.clientX, e.clientY] : pointer(e, this._container)\n const path: (HTMLElement | SVGGElement)[] = (e.composedPath && e.composedPath()) || (e as any).path || [e.target]\n\n // Go through all of the configured triggers\n for (const className of Object.keys(triggers)) {\n const template = triggers[className]\n if (!template) continue // Skip if the trigger is not configured\n\n const els = selection.selectAll<HTMLElement | SVGGElement, unknown>(`.${className}`).nodes()\n\n // Go through all of the elements in the event path (from the deepest element upwards)\n for (const el of path) {\n if (el === selection.node()) break // Break on the component's level (usually the `<g>` element)\n if (el.classList.contains(className)) { // If there's a match, show the tooltip\n const i = els.indexOf(el)\n const d = select(el).datum()\n const content = template(d, i, els)\n if (content) this.show(content, { x, y })\n else this.hide()\n\n e.stopPropagation() // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair\n return // Stop looking for other matches\n }\n }\n }\n\n // Hide the tooltip if the event didn't pass through any of the configured triggers.\n // We use the `this._isShown` condition as a little performance optimization tweak\n // (we don't want the tooltip to update its class on every mouse movement, see `this.hide()`).\n if (this._isShown) this.hide()\n })\n .on('mouseleave.tooltip', (e: MouseEvent) => {\n e.stopPropagation() // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair\n this.hide()\n })\n })\n }\n\n private _setUpAttributes (): void {\n const attributesMap = this.config.attributes\n if (!attributesMap) return\n\n Object.keys(attributesMap).forEach(attr => {\n this.div.attr(attr, attributesMap[attr])\n })\n }\n\n public destroy (): void {\n this.div?.remove()\n }\n}\n"],"names":["s.tooltip","s.hidden","s.show","s.positionFixed","s"],"mappings":";;;;;;;MAiBa,OAAO,CAAA;AAalB,IAAA,WAAA,CAAa,SAAiC,EAAE,EAAA;QAVtC,IAAc,CAAA,cAAA,GAAG,oBAA8C,CAAA;AAClE,QAAA,IAAA,CAAA,MAAM,GAA2B,IAAI,CAAC,cAAc,CAAA;QAInD,IAAqB,CAAA,qBAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;QACxD,IAA8B,CAAA,8BAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;QAC1E,IAAQ,CAAA,QAAA,GAAG,KAAK,CAAA;QAItB,IAAI,CAAC,OAAO,GAAG,QA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BAAA,IAAI,OAAO;gCAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;;gCACpC,IAAI,CAAC,IAAI,EAAE,CAAA;AAEhB,4BAAA,CAAC,CAAC,eAAe,EAAE,CAAA;AACnB,4BAAA,OAAM;AACP,yBAAA;AACF,qBAAA;AACF,iBAAA;;;;gBAKD,IAAI,IAAI,CAAC,QAAQ;oBAAE,IAAI,CAAC,IAAI,EAAE,CAAA;AAChC,aAAC,CAAC;AACD,iBAAA,EAAE,CAAC,oBAAoB,EAAE,CAAC,CAAa,KAAI;AAC1C,gBAAA,CAAC,CAAC,eAAe,EAAE,CAAA;gBACnB,IAAI,CAAC,IAAI,EAAE,CAAA;AACb,aAAC,CAAC,CAAA;AACN,SAAC,CAAC,CAAA;KACH;IAEO,gBAAgB,GAAA;AACtB,QAAA,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;AAC5C,QAAA,IAAI,CAAC,aAAa;YAAE,OAAM;QAE1B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,IAAI,IAAG;AACxC,YAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,SAAC,CAAC,CAAA;KACH;IAEM,OAAO,GAAA;;AACZ,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,EAAE,CAAA;KACnB;;AA9MM,OAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/tooltip/index.ts"],"sourcesContent":["import { select, Selection, pointer } from 'd3-selection'\n\n// Core\nimport { ComponentCore } from 'core/component'\n\n// Types\nimport { Position } from 'types/position'\n\n// Utils\nimport { merge, throttle } from 'utils/data'\n\n// Config\nimport { TooltipDefaultConfig, TooltipConfigInterface } from './config'\n\n// Style\nimport * as s from './style'\n\nexport class Tooltip {\n element: HTMLElement\n div: Selection<HTMLElement, unknown, null, undefined>\n protected _defaultConfig = TooltipDefaultConfig as TooltipConfigInterface\n public config: TooltipConfigInterface = this._defaultConfig\n prevConfig: TooltipConfigInterface\n components: ComponentCore<unknown>[]\n static selectors = s\n private _setUpEventsThrottled = throttle(this._setUpEvents, 500)\n private _setContainerPositionThrottled = throttle(this._setContainerPosition, 500)\n private _isShown = false\n private _container: HTMLElement\n private _mutationObserver: MutationObserver\n private _hoveredElement: HTMLElement | SVGElement\n private _position: [number, number]\n\n constructor (config: TooltipConfigInterface = {}) {\n this.element = document.createElement('div')\n this.div = select(this.element).attr('class', s.root)\n\n this.setConfig(config)\n this.components = this.config.components\n\n // Set up MutationObserver to automatically re-position the tooltip\n // if the content has been dynamically changed\n this._mutationObserver = new MutationObserver(() => {\n if (!this._isShown) return\n\n // Handle changes to the content of this.div\n // Add your logic here\n if (!this.config.followCursor && this._hoveredElement) {\n this.placeByElement(this._hoveredElement)\n } else if (this._position) {\n this.place({ x: this._position[0], y: this._position[1] })\n }\n })\n\n this._mutationObserver.observe(this.div.node(), { childList: true, subtree: true })\n }\n\n public setConfig (config: TooltipConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n\n if (this.config.container && (this.config.container !== this.prevConfig?.container)) {\n this.setContainer(this.config.container)\n }\n\n this._setUpAttributes()\n }\n\n public setContainer (container: HTMLElement): void {\n this.element.parentNode?.removeChild(this.element)\n\n this._container = container\n this._container.appendChild(this.element)\n\n this._setContainerPositionThrottled()\n }\n\n public getContainer (): HTMLElement {\n return this._container\n }\n\n public hasContainer (): boolean {\n return !!this._container && this._container.isConnected\n }\n\n public setComponents (components: ComponentCore<unknown>[]): void {\n this.components = components\n }\n\n public update (): void {\n if (!this._container) return\n\n this._setUpEventsThrottled()\n }\n\n /** Show the tooltip by providing content and position */\n public show (html: string | HTMLElement | null | void, pos: { x: number; y: number }): void {\n this.render(html)\n this.place(pos)\n }\n\n /** Hide the tooltip */\n public hide (): void {\n this.div\n .classed(s.show, false) // The `show` class triggers the opacity transition\n .on('transitionend', () => {\n // We hide the element once the transition completes\n // This ensures container overflow will not occur when the window is resized\n this.div.classed(s.hidden, !this._isShown)\n })\n\n this._isShown = false\n }\n\n /** Simply displays the tooltip with its previous content on position */\n public display (): void {\n this.div\n .classed(s.hidden, false) // The `hidden` class sets `display: none;`\n .classed(s.show, true) // The `show` class triggers the opacity transition\n\n this._isShown = true\n }\n\n public place (pos: { x: number; y: number }): void {\n this._position = [pos.x, pos.y]\n\n if (!this.hasContainer()) {\n console.warn('Unovis | Tooltip: Container was not set or is not initialized yet')\n return\n }\n\n const { config } = this\n const tooltipWidth = this.element.offsetWidth\n const tooltipHeight = this.element.offsetHeight\n\n const horizontalPlacement = config.horizontalPlacement === Position.Auto\n ? Position.Center\n : config.horizontalPlacement\n\n const verticalPlacement = config.verticalPlacement === Position.Auto\n ? ((pos.y - tooltipHeight) < 0 ? Position.Bottom : Position.Top)\n : config.verticalPlacement\n\n // Todo: Get rid of the hardcoded margin in version 2.0\n // Can be simply replaced with `verticalShift` and `horizontalShift`\n // but it'll be a breaking change\n const margin = 5\n const translateX = horizontalPlacement === Position.Left ? -tooltipWidth - margin - config.horizontalShift\n : horizontalPlacement === Position.Center ? -tooltipWidth / 2\n : margin + config.horizontalShift\n\n const translateY = verticalPlacement === Position.Bottom ? margin + config.verticalShift\n : verticalPlacement === Position.Center ? -tooltipHeight / 2\n : -margin - config.verticalShift - tooltipHeight\n\n // translateX and translateY variables shift the tooltip from the default position (above the cursor, centred horizontally)\n const [top, left] = this._constraintPosToContainer(pos.x + translateX, pos.y + translateY, tooltipWidth, tooltipHeight)\n this._applyPosition(top, left, tooltipHeight)\n }\n\n public placeByElement (hoveredElement: SVGElement | HTMLElement): void {\n const { config } = this\n\n // Store the hovered element and the event for future reference,\n // i.e. to re-position the tooltip if the content has been changed\n // by something else and it was captured by the MutationObserver\n this._hoveredElement = hoveredElement\n\n // Todo: Get rid of the hardcoded margin in version 2.0\n // Can be simply replaced with `verticalShift` and `horizontalShift`\n // but it'll be a breaking change\n const margin = 5\n const tooltipWidth = this.element.offsetWidth\n const tooltipHeight = this.element.offsetHeight\n const isContainerBody = this.isContainerBody()\n const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth\n const hoveredElementRect = hoveredElement.getBoundingClientRect()\n\n // We use D3's point transformation to get the correct position of the element by pretending it's a pointer event\n // See more: https://github.com/d3/d3-selection/blob/main/src/pointer.js\n const elementPos = isContainerBody ? [hoveredElementRect.x, hoveredElementRect.y] : pointer({\n clientX: hoveredElementRect.x,\n clientY: hoveredElementRect.y,\n pageX: hoveredElementRect.x,\n pageY: hoveredElementRect.y,\n }, this._container)\n\n const horizontalPlacement = config.horizontalPlacement === Position.Auto\n ? (elementPos[0] - tooltipWidth < 0 ? Position.Right\n : elementPos[0] + tooltipWidth > containerWidth ? Position.Left : Position.Center)\n : config.horizontalPlacement\n\n let translateX = 0\n switch (horizontalPlacement) {\n case Position.Left:\n translateX = -tooltipWidth - margin - config.horizontalShift\n break\n case Position.Right:\n translateX = hoveredElementRect.width + margin + config.horizontalShift\n break\n case Position.Center:\n default:\n translateX = (-tooltipWidth + hoveredElementRect.width) / 2\n break\n }\n\n const verticalPlacement = config.verticalPlacement === Position.Auto\n ? (horizontalPlacement !== Position.Center ? Position.Center\n : elementPos[1] - tooltipHeight < 0 ? Position.Bottom : Position.Top)\n : config.verticalPlacement\n\n let translateY = -tooltipHeight\n switch (verticalPlacement) {\n case Position.Center:\n translateY += (tooltipHeight + hoveredElementRect.height) / 2\n break\n case Position.Bottom:\n translateY += tooltipHeight + hoveredElementRect.height + margin + config.verticalShift\n break\n case Position.Top:\n default:\n translateY += -margin - config.verticalShift\n break\n }\n\n const [top, left] = this._constraintPosToContainer(elementPos[0] + translateX, elementPos[1] + translateY, tooltipWidth, tooltipHeight)\n this._applyPosition(top, left, tooltipHeight)\n }\n\n public isContainerBody (): boolean {\n return this._container === document.body\n }\n\n public render (html: string | HTMLElement | null | void): void {\n const { config, prevConfig } = this\n if (html instanceof HTMLElement) {\n const node = this.div.select(':first-child').node()\n if (node !== html) this.div.html('').append(() => html)\n } else if (html) {\n this.div.html(html)\n }\n\n this.div\n .classed(config.className ?? '', Boolean(config.className))\n .classed(s.nonInteractive, !config.allowHover || config.followCursor)\n\n // Remove the previous class name if it was set\n if (prevConfig?.className && prevConfig.className !== config.className) {\n this.div.classed(prevConfig.className, false)\n }\n\n this.display()\n }\n\n private _applyPosition (x: number, y: number, tooltipHeight: number): void {\n const isContainerBody = this.isContainerBody()\n const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight\n\n this.div\n .classed(s.positionFixed, isContainerBody)\n .style('top', isContainerBody ? `${y}px` : 'unset')\n .style('bottom', !isContainerBody ? `${containerHeight - y - tooltipHeight}px` : 'unset')\n .style('left', `${x}px`)\n }\n\n private _constraintPosToContainer (top: number, left: number, tooltipWidth: number, tooltipHeight: number): [number, number] {\n const isContainerBody = this.isContainerBody()\n const containerHeight = isContainerBody ? window.innerHeight : this._container.scrollHeight\n const containerWidth = isContainerBody ? window.innerWidth : this._container.scrollWidth\n\n // // Constraint to container\n const paddingX = 10\n const hitRight = top > (containerWidth - tooltipWidth - paddingX)\n const hitLeft = top < paddingX\n const constrainedLeft = hitRight ? containerWidth - tooltipWidth - paddingX\n : hitLeft ? paddingX : top\n\n const paddingY = 10\n const hitBottom = left > (containerHeight - tooltipHeight - paddingY)\n const hitTop = left < paddingY\n const constrainedTop = hitBottom ? containerHeight - tooltipHeight - paddingY\n : hitTop ? paddingY : left\n\n return [\n containerWidth < tooltipWidth ? 0 : constrainedLeft,\n containerHeight < tooltipHeight ? 0 : constrainedTop,\n ]\n }\n\n private _setContainerPosition (): void {\n // Tooltip position calculation relies on the parent position\n // If it's not set (static), we set it to `relative` (not a good practice)\n if (this._container !== document.body && getComputedStyle(this._container)?.position === 'static') {\n this._container.style.position = 'relative'\n }\n }\n\n private _setUpEvents (): void {\n const { config } = this\n\n // We use the Event Delegation pattern to set up Tooltip events\n // Every component will have single `mousemove` and `mouseleave` event listener functions, where we'll check\n // the `path` of the event and trigger corresponding callbacks\n this.components.forEach(component => {\n const selection = select(component.element)\n selection\n .on('mousemove.tooltip', (e: MouseEvent) => {\n const path: (HTMLElement | SVGGElement)[] = (e.composedPath && e.composedPath()) || (e as any).path || [e.target]\n\n // Go through all of the configured triggers\n for (const className of Object.keys(config.triggers)) {\n const template = config.triggers[className]\n if (!template) continue // Skip if the trigger is not configured\n\n const els = selection.selectAll<HTMLElement | SVGGElement, unknown>(`.${className}`).nodes()\n\n // Go through all of the elements in the event path (from the deepest element upwards)\n for (const el of path) {\n if (el === selection.node()) break // Break on the component's level (usually the `<g>` element)\n if (el.classList.contains(className)) { // If there's a match, show the tooltip\n const i = els.indexOf(el)\n const d = select(el).datum()\n const content = template(d, i, els)\n const [x, y] = this.isContainerBody() ? [e.clientX, e.clientY] : pointer(e, this._container)\n if (content === null) {\n // If the content is `null`, we hide the tooltip\n this.hide()\n } else {\n // Otherwise we show the tooltip, but don't render the content if it's `undefined` or\n // an empty string. This way we can allow it to work with things like `createPortal` in React\n this.render(content)\n if (config.followCursor) this.place({ x, y })\n else this.placeByElement(el)\n }\n\n // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair\n e.stopPropagation()\n\n // Stop looking for other matches\n return\n }\n }\n }\n\n // Hide the tooltip if the event didn't pass through any of the configured triggers.\n // We use the `this._isShown` condition as a little performance optimization tweak\n // (we don't want the tooltip to update its class on every mouse movement, see `this.hide()`).\n if (this._isShown) this.hide()\n })\n .on('mouseleave.tooltip', (e: MouseEvent) => {\n e.stopPropagation() // Stop propagation to prevent other interfering events from being triggered, e.g. Crosshair\n this.hide()\n })\n })\n\n // Set up Tooltip hover\n if (config.allowHover && !config.followCursor) {\n this.div\n .on('mouseenter.tooltip', this.display.bind(this))\n .on('mouseleave.tooltip', this.hide.bind(this))\n } else {\n this.div\n .on('mouseenter.tooltip', null)\n .on('mouseleave.tooltip', null)\n }\n }\n\n private _setUpAttributes (): void {\n const attributesMap = this.config.attributes\n if (!attributesMap) return\n\n Object.keys(attributesMap).forEach(attr => {\n this.div.attr(attr, attributesMap[attr])\n })\n }\n\n public destroy (): void {\n this._mutationObserver.disconnect()\n this.div?.remove()\n }\n}\n"],"names":["s.root","s.show","s.hidden","s.nonInteractive","s.positionFixed","s"],"mappings":";;;;;;;MAiBa,OAAO,CAAA;AAgBlB,IAAA,WAAA,CAAa,SAAiC,EAAE,EAAA;QAbtC,IAAc,CAAA,cAAA,GAAG,oBAA8C,CAAA;AAClE,QAAA,IAAA,CAAA,MAAM,GAA2B,IAAI,CAAC,cAAc,CAAA;QAInD,IAAqB,CAAA,qBAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;QACxD,IAA8B,CAAA,8BAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;QAC1E,IAAQ,CAAA,QAAA,GAAG,KAAK,CAAA;QAOtB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAC5C,QAAA,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC,CAAA;AAErD,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;;;AAIxC,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,gBAAgB,CAAC,MAAK;YACjD,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAM;;;YAI1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,IAA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AAI,CAAC;AAC9B,iBAAA,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAA;AAClC,SAAA;KACF;IAEO,gBAAgB,GAAA;AACtB,QAAA,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;AAC5C,QAAA,IAAI,CAAC,aAAa;YAAE,OAAM;QAE1B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,IAAI,IAAG;AACxC,YAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,SAAC,CAAC,CAAA;KACH;IAEM,OAAO,GAAA;;AACZ,QAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAA;AACnC,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,EAAE,CAAA;KACnB;;AAnWM,OAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
@@ -1,6 +1,10 @@
1
1
  export declare const root: string;
2
- export declare const variables: void;
2
+ /**
3
+ * @deprecated This selector is deprecated and will be removed in future versions. Use `root` instead.
4
+ */
3
5
  export declare const tooltip: string;
6
+ export declare const variables: void;
4
7
  export declare const positionFixed: string;
5
8
  export declare const show: string;
6
9
  export declare const hidden: string;
10
+ export declare const nonInteractive: string;
@@ -2,7 +2,27 @@ import { css, injectGlobal } from '@emotion/css';
2
2
 
3
3
  const root = css `
4
4
  label: tooltip;
5
+ display: inline-block;
6
+ left: 0;
7
+ bottom: 0;
8
+ min-width: max-content;
9
+ position: absolute;
10
+ opacity: 0;
11
+ transition: opacity;
12
+ transition-duration: var(--vis-tooltip-transition-duration);
13
+ z-index: 999999;
14
+ padding: var(--vis-tooltip-padding);
15
+ color: var(--vis-tooltip-text-color);
16
+ border-radius: var(--vis-tooltip-border-radius);
17
+ box-shadow: var(--vis-tooltip-box-shadow);
18
+ border: solid 1px var(--vis-tooltip-border-color);
19
+ background-color: var(--vis-tooltip-background-color);
20
+ backdrop-filter: var(--vis-tooltip-backdrop-filter);
5
21
  `;
22
+ /**
23
+ * @deprecated This selector is deprecated and will be removed in future versions. Use `root` instead.
24
+ */
25
+ const tooltip = root;
6
26
  const variables = injectGlobal `
7
27
  :root {
8
28
  --vis-tooltip-background-color: rgba(255, 255, 255, 0.95);
@@ -11,6 +31,9 @@ const variables = injectGlobal `
11
31
  --vis-tooltip-shadow-color: rgba(172, 179, 184, 0.35);
12
32
  --vis-tooltip-backdrop-filter: none;
13
33
  --vis-tooltip-padding: 10px 15px;
34
+ --vis-tooltip-border-radius: 5px;
35
+ --vis-tooltip-transition-duration: 300ms;
36
+ --vis-tooltip-box-shadow: none;
14
37
 
15
38
  --vis-dark-tooltip-background-color: rgba(30,30,30, 0.95);
16
39
  --vis-dark-tooltip-text-color: #e5e9f7;
@@ -32,30 +55,6 @@ const variables = injectGlobal `
32
55
  --vis-tooltip-shadow-color: rgba(0,0,0, 0.95);
33
56
  }
34
57
  `;
35
- const tooltip = css `
36
- label: tooltip;
37
- display: inline-block;
38
- left: 0;
39
- bottom: 0;
40
- min-width: max-content;
41
- position: absolute;
42
- pointer-events: none;
43
- opacity: 0;
44
- transition: opacity;
45
- transition-duration: 300ms;
46
- user-select: none;
47
- z-index: 999999;
48
- padding: var(--vis-tooltip-padding);
49
- transform: translate(0, -5px);
50
- color: var(--vis-tooltip-text-color);
51
-
52
- /* object-fit: contain; */
53
- border-radius: 5px;
54
- box-shadow: 0 13px 25px 0 var(--vis-tooltip-box-shadow);
55
- border: solid 1px var(--vis-tooltip-border-color);
56
- background-color: var(--vis-tooltip-background-color);
57
- backdrop-filter: var(--vis-tooltip-backdrop-filter);
58
- `;
59
58
  const positionFixed = css `
60
59
  bottom: unset;
61
60
  position: fixed;
@@ -65,7 +64,12 @@ const show = css `
65
64
  `;
66
65
  const hidden = css `
67
66
  display: none;
67
+ `;
68
+ const nonInteractive = css `
69
+ label: non-interactive;
70
+ pointer-events: none;
71
+ user-select: none;
68
72
  `;
69
73
 
70
- export { hidden, positionFixed, root, show, tooltip, variables };
74
+ export { hidden, nonInteractive, positionFixed, root, show, tooltip, variables };
71
75
  //# sourceMappingURL=style.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style.js","sources":["../../../src/components/tooltip/style.ts"],"sourcesContent":["import { css, injectGlobal } from '@emotion/css'\n\nexport const root = css`\n label: tooltip;\n`\n\nexport const variables = injectGlobal`\n :root {\n --vis-tooltip-background-color: rgba(255, 255, 255, 0.95);\n --vis-tooltip-border-color: #e5e9f7;\n --vis-tooltip-text-color: #000;\n --vis-tooltip-shadow-color: rgba(172, 179, 184, 0.35);\n --vis-tooltip-backdrop-filter: none;\n --vis-tooltip-padding: 10px 15px;\n\n --vis-dark-tooltip-background-color: rgba(30,30,30, 0.95);\n --vis-dark-tooltip-text-color: #e5e9f7;\n --vis-dark-tooltip-border-color: var(--vis-color-grey);\n --vis-dark-tooltip-shadow-color: rgba(0,0,0, 0.95);\n }\n\n body.theme-dark ${`.${root}`} {\n --vis-tooltip-background-color: var(--vis-dark-tooltip-background-color);\n --vis-tooltip-text-color: var(--vis-dark-tooltip-text-color);\n --vis-tooltip-border-color: var(--vis-dark-tooltip-border-color);\n --vis-tooltip-shadow-color: var(--vis-dark-tooltip-shadow-color);\n }\n\n body.theme-dark {\n --vis-tooltip-background-color: rgba(30,30,30, 0.95);\n --vis-tooltip-text-color: #e5e9f7;\n --vis-tooltip-border-color: var(--vis-color-grey);\n --vis-tooltip-shadow-color: rgba(0,0,0, 0.95);\n }\n`\n\nexport const tooltip = css`\n label: tooltip;\n display: inline-block;\n left: 0;\n bottom: 0;\n min-width: max-content;\n position: absolute;\n pointer-events: none;\n opacity: 0;\n transition: opacity;\n transition-duration: 300ms;\n user-select: none;\n z-index: 999999;\n padding: var(--vis-tooltip-padding);\n transform: translate(0, -5px);\n color: var(--vis-tooltip-text-color);\n\n /* object-fit: contain; */\n border-radius: 5px;\n box-shadow: 0 13px 25px 0 var(--vis-tooltip-box-shadow);\n border: solid 1px var(--vis-tooltip-border-color);\n background-color: var(--vis-tooltip-background-color);\n backdrop-filter: var(--vis-tooltip-backdrop-filter);\n`\n\nexport const positionFixed = css`\n bottom: unset;\n position: fixed;\n`\n\nexport const show = css`\n opacity: 1;\n`\n\nexport const hidden = css`\n display: none;\n`\n"],"names":[],"mappings":";;AAEO,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;EAEtB;AAEM,MAAM,SAAS,GAAG,YAAY,CAAA,CAAA;;;;;;;;;;;;;;;AAejB,kBAAA,EAAA,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA,CAAA;;;;;;;;;;;;;EAa7B;AAEM,MAAM,OAAO,GAAG,GAAG,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBzB;AAEM,MAAM,aAAa,GAAG,GAAG,CAAA,CAAA;;;EAG/B;AAEM,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;EAEtB;AAEM,MAAM,MAAM,GAAG,GAAG,CAAA,CAAA;;;;;;"}
1
+ {"version":3,"file":"style.js","sources":["../../../src/components/tooltip/style.ts"],"sourcesContent":["import { css, injectGlobal } from '@emotion/css'\n\nexport const root = css`\n label: tooltip;\n display: inline-block;\n left: 0;\n bottom: 0;\n min-width: max-content;\n position: absolute;\n opacity: 0;\n transition: opacity;\n transition-duration: var(--vis-tooltip-transition-duration);\n z-index: 999999;\n padding: var(--vis-tooltip-padding);\n color: var(--vis-tooltip-text-color);\n border-radius: var(--vis-tooltip-border-radius);\n box-shadow: var(--vis-tooltip-box-shadow);\n border: solid 1px var(--vis-tooltip-border-color);\n background-color: var(--vis-tooltip-background-color);\n backdrop-filter: var(--vis-tooltip-backdrop-filter);\n`\n\n/**\n * @deprecated This selector is deprecated and will be removed in future versions. Use `root` instead.\n */\nexport const tooltip = root\n\nexport const variables = injectGlobal`\n :root {\n --vis-tooltip-background-color: rgba(255, 255, 255, 0.95);\n --vis-tooltip-border-color: #e5e9f7;\n --vis-tooltip-text-color: #000;\n --vis-tooltip-shadow-color: rgba(172, 179, 184, 0.35);\n --vis-tooltip-backdrop-filter: none;\n --vis-tooltip-padding: 10px 15px;\n --vis-tooltip-border-radius: 5px;\n --vis-tooltip-transition-duration: 300ms;\n --vis-tooltip-box-shadow: none;\n\n --vis-dark-tooltip-background-color: rgba(30,30,30, 0.95);\n --vis-dark-tooltip-text-color: #e5e9f7;\n --vis-dark-tooltip-border-color: var(--vis-color-grey);\n --vis-dark-tooltip-shadow-color: rgba(0,0,0, 0.95);\n }\n\n body.theme-dark ${`.${root}`} {\n --vis-tooltip-background-color: var(--vis-dark-tooltip-background-color);\n --vis-tooltip-text-color: var(--vis-dark-tooltip-text-color);\n --vis-tooltip-border-color: var(--vis-dark-tooltip-border-color);\n --vis-tooltip-shadow-color: var(--vis-dark-tooltip-shadow-color);\n }\n\n body.theme-dark {\n --vis-tooltip-background-color: rgba(30,30,30, 0.95);\n --vis-tooltip-text-color: #e5e9f7;\n --vis-tooltip-border-color: var(--vis-color-grey);\n --vis-tooltip-shadow-color: rgba(0,0,0, 0.95);\n }\n`\n\nexport const positionFixed = css`\n bottom: unset;\n position: fixed;\n`\n\nexport const show = css`\n opacity: 1;\n`\n\nexport const hidden = css`\n display: none;\n`\n\nexport const nonInteractive = css`\n label: non-interactive;\n pointer-events: none;\n user-select: none;\n`\n"],"names":[],"mappings":";;AAEO,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;;;;;;;;;;;;;;;;;EAkBtB;AAED;;AAEG;AACI,MAAM,OAAO,GAAG,KAAI;AAEpB,MAAM,SAAS,GAAG,YAAY,CAAA,CAAA;;;;;;;;;;;;;;;;;;AAkBjB,kBAAA,EAAA,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA,CAAA;;;;;;;;;;;;;EAa7B;AAEM,MAAM,aAAa,GAAG,GAAG,CAAA,CAAA;;;EAG/B;AAEM,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;EAEtB;AAEM,MAAM,MAAM,GAAG,GAAG,CAAA,CAAA;;EAExB;AAEM,MAAM,cAAc,GAAG,GAAG,CAAA,CAAA;;;;;;;;"}
@@ -8,8 +8,8 @@ export declare class ComponentCore<CoreDatum, ConfigInterface extends ComponentC
8
8
  element: SVGGElement | HTMLElement;
9
9
  type: ComponentType;
10
10
  g: Selection<SVGGElement, unknown, null, undefined> | Selection<HTMLElement, unknown, null, undefined>;
11
- config: ConfigInterface;
12
- prevConfig: ConfigInterface;
11
+ config: ComponentConfigInterface;
12
+ prevConfig: ComponentConfigInterface;
13
13
  datamodel: CoreDataModel<CoreDatum>;
14
14
  sizing: Sizing | string;
15
15
  uid: string;
@@ -19,7 +19,7 @@ export declare class ComponentCore<CoreDatum, ConfigInterface extends ComponentC
19
19
  };
20
20
  };
21
21
  /** Default configuration */
22
- protected _defaultConfig: ConfigInterface;
22
+ protected _defaultConfig: ComponentConfigInterface;
23
23
  /** Component width in pixels. This property is set automatically by the container. */
24
24
  protected _width: number;
25
25
  /** Component height in pixels. This property is set automatically by the container. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/core/component/index.ts"],"sourcesContent":["import { select, Selection, ValueFn } from 'd3-selection'\nimport { Transition } from 'd3-transition'\n\n// Core\nimport { CoreDataModel } from 'data-models/core'\n\n// Utils\nimport { merge, throttle } from 'utils/data'\nimport { guid } from 'utils/misc'\n\n// Types\nimport { ComponentType, Sizing } from 'types/component'\nimport { Spacing } from 'types/spacing'\n\n// Local Types\nimport { VisEventCallback, VisEventType } from './types'\n\n// Config\nimport { ComponentDefaultConfig, ComponentConfigInterface } from './config'\n\nexport class ComponentCore<\n CoreDatum,\n ConfigInterface extends ComponentConfigInterface = ComponentConfigInterface,\n> {\n public element: SVGGElement | HTMLElement\n public type: ComponentType = ComponentType.SVG\n public g: Selection<SVGGElement, unknown, null, undefined> | Selection<HTMLElement, unknown, null, undefined>\n public config: ConfigInterface\n public prevConfig: ConfigInterface\n public datamodel: CoreDataModel<CoreDatum> = new CoreDataModel()\n public sizing: Sizing | string = Sizing.Fit // Supported by SingleContainer and a subset of components only (Sankey)\n public uid: string\n\n protected events: {\n [selector: string]: {\n [eventType in VisEventType]?: VisEventCallback;\n };\n } = {}\n\n /** Default configuration */\n protected _defaultConfig: ConfigInterface = ComponentDefaultConfig as ConfigInterface\n /** Component width in pixels. This property is set automatically by the container. */\n protected _width = 400\n /** Component height in pixels. This property is set automatically by the container. */\n protected _height = 200\n /** Container width in pixels. This property is set automatically by the container. */\n protected _containerWidth: number | undefined = undefined\n /** Container height in pixels. This property is set automatically by the container. */\n protected _containerHeight: number | undefined = undefined\n\n _setUpComponentEventsThrottled = throttle(this._setUpComponentEvents, 500)\n _setCustomAttributesThrottled = throttle(this._setCustomAttributes, 500)\n\n constructor (type = ComponentType.SVG) {\n if (type === ComponentType.SVG) {\n this.element = document.createElementNS('http://www.w3.org/2000/svg', 'g')\n } else {\n this.element = document.createElement('div')\n }\n this.uid = guid()\n this.g = select(this.element) as Selection<SVGGElement, unknown, null, undefined> | Selection<HTMLElement, unknown, null, undefined>\n\n // Setting the root class if available\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line dot-notation\n const rootClass = this.constructor?.['selectors']?.root as string\n if (rootClass) this.g.attr('class', rootClass)\n }\n\n setConfig (config: ConfigInterface): void {\n this.prevConfig = this.config // Store the previous config instance\n this.config = merge(this._defaultConfig, config)\n }\n\n setData (data: CoreDatum): void {\n this.datamodel.data = data\n }\n\n setSize (width: number, height: number, containerWidth: number, containerHeight: number): void {\n if (isFinite(width)) this._width = width\n if (isFinite(height)) this._height = height\n if (isFinite(containerWidth)) this._containerWidth = containerWidth\n if (isFinite(containerHeight)) this._containerHeight = containerHeight\n }\n\n render (duration = this.config.duration): void {\n this._render(duration)\n\n // While transition is in progress, we add the 'animating' attribute to the component's SVG group\n const ANIMATING_ATTR = 'animating'\n if (duration) {\n this.g.attr(ANIMATING_ATTR, '')\n const transition = this.g\n .transition(ANIMATING_ATTR)\n .duration(duration) as Transition<SVGGElement | HTMLElement, unknown, null, undefined>\n\n transition.on('end interrupt', () => {\n this.g.attr(ANIMATING_ATTR, null)\n })\n }\n this._setUpComponentEventsThrottled()\n this._setCustomAttributesThrottled()\n }\n\n get bleed (): Spacing {\n return { top: 0, bottom: 0, left: 0, right: 0 }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n _render (duration = this.config.duration): void {\n }\n\n private _setCustomAttributes (): void {\n const attributeMap = this.config.attributes\n\n Object.keys(attributeMap).forEach(className => {\n Object.keys(attributeMap[className]).forEach(attr => {\n const selection = (this.g as Selection<SVGGElement | HTMLElement, unknown, null, undefined>)\n .selectAll<SVGGElement | HTMLElement, unknown>(`.${className}`)\n\n selection.attr(attr, attributeMap[className][attr] as ValueFn<SVGGElement | HTMLElement, unknown, string | number | boolean>)\n })\n })\n }\n\n private _setUpComponentEvents (): void {\n // Set up default events\n this._bindEvents(this.events)\n\n // Set up user-defined events\n this._bindEvents(this.config.events, '.user')\n }\n\n private _bindEvents (events = this.events, suffix = ''): void {\n Object.keys(events).forEach(className => {\n Object.keys(events[className]).forEach(eventType => {\n const selection = (this.g as Selection<SVGGElement | HTMLElement, unknown, null, undefined>)\n .selectAll<SVGGElement | HTMLElement, unknown>(`.${className}`)\n selection.on(eventType + suffix, (event: MouseEvent & WheelEvent & PointerEvent & TouchEvent, d) => {\n const els = selection.nodes()\n const i = els.indexOf(event.currentTarget as SVGGElement | HTMLElement)\n const eventFunction = events[className][eventType as VisEventType]\n return eventFunction?.(d, event, i, els)\n })\n })\n })\n }\n\n public destroy (): void {\n this.g?.remove()\n this.element = undefined\n }\n\n public isDestroyed (): boolean {\n return !this.element\n }\n}\n"],"names":[],"mappings":";;;;;;;MAoBa,aAAa,CAAA;AAiCxB,IAAA,WAAA,CAAa,IAAI,GAAG,aAAa,CAAC,GA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KACrB;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/core/component/index.ts"],"sourcesContent":["import { select, Selection, ValueFn } from 'd3-selection'\nimport { Transition } from 'd3-transition'\n\n// Core\nimport { CoreDataModel } from 'data-models/core'\n\n// Utils\nimport { merge, throttle } from 'utils/data'\nimport { guid } from 'utils/misc'\n\n// Types\nimport { ComponentType, Sizing } from 'types/component'\nimport { Spacing } from 'types/spacing'\n\n// Local Types\nimport { VisEventCallback, VisEventType } from './types'\n\n// Config\nimport { ComponentDefaultConfig, ComponentConfigInterface } from './config'\n\nexport class ComponentCore<\n CoreDatum,\n ConfigInterface extends ComponentConfigInterface = ComponentConfigInterface,\n> {\n public element: SVGGElement | HTMLElement\n public type: ComponentType = ComponentType.SVG\n public g: Selection<SVGGElement, unknown, null, undefined> | Selection<HTMLElement, unknown, null, undefined>\n public config: ComponentConfigInterface\n public prevConfig: ComponentConfigInterface\n public datamodel: CoreDataModel<CoreDatum> = new CoreDataModel()\n public sizing: Sizing | string = Sizing.Fit // Supported by SingleContainer and a subset of components only (Sankey)\n public uid: string\n\n protected events: {\n [selector: string]: {\n [eventType in VisEventType]?: VisEventCallback;\n };\n } = {}\n\n /** Default configuration */\n protected _defaultConfig: ComponentConfigInterface = ComponentDefaultConfig\n /** Component width in pixels. This property is set automatically by the container. */\n protected _width = 400\n /** Component height in pixels. This property is set automatically by the container. */\n protected _height = 200\n /** Container width in pixels. This property is set automatically by the container. */\n protected _containerWidth: number | undefined = undefined\n /** Container height in pixels. This property is set automatically by the container. */\n protected _containerHeight: number | undefined = undefined\n\n _setUpComponentEventsThrottled = throttle(this._setUpComponentEvents, 500)\n _setCustomAttributesThrottled = throttle(this._setCustomAttributes, 500)\n\n constructor (type = ComponentType.SVG) {\n if (type === ComponentType.SVG) {\n this.element = document.createElementNS('http://www.w3.org/2000/svg', 'g')\n } else {\n this.element = document.createElement('div')\n }\n this.uid = guid()\n this.g = select(this.element) as Selection<SVGGElement, unknown, null, undefined> | Selection<HTMLElement, unknown, null, undefined>\n\n // Setting the root class if available\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line dot-notation\n const rootClass = this.constructor?.['selectors']?.root as string\n if (rootClass) this.g.attr('class', rootClass)\n }\n\n setConfig (config: ConfigInterface): void {\n this.prevConfig = this.config // Store the previous config instance\n this.config = merge(this._defaultConfig, config)\n }\n\n setData (data: CoreDatum): void {\n this.datamodel.data = data\n }\n\n setSize (width: number, height: number, containerWidth: number, containerHeight: number): void {\n if (isFinite(width)) this._width = width\n if (isFinite(height)) this._height = height\n if (isFinite(containerWidth)) this._containerWidth = containerWidth\n if (isFinite(containerHeight)) this._containerHeight = containerHeight\n }\n\n render (duration = this.config.duration): void {\n this._render(duration)\n\n // While transition is in progress, we add the 'animating' attribute to the component's SVG group\n const ANIMATING_ATTR = 'animating'\n if (duration) {\n this.g.attr(ANIMATING_ATTR, '')\n const transition = this.g\n .transition(ANIMATING_ATTR)\n .duration(duration) as Transition<SVGGElement | HTMLElement, unknown, null, undefined>\n\n transition.on('end interrupt', () => {\n this.g.attr(ANIMATING_ATTR, null)\n })\n }\n this._setUpComponentEventsThrottled()\n this._setCustomAttributesThrottled()\n }\n\n get bleed (): Spacing {\n return { top: 0, bottom: 0, left: 0, right: 0 }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n _render (duration = this.config.duration): void {\n }\n\n private _setCustomAttributes (): void {\n const attributeMap = this.config.attributes\n\n Object.keys(attributeMap).forEach(className => {\n Object.keys(attributeMap[className]).forEach(attr => {\n const selection = (this.g as Selection<SVGGElement | HTMLElement, unknown, null, undefined>)\n .selectAll<SVGGElement | HTMLElement, unknown>(`.${className}`)\n\n selection.attr(attr, attributeMap[className][attr] as ValueFn<SVGGElement | HTMLElement, unknown, string | number | boolean>)\n })\n })\n }\n\n private _setUpComponentEvents (): void {\n // Set up default events\n this._bindEvents(this.events)\n\n // Set up user-defined events\n this._bindEvents(this.config.events, '.user')\n }\n\n private _bindEvents (events = this.events, suffix = ''): void {\n Object.keys(events).forEach(className => {\n Object.keys(events[className]).forEach(eventType => {\n const selection = (this.g as Selection<SVGGElement | HTMLElement, unknown, null, undefined>)\n .selectAll<SVGGElement | HTMLElement, unknown>(`.${className}`)\n selection.on(eventType + suffix, (event: MouseEvent & WheelEvent & PointerEvent & TouchEvent, d) => {\n const els = selection.nodes()\n const i = els.indexOf(event.currentTarget as SVGGElement | HTMLElement)\n const eventFunction = events[className][eventType as VisEventType]\n return eventFunction?.(d, event, i, els)\n })\n })\n })\n }\n\n public destroy (): void {\n this.g?.remove()\n this.element = undefined\n }\n\n public isDestroyed (): boolean {\n return !this.element\n }\n}\n"],"names":[],"mappings":";;;;;;;MAoBa,aAAa,CAAA;AAiCxB,IAAA,WAAA,CAAa,IAAI,GAAG,aAAa,CAAC,GAAG,EAAA;;AA5B9B,QAAA,IAAA,CAAA,IAAI,GAAkB,aAAa,CAAC,GAAG,CAAA;AAIvC,QAAA,IAAA,CAAA,SAAS,GAA6B,IAAI,aAAa,EAAE,CAAA;AACzD,QAAA,IAAA,CAAA,MAAM,GAAoB,MAAM,CAAC,GAAG,CAAA;QAGjC,IAAM,CAAA,MAAA,GAIZ,EAAE,CAAA;;QAGI,IAAc,CAAA,cAAA,GAA6B,sBAAsB,CAAA;;QAEjE,IAAM,CAAA,MAAA,GAAG,GAAG,CAAA;;QAEZ,IAAO,CAAA,OAAA,GAAG,GAAG,CAAA;;QAEb,IAAe,CAAA,eAAA,GAAuB,SAAS,CAAA;;QAE/C,IAAgB,CAAA,gBAAA,GAAuB,SAAS,CAAA;QAE1D,IAA8B,CAAA,8BAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;QAC1E,IAA6B,CAAA,6BAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;AAGtE,QAAA,IAAI,IAAI,KAAK,aAAa,CAAC,GAAG,EAA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AA;AAClE,oBAAA,OAAO,aAAa,KAAA,IAAA,IAAb,aAAa,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAb,aAAa,CAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAC1C,iBAAC,CAAC,CAAA;AACJ,aAAC,CAAC,CAAA;AACJ,SAAC,CAAC,CAAA;KACH;IAEM,OAAO,GAAA;;AACZ,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,CAAC,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,EAAE,CAAA;AAChB,QAAA,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;KACzB;IAEM,WAAW,GAAA;AAChB,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;KACrB;AACF;;;;"}
@@ -38,7 +38,7 @@ class ContainerCore {
38
38
  _render(duration) {
39
39
  const { config, prevConfig } = this;
40
40
  // Add `svgDefs` if provided in the config
41
- if (config.svgDefs !== prevConfig.svgDefs) {
41
+ if (config.svgDefs !== (prevConfig === null || prevConfig === void 0 ? void 0 : prevConfig.svgDefs)) {
42
42
  this._svgDefsExternal.selectAll('*').remove();
43
43
  this._svgDefsExternal.html(config.svgDefs);
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/core/container/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Types\nimport { Sizing } from 'types/component'\n\n// Utils\nimport { isEqual, clamp, merge } from 'utils/data'\nimport { ResizeObserver } from 'utils/resize-observer'\n\n// Config\nimport { ContainerDefaultConfig, ContainerConfigInterface } from './config'\n\nexport class ContainerCore {\n public svg: Selection<SVGSVGElement, unknown, null, undefined>\n public element: SVGSVGElement\n public prevConfig: ContainerConfigInterface\n public config: ContainerConfigInterface\n\n protected _defaultConfig: ContainerConfigInterface = ContainerDefaultConfig\n protected _container: HTMLElement\n protected _requestedAnimationFrame: number\n protected _isFirstRender = true\n protected _resizeObserver: ResizeObserver | undefined\n protected _svgDefs: Selection<SVGDefsElement, unknown, null, undefined>\n protected _svgDefsExternal: Selection<SVGDefsElement, unknown, null, undefined>\n private _containerSize: { width: number; height: number }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static DEFAULT_CONTAINER_HEIGHT = 300\n\n constructor (element: HTMLElement) {\n this._requestedAnimationFrame = null\n this._container = element\n\n // Setting `role` attribute to `image` to make the container accessible\n const container = select(this._container)\n container.attr('role', 'figure')\n\n // Create SVG element for visualizations\n this.svg = container.append('svg')\n // We set `display` to `block` because inline elements have an invisible\n // inline space that adds 4px to the height of the container\n .style('display', 'block')\n .attr('xmlns', 'http://www.w3.org/2000/svg')\n .attr('height', ContainerCore.DEFAULT_CONTAINER_HEIGHT) // Overriding default SVG height of 150\n .attr('aria-hidden', true)\n\n this._svgDefs = this.svg.append('defs')\n this._svgDefsExternal = this.svg.append('defs')\n this.element = this.svg.node()\n }\n\n public updateContainer<T extends ContainerConfigInterface> (config: T): void {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n }\n\n // The `_preRender` step should be used to perform some actions before rendering.\n // For example, calculating scales, setting component sizes, etc ...\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n protected _preRender (): void {}\n\n // The `_render` step should be used to perform the actual rendering\n protected _render (duration?: number): void {\n const { config, prevConfig } = this\n\n // Add `svgDefs` if provided in the config\n if (config.svgDefs !== prevConfig.svgDefs) {\n this._svgDefsExternal.selectAll('*').remove()\n this._svgDefsExternal.html(config.svgDefs)\n }\n\n // Apply the `aria-label` attribute\n select(this._container)\n .attr('aria-label', config.ariaLabel)\n\n this._isFirstRender = false\n }\n\n // Warning: Some Containers (i.e. Single Container) may override this method, so if you introduce any changes here,\n // make sure to check that other containers didn't break after them.\n public render (duration = this.config.duration): void {\n const width = this.config.width || this.containerWidth\n const height = this.config.height || this.containerHeight\n\n // We set SVG size in `render()` instead of `_render()`, because the size values in pixels will become\n // available only in the next animation when being accessed via `element.clientWidth` and `element.clientHeight`,\n // and we rely on those values when setting width and size of the components.\n this.svg\n .attr('width', width)\n .attr('height', height)\n\n // Set up Resize Observer. We do it in `render()` to capture container size change if it happened\n // in the next animation frame after the initial `render` was called.\n if (!this._resizeObserver) this._setUpResizeObserver()\n\n // Schedule the actual rendering in the next frame\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._requestedAnimationFrame = requestAnimationFrame(() => {\n this._preRender()\n this._render(duration)\n })\n }\n\n get containerWidth (): number {\n return this.config.width\n ? this.element.clientWidth\n : (this._container.clientWidth || this._container.getBoundingClientRect().width)\n }\n\n get containerHeight (): number {\n return this.config.height\n ? this.element.clientHeight\n : (this._container.clientHeight || this._container.getBoundingClientRect().height || ContainerCore.DEFAULT_CONTAINER_HEIGHT)\n }\n\n get width (): number {\n return clamp(this.containerWidth - this.config.margin.left - this.config.margin.right, 0, Number.POSITIVE_INFINITY)\n }\n\n get height (): number {\n return clamp(this.containerHeight - this.config.margin.top - this.config.margin.bottom, 0, Number.POSITIVE_INFINITY)\n }\n\n protected _removeAllChildren (): void {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild)\n }\n }\n\n protected _onResize (): void {\n const { config } = this\n const redrawOnResize = config.sizing === Sizing.Fit || config.sizing === Sizing.FitWidth\n if (redrawOnResize) this.render(0)\n }\n\n protected _setUpResizeObserver (): void {\n if (this._resizeObserver) return\n const containerRect = this._container.getBoundingClientRect()\n this._containerSize = { width: containerRect.width, height: containerRect.height }\n\n this._resizeObserver = new ResizeObserver((entries, observer) => {\n const resizedContainerRect = this._container.getBoundingClientRect()\n const resizedContainerSize = { width: resizedContainerRect.width, height: resizedContainerRect.height }\n const hasSizeChanged = !isEqual(this._containerSize, resizedContainerSize)\n // Do resize only if element is attached to the DOM\n // will come in useful when some ancestor of container becomes detached\n if (hasSizeChanged && resizedContainerSize.width && resizedContainerSize.height) {\n this._containerSize = resizedContainerSize\n this._onResize()\n }\n })\n this._resizeObserver.observe(this._container)\n }\n\n public destroy (): void {\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._resizeObserver?.disconnect()\n this.svg.remove()\n }\n}\n"],"names":[],"mappings":";;;;;;MAYa,aAAa,CAAA;AAkBxB,IAAA,WAAA,CAAa,OAAoB,EAAA;QAZvB,IAAc,CAAA,cAAA,GAA6B,sBAAsB,CAAA;QAGjE,IAAc,CAAA,cAAA,GAAG,IAAI,CAAA;AAU7B,QAAA,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAA;AACpC,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;;QAGzB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACzC,QAAA,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;;QAGhC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;;;AAG/B,aAAA,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC;AACzB,aAAA,IAAI,CAAC,OAAO,EAAE,4BAA4B,CAAC;aAC3C,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC;AACtD,aAAA,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAE5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;KAC/B;AAEM,IAAA,eAAe,CAAsC,MAAS,EAAA;;AAEnE,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC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AAA,IAAI,CAAC,eAAe,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAU,EAAE,CAAA;AAClC,QAAA,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;KAClB;;AArID;AACO,aAAwB,CAAA,wBAAA,GAAG,GAAG;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/core/container/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Types\nimport { Sizing } from 'types/component'\n\n// Utils\nimport { isEqual, clamp, merge } from 'utils/data'\nimport { ResizeObserver } from 'utils/resize-observer'\n\n// Config\nimport { ContainerDefaultConfig, ContainerConfigInterface } from './config'\n\nexport class ContainerCore {\n public svg: Selection<SVGSVGElement, unknown, null, undefined>\n public element: SVGSVGElement\n public prevConfig: ContainerConfigInterface\n public config: ContainerConfigInterface\n\n protected _defaultConfig: ContainerConfigInterface = ContainerDefaultConfig\n protected _container: HTMLElement\n protected _requestedAnimationFrame: number\n protected _isFirstRender = true\n protected _resizeObserver: ResizeObserver | undefined\n protected _svgDefs: Selection<SVGDefsElement, unknown, null, undefined>\n protected _svgDefsExternal: Selection<SVGDefsElement, unknown, null, undefined>\n private _containerSize: { width: number; height: number }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static DEFAULT_CONTAINER_HEIGHT = 300\n\n constructor (element: HTMLElement) {\n this._requestedAnimationFrame = null\n this._container = element\n\n // Setting `role` attribute to `image` to make the container accessible\n const container = select(this._container)\n container.attr('role', 'figure')\n\n // Create SVG element for visualizations\n this.svg = container.append('svg')\n // We set `display` to `block` because inline elements have an invisible\n // inline space that adds 4px to the height of the container\n .style('display', 'block')\n .attr('xmlns', 'http://www.w3.org/2000/svg')\n .attr('height', ContainerCore.DEFAULT_CONTAINER_HEIGHT) // Overriding default SVG height of 150\n .attr('aria-hidden', true)\n\n this._svgDefs = this.svg.append('defs')\n this._svgDefsExternal = this.svg.append('defs')\n this.element = this.svg.node()\n }\n\n public updateContainer<T extends ContainerConfigInterface> (config: T): void {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n }\n\n // The `_preRender` step should be used to perform some actions before rendering.\n // For example, calculating scales, setting component sizes, etc ...\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n protected _preRender (): void {}\n\n // The `_render` step should be used to perform the actual rendering\n protected _render (duration?: number): void {\n const { config, prevConfig } = this\n\n // Add `svgDefs` if provided in the config\n if (config.svgDefs !== prevConfig?.svgDefs) {\n this._svgDefsExternal.selectAll('*').remove()\n this._svgDefsExternal.html(config.svgDefs)\n }\n\n // Apply the `aria-label` attribute\n select(this._container)\n .attr('aria-label', config.ariaLabel)\n\n this._isFirstRender = false\n }\n\n // Warning: Some Containers (i.e. Single Container) may override this method, so if you introduce any changes here,\n // make sure to check that other containers didn't break after them.\n public render (duration = this.config.duration): void {\n const width = this.config.width || this.containerWidth\n const height = this.config.height || this.containerHeight\n\n // We set SVG size in `render()` instead of `_render()`, because the size values in pixels will become\n // available only in the next animation when being accessed via `element.clientWidth` and `element.clientHeight`,\n // and we rely on those values when setting width and size of the components.\n this.svg\n .attr('width', width)\n .attr('height', height)\n\n // Set up Resize Observer. We do it in `render()` to capture container size change if it happened\n // in the next animation frame after the initial `render` was called.\n if (!this._resizeObserver) this._setUpResizeObserver()\n\n // Schedule the actual rendering in the next frame\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._requestedAnimationFrame = requestAnimationFrame(() => {\n this._preRender()\n this._render(duration)\n })\n }\n\n get containerWidth (): number {\n return this.config.width\n ? this.element.clientWidth\n : (this._container.clientWidth || this._container.getBoundingClientRect().width)\n }\n\n get containerHeight (): number {\n return this.config.height\n ? this.element.clientHeight\n : (this._container.clientHeight || this._container.getBoundingClientRect().height || ContainerCore.DEFAULT_CONTAINER_HEIGHT)\n }\n\n get width (): number {\n return clamp(this.containerWidth - this.config.margin.left - this.config.margin.right, 0, Number.POSITIVE_INFINITY)\n }\n\n get height (): number {\n return clamp(this.containerHeight - this.config.margin.top - this.config.margin.bottom, 0, Number.POSITIVE_INFINITY)\n }\n\n protected _removeAllChildren (): void {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild)\n }\n }\n\n protected _onResize (): void {\n const { config } = this\n const redrawOnResize = config.sizing === Sizing.Fit || config.sizing === Sizing.FitWidth\n if (redrawOnResize) this.render(0)\n }\n\n protected _setUpResizeObserver (): void {\n if (this._resizeObserver) return\n const containerRect = this._container.getBoundingClientRect()\n this._containerSize = { width: containerRect.width, height: containerRect.height }\n\n this._resizeObserver = new ResizeObserver((entries, observer) => {\n const resizedContainerRect = this._container.getBoundingClientRect()\n const resizedContainerSize = { width: resizedContainerRect.width, height: resizedContainerRect.height }\n const hasSizeChanged = !isEqual(this._containerSize, resizedContainerSize)\n // Do resize only if element is attached to the DOM\n // will come in useful when some ancestor of container becomes detached\n if (hasSizeChanged && resizedContainerSize.width && resizedContainerSize.height) {\n this._containerSize = resizedContainerSize\n this._onResize()\n }\n })\n this._resizeObserver.observe(this._container)\n }\n\n public destroy (): void {\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._resizeObserver?.disconnect()\n this.svg.remove()\n }\n}\n"],"names":[],"mappings":";;;;;;MAYa,aAAa,CAAA;AAkBxB,IAAA,WAAA,CAAa,OAAoB,EAAA;QAZvB,IAAc,CAAA,cAAA,GAA6B,sBAAsB,CAAA;QAGjE,IAAc,CAAA,cAAA,GAAG,IAAI,CAAA;AAU7B,QAAA,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAA;AACpC,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;;QAGzB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACzC,QAAA,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;;QAGhC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,MAAM,CAA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AAI,cAAc,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAI;YAC9D,MAAM,oBAAoB,GAAG,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAA;AACpE,YAAA,MAAM,oBAAoB,GAAG,EAAE,KAAK,EAAE,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,oBAAoB,CAAC,MAAM,EAAE,CAAA;YACvG,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAA;;;YAG1E,IAAI,cAAc,IAAI,oBAAoB,CAAC,KAAK,IAAI,oBAAoB,CAAC,MAAM,EAAE;AAC/E,gBAAA,IAAI,CAAC,cAAc,GAAG,oBAAoB,CAAA;gBAC1C,IAAI,CAAC,SAAS,EAAE,CAAA;AACjB,aAAA;AACH,SAAC,CAAC,CAAA;QACF,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;KAC9C;IAEM,OAAO,GAAA;;AACZ,QAAA,oBAAoB,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;AACnD,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,eAAe,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAU,EAAE,CAAA;AAClC,QAAA,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;KAClB;;AArID;AACO,aAAwB,CAAA,wBAAA,GAAG,GAAG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unovis/ts",
3
3
  "description": "Modular data visualization framework for React, Angular, Svelte, and vanilla TypeScript or JavaScript",
4
- "version": "1.4.3",
4
+ "version": "1.4.4-beta.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/f5/unovis.git",