@unovis/ts 1.5.1-ql.2 → 1.5.1-ql.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/components/area/config.d.ts +7 -3
  3. package/components/area/config.js +1 -1
  4. package/components/area/config.js.map +1 -1
  5. package/components/area/index.js +26 -10
  6. package/components/area/index.js.map +1 -1
  7. package/components/axis/config.d.ts +1 -1
  8. package/components/axis/config.js.map +1 -1
  9. package/components/axis/index.js.map +1 -1
  10. package/components/chord-diagram/index.js +3 -1
  11. package/components/chord-diagram/index.js.map +1 -1
  12. package/components/donut/config.d.ts +4 -0
  13. package/components/donut/config.js +1 -1
  14. package/components/donut/config.js.map +1 -1
  15. package/components/donut/constants.d.ts +2 -0
  16. package/components/donut/constants.js +8 -0
  17. package/components/donut/constants.js.map +1 -0
  18. package/components/donut/index.js +35 -5
  19. package/components/donut/index.js.map +1 -1
  20. package/components/graph/config.d.ts +22 -1
  21. package/components/graph/config.js +5 -2
  22. package/components/graph/config.js.map +1 -1
  23. package/components/graph/index.d.ts +12 -9
  24. package/components/graph/index.js +33 -21
  25. package/components/graph/index.js.map +1 -1
  26. package/components/graph/modules/layout-helpers.js +1 -1
  27. package/components/graph/modules/layout-helpers.js.map +1 -1
  28. package/components/graph/modules/layout.js +1 -1
  29. package/components/graph/modules/layout.js.map +1 -1
  30. package/components/graph/modules/link/index.d.ts +3 -2
  31. package/components/graph/modules/link/index.js +45 -23
  32. package/components/graph/modules/link/index.js.map +1 -1
  33. package/components/graph/modules/link/style.js +0 -2
  34. package/components/graph/modules/link/style.js.map +1 -1
  35. package/components/graph/modules/node/index.d.ts +2 -0
  36. package/components/graph/modules/node/index.js +7 -4
  37. package/components/graph/modules/node/index.js.map +1 -1
  38. package/components/graph/modules/panel/index.js +2 -2
  39. package/components/graph/modules/panel/index.js.map +1 -1
  40. package/components/graph/types.d.ts +5 -0
  41. package/components/graph/types.js.map +1 -1
  42. package/components/line/config.d.ts +5 -0
  43. package/components/line/config.js +1 -1
  44. package/components/line/config.js.map +1 -1
  45. package/components/line/index.js +41 -2
  46. package/components/line/index.js.map +1 -1
  47. package/components/line/style.d.ts +1 -0
  48. package/components/line/style.js +12 -1
  49. package/components/line/style.js.map +1 -1
  50. package/components/line/types.d.ts +1 -0
  51. package/components/stacked-bar/index.js +7 -5
  52. package/components/stacked-bar/index.js.map +1 -1
  53. package/components/stacked-bar/types.d.ts +1 -1
  54. package/components/tooltip/config.d.ts +6 -4
  55. package/components/tooltip/config.js +3 -1
  56. package/components/tooltip/config.js.map +1 -1
  57. package/components/tooltip/index.d.ts +7 -3
  58. package/components/tooltip/index.js +39 -9
  59. package/components/tooltip/index.js.map +1 -1
  60. package/components.d.ts +1 -0
  61. package/components.js +1 -0
  62. package/components.js.map +1 -1
  63. package/data-models/graph.d.ts +3 -2
  64. package/data-models/graph.js +15 -6
  65. package/data-models/graph.js.map +1 -1
  66. package/data-models/index.d.ts +4 -0
  67. package/data-models/index.js +5 -0
  68. package/data-models/index.js.map +1 -0
  69. package/index.d.ts +1 -0
  70. package/index.js +6 -0
  71. package/index.js.map +1 -1
  72. package/package.json +5 -5
  73. package/types/data.d.ts +1 -2
  74. package/types/graph.d.ts +4 -0
  75. package/utils/data.d.ts +1 -1
  76. package/utils/data.js +9 -16
  77. package/utils/data.js.map +1 -1
  78. package/utils/text.d.ts +8 -8
  79. package/utils/text.js +16 -8
  80. package/utils/text.js.map +1 -1
@@ -59,7 +59,7 @@ class StackedBar extends XYComponentCore {
59
59
  const duration = isNumber(customDuration) ? customDuration : config.duration;
60
60
  const yAccessors = this.getAccessors();
61
61
  const stacked = getStackedData(this._barData, 0, yAccessors, this._prevNegative);
62
- this._prevNegative = stacked.map(s => !!s.negative);
62
+ this._prevNegative = stacked.map(s => !!s.isMostlyNegative);
63
63
  const barGroups = this.g
64
64
  .selectAll(`.${barGroup}`)
65
65
  .data(this._barData, (d, i) => { var _a; return `${(_a = getString(d, config.id, i)) !== null && _a !== void 0 ? _a : i}`; });
@@ -90,7 +90,10 @@ class StackedBar extends XYComponentCore {
90
90
  // Render Bars
91
91
  const bars = barGroupsMerged
92
92
  .selectAll(`.${bar}`)
93
- .data((d, j) => stacked.map((s) => (Object.assign(Object.assign({}, d), { _stacked: s[j], _negative: s.negative, _ending: s.ending }))));
93
+ .data((d, j) => stacked.map((s, stackIndex) => (Object.assign(Object.assign({}, d), { _index: j, _stacked: s[j],
94
+ // Ending bar if the next stack is not the same as the current one
95
+ _ending: (stackIndex === stacked.length - 1) ||
96
+ ((stackIndex <= stacked.length - 1) && stacked[stackIndex + 1][j][0] !== s[j][1]) }))));
94
97
  const barsEnter = bars.enter().append('path')
95
98
  .attr('class', bar)
96
99
  .attr('d', (d, j) => this._getBarPath(d, j, true))
@@ -150,10 +153,9 @@ class StackedBar extends XYComponentCore {
150
153
  const { config } = this;
151
154
  const yAccessors = this.getAccessors();
152
155
  const barWidth = this._getBarWidth();
153
- const isNegative = d._negative;
156
+ const isNegative = d._stacked[1] < 0;
154
157
  const isEnding = d._ending; // The most top bar or, if the value is negative, the most bottom bar
155
- // Todo: Find a way to pass the datum index to `getNumber` below
156
- const value = getNumber(d, yAccessors[accessorIndex]);
158
+ const value = getNumber(d, yAccessors[accessorIndex], d._index);
157
159
  const height = isEntering ? 0 : Math.abs(this.valueScale(d._stacked[0]) - this.valueScale(d._stacked[1]));
158
160
  const h = !isEntering && config.barMinHeight1Px && (height < 1) && isFinite(value) && (value !== config.barMinHeightZeroValue) ? 1 : height;
159
161
  const y = isEntering
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/stacked-bar/index.ts"],"sourcesContent":["import { min, max } from 'd3-array'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { isNumber, isArray, isEmpty, clamp, getStackedExtent, getString, getNumber, getStackedData, getExtent } from 'utils/data'\nimport { roundedRectPath } from 'utils/path'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { ContinuousScale } from 'types/scale'\nimport { NumericAccessor } from 'types/accessor'\nimport { Spacing } from 'types/spacing'\nimport { Orientation } from 'types/position'\n\n// Local Types\nimport { StackedBarDataRecord } from './types'\n\n// Config\nimport { StackedBarDefaultConfig, StackedBarConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class StackedBar<Datum> extends XYComponentCore<Datum, StackedBarConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = StackedBarDefaultConfig as StackedBarConfigInterface<Datum>\n public config: StackedBarConfigInterface<Datum> = this._defaultConfig\n\n getAccessors = (): NumericAccessor<Datum>[] => (isArray(this.config.y) ? this.config.y : [this.config.y])\n stacked = true\n events = {}\n private _prevNegative: boolean[] | undefined // To help guessing the bar direction when an accessor was set to null or 0\n private _barData: Datum[] = []\n\n constructor (config?: StackedBarConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n }\n\n get bleed (): Spacing {\n this._barData = this._getVisibleData()\n if (this._barData.length === 0) return { top: 0, bottom: 0, left: 0, right: 0 }\n\n // By default, horizontal orientation is \"flipped\", i.e. the `yDirection` of `XYContainer` is set to `Direction.North`\n const isHorizontalAndFlipped = !this.isVertical() && (this.dataScale.range()[0] > this.dataScale.range()[1])\n const dataDomain = this.dataScale.domain()\n const halfGroupWidth = this._getBarWidth() / 2\n\n const dataScaleValues = this._barData.map((d, i) => getNumber(d, this.config.x, i))\n const firstDataValue = min(dataScaleValues)\n const lastDataValue = max(dataScaleValues)\n const firstValuePx = this.dataScale(firstDataValue)\n const lastValuePx = this.dataScale(lastDataValue)\n\n const dataDomainRequiredStart = this.dataScale.invert(firstValuePx + (isHorizontalAndFlipped ? halfGroupWidth : -halfGroupWidth))\n const dataDomainRequiredEnd = this.dataScale.invert(lastValuePx + (isHorizontalAndFlipped ? -halfGroupWidth : halfGroupWidth))\n const bleedPxStart = dataDomainRequiredStart <= dataDomain[0] ? this.dataScale(dataDomain[0]) - this.dataScale(dataDomainRequiredStart) : 0\n const bleedPxEnd = dataDomainRequiredEnd > dataDomain[1] ? this.dataScale(dataDomainRequiredEnd) - this.dataScale(dataDomain[1]) : 0\n\n return {\n top: this.isVertical() ? 0 : (isHorizontalAndFlipped ? -bleedPxEnd : bleedPxStart),\n bottom: this.isVertical() ? 0 : (isHorizontalAndFlipped ? -bleedPxStart : bleedPxEnd),\n left: this.isVertical() ? bleedPxStart : 0,\n right: this.isVertical() ? bleedPxEnd : 0,\n }\n }\n\n private get dataScale (): ContinuousScale {\n return this.isVertical() ? this.xScale : this.yScale\n }\n\n private get valueScale (): ContinuousScale {\n return this.isVertical() ? this.yScale : this.xScale\n }\n\n private isVertical (): boolean {\n return this.config.orientation === Orientation.Vertical\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const yAccessors = this.getAccessors()\n const stacked = getStackedData(this._barData, 0, yAccessors, this._prevNegative)\n this._prevNegative = stacked.map(s => !!s.negative)\n\n const barGroups = this.g\n .selectAll<SVGGElement, Datum>(`.${s.barGroup}`)\n .data(this._barData, (d, i) => `${getString(d, config.id, i) ?? i}`)\n\n const getBarGroupsTransform = (d: Datum, i: number): string => {\n const v = this.dataScale(getNumber(d, config.x, i))\n const x = this.isVertical() ? v : 0\n const y = this.isVertical() ? 0 : v\n return `translate(${x},${y})`\n }\n\n const barGroupsEnter = barGroups.enter().append('g')\n .attr('class', s.barGroup)\n .attr('transform', getBarGroupsTransform)\n .style('opacity', 1)\n\n const barGroupsMerged = barGroupsEnter.merge(barGroups)\n smartTransition(barGroupsMerged, duration)\n .attr('transform', getBarGroupsTransform)\n .style('opacity', 1)\n\n const barGroupExit = barGroups.exit()\n .attr('class', s.barGroupExit)\n\n smartTransition(barGroupExit, duration)\n .style('opacity', 0)\n .remove()\n\n // Animate bars from exiting groups going down\n smartTransition(barGroupExit.selectAll(`.${s.bar}`), duration)\n .attr('transform', this.isVertical()\n ? `translate(0,${this._height / 3})`\n : `translate(${this._width / 6},0)`\n )\n\n // Render Bars\n const bars = barGroupsMerged\n .selectAll<SVGPathElement, StackedBarDataRecord<Datum>>(`.${s.bar}`)\n .data((d, j) => stacked.map((s) =>\n ({ ...d, _stacked: s[j], _negative: s.negative, _ending: s.ending }))\n )\n\n const barsEnter = bars.enter().append('path')\n .attr('class', s.bar)\n .attr('d', (d, j) => this._getBarPath(d, j, true))\n .style('fill', (d, j) => getColor(d, config.color, j))\n\n const barsMerged = barsEnter.merge(bars)\n\n smartTransition(barsMerged, duration)\n .attr('d', (d, j) => this._getBarPath(d, j))\n .style('fill', (d, j) => getColor(d, config.color, j))\n .style('cursor', (d, j) => getString(d, config.cursor, j))\n\n smartTransition(bars.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n _getBarWidth (): number {\n const { config, datamodel: { data } } = this\n if (isEmpty(data)) return 0\n if (config.barWidth) return min([config.barWidth, config.barMaxWidth])\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const isOrdinal = this.dataScale.bandwidth\n const domain = (this.dataScale.domain ? this.dataScale.domain() : []) as number[]\n const domainLength = isOrdinal ? domain.length : domain[1] - domain[0]\n\n // If the dataStep property is provided the amount of data elements is calculates as domainLength / dataStep\n // otherwise we get the number of data elements within the domain range\n // Or if the scale is ordinal we use data.length\n let dataSize = (1 + domainLength / config.dataStep) ||\n (!isOrdinal && data.filter((d, i) => {\n const value = getNumber(d, config.x, i)\n return (value >= domain[0]) && (value <= domain[1])\n }).length) ||\n data.length\n\n // We increase the dataSize by 1 to take into account possible additional domain space\n if (!isOrdinal && dataSize >= 2) dataSize += 1\n\n const c = dataSize < 2 ? 1 : 1 - config.barPadding\n const barWidth = c * (this.isVertical() ? this._width : this._height) / dataSize\n\n return min([barWidth, config.barMaxWidth])\n }\n\n _getVisibleData (): Datum[] {\n const { config, datamodel: { data } } = this\n\n const groupWidth = this._getBarWidth()\n const halfGroupWidthPx = data.length < 2 ? 0 : groupWidth / 2\n\n const scale = this.dataScale\n const halfGroupWidth = Math.abs((scale.invert(halfGroupWidthPx) as number) - (scale.invert(0) as number))\n const filtered = data?.filter((d, i) => {\n const v = getNumber(d, config.x, i)\n const domain: number[] | Date[] = scale.domain()\n const domainMin = +domain[0]\n const domainMax = +domain[1]\n return (v >= (domainMin - halfGroupWidth)) && (v <= (domainMax + halfGroupWidth))\n })\n\n return filtered\n }\n\n _getBarPath (d: StackedBarDataRecord<Datum>, accessorIndex: number, isEntering = false): string {\n const { config } = this\n const yAccessors = this.getAccessors()\n const barWidth = this._getBarWidth()\n\n const isNegative = d._negative\n const isEnding = d._ending // The most top bar or, if the value is negative, the most bottom bar\n // Todo: Find a way to pass the datum index to `getNumber` below\n const value = getNumber(d, yAccessors[accessorIndex])\n const height = isEntering ? 0 : Math.abs(this.valueScale(d._stacked[0]) - this.valueScale(d._stacked[1]))\n const h = !isEntering && config.barMinHeight1Px && (height < 1) && isFinite(value) && (value !== config.barMinHeightZeroValue) ? 1 : height\n const y = isEntering\n ? this.valueScale(0)\n : this.valueScale(isNegative ? d._stacked[0] : d._stacked[1]) - (height < 1 && config.barMinHeight1Px ? 1 : 0)\n\n const x = -barWidth / 2\n const width = barWidth\n\n const cornerRadius = config.roundedCorners\n ? isNumber(config.roundedCorners) ? +config.roundedCorners : width / 2\n : 0\n const cornerRadiusClamped = clamp(cornerRadius, 0, Math.min(height, width) / 2)\n const isNorthDirected = this.yScale.range()[0] > this.yScale.range()[1]\n\n return roundedRectPath({\n x: this.isVertical() ? x : y - h,\n y: this.isVertical() ? y + (isNorthDirected ? 0 : -h) : x,\n w: this.isVertical() ? width : h,\n h: this.isVertical() ? h : width,\n tl: isEnding && (this.isVertical()\n ? (!isNegative && isNorthDirected) || (isNegative && !isNorthDirected)\n : isNegative\n ),\n tr: isEnding && (this.isVertical()\n ? (!isNegative && isNorthDirected) || (isNegative && !isNorthDirected)\n : !isNegative\n ),\n br: isEnding && (this.isVertical()\n ? (isNegative && isNorthDirected) || (!isNegative && !isNorthDirected)\n : !isNegative\n ),\n bl: isEnding && (this.isVertical()\n ? (isNegative && isNorthDirected) || (!isNegative && !isNorthDirected)\n : isNegative\n ),\n r: cornerRadiusClamped,\n })\n }\n\n getValueScaleExtent (scaleByVisibleData: boolean): number[] {\n const { datamodel } = this\n const yAccessors = this.getAccessors()\n\n const data = scaleByVisibleData ? this._getVisibleData() : datamodel.data\n return getStackedExtent(data, ...yAccessors)\n }\n\n getDataScaleExtent (): number[] {\n const { config, datamodel } = this\n return getExtent(datamodel.data, config.x)\n }\n\n getYDataExtent (scaleByVisibleData: boolean): number[] {\n return this.isVertical() ? this.getValueScaleExtent(scaleByVisibleData) : this.getDataScaleExtent()\n }\n\n getXDataExtent (): number[] {\n return this.isVertical() ? this.getDataScaleExtent() : this.getValueScaleExtent(false)\n }\n}\n"],"names":["s.barGroup","barGroupExit","s.barGroupExit","s.bar","s"],"mappings":";;;;;;;;;;;AA0BM,MAAO,UAAkB,SAAQ,eAAwD,CAAA;AAW7F,IAAA,WAAA,CAAa,MAAyC,EAAA;AACpD,QAAA,KAAK,EAAE,CAAA;QAVC,IAAc,CAAA,cAAA,GAAG,uBAA2D,CAAA;AAC/E,QAAA,IAAA,CAAA,MAAM,GAAqC,IAAI,CAAC,cAAc,CAAA;AAErE,QAAA,IAAA,CAAA,YAAY,GAAG,OAAiC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACzG,IAAO,CAAA,OAAA,GAAG,IAAI,CAAA;QACd,IAAM,CAAA,MAAA,GAAG,EAAE,CAAA;QAEH,IAAQ,CAAA,QAAA,GAAY,EAAE,CAAA;AAI5B,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;KACnC;AAED,IAAA,IAAI,KAAK,GAAA;AACP,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G,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAA;KACvF;;AA/OM,UAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/stacked-bar/index.ts"],"sourcesContent":["import { min, max } from 'd3-array'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { isNumber, isArray, isEmpty, clamp, getStackedExtent, getString, getNumber, getStackedData, getExtent } from 'utils/data'\nimport { roundedRectPath } from 'utils/path'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { ContinuousScale } from 'types/scale'\nimport { NumericAccessor } from 'types/accessor'\nimport { Spacing } from 'types/spacing'\nimport { Orientation } from 'types/position'\n\n// Local Types\nimport { StackedBarDataRecord } from './types'\n\n// Config\nimport { StackedBarDefaultConfig, StackedBarConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class StackedBar<Datum> extends XYComponentCore<Datum, StackedBarConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = StackedBarDefaultConfig as StackedBarConfigInterface<Datum>\n public config: StackedBarConfigInterface<Datum> = this._defaultConfig\n\n getAccessors = (): NumericAccessor<Datum>[] => (isArray(this.config.y) ? this.config.y : [this.config.y])\n stacked = true\n events = {}\n private _prevNegative: boolean[] | undefined // To help guessing the bar direction when an accessor was set to null or 0\n private _barData: Datum[] = []\n\n constructor (config?: StackedBarConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n }\n\n get bleed (): Spacing {\n this._barData = this._getVisibleData()\n if (this._barData.length === 0) return { top: 0, bottom: 0, left: 0, right: 0 }\n\n // By default, horizontal orientation is \"flipped\", i.e. the `yDirection` of `XYContainer` is set to `Direction.North`\n const isHorizontalAndFlipped = !this.isVertical() && (this.dataScale.range()[0] > this.dataScale.range()[1])\n const dataDomain = this.dataScale.domain()\n const halfGroupWidth = this._getBarWidth() / 2\n\n const dataScaleValues = this._barData.map((d, i) => getNumber(d, this.config.x, i))\n const firstDataValue = min(dataScaleValues)\n const lastDataValue = max(dataScaleValues)\n const firstValuePx = this.dataScale(firstDataValue)\n const lastValuePx = this.dataScale(lastDataValue)\n\n const dataDomainRequiredStart = this.dataScale.invert(firstValuePx + (isHorizontalAndFlipped ? halfGroupWidth : -halfGroupWidth))\n const dataDomainRequiredEnd = this.dataScale.invert(lastValuePx + (isHorizontalAndFlipped ? -halfGroupWidth : halfGroupWidth))\n const bleedPxStart = dataDomainRequiredStart <= dataDomain[0] ? this.dataScale(dataDomain[0]) - this.dataScale(dataDomainRequiredStart) : 0\n const bleedPxEnd = dataDomainRequiredEnd > dataDomain[1] ? this.dataScale(dataDomainRequiredEnd) - this.dataScale(dataDomain[1]) : 0\n\n return {\n top: this.isVertical() ? 0 : (isHorizontalAndFlipped ? -bleedPxEnd : bleedPxStart),\n bottom: this.isVertical() ? 0 : (isHorizontalAndFlipped ? -bleedPxStart : bleedPxEnd),\n left: this.isVertical() ? bleedPxStart : 0,\n right: this.isVertical() ? bleedPxEnd : 0,\n }\n }\n\n private get dataScale (): ContinuousScale {\n return this.isVertical() ? this.xScale : this.yScale\n }\n\n private get valueScale (): ContinuousScale {\n return this.isVertical() ? this.yScale : this.xScale\n }\n\n private isVertical (): boolean {\n return this.config.orientation === Orientation.Vertical\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const yAccessors = this.getAccessors()\n const stacked = getStackedData(this._barData, 0, yAccessors, this._prevNegative)\n this._prevNegative = stacked.map(s => !!s.isMostlyNegative)\n\n const barGroups = this.g\n .selectAll<SVGGElement, Datum>(`.${s.barGroup}`)\n .data(this._barData, (d, i) => `${getString(d, config.id, i) ?? i}`)\n\n const getBarGroupsTransform = (d: Datum, i: number): string => {\n const v = this.dataScale(getNumber(d, config.x, i))\n const x = this.isVertical() ? v : 0\n const y = this.isVertical() ? 0 : v\n return `translate(${x},${y})`\n }\n\n const barGroupsEnter = barGroups.enter().append('g')\n .attr('class', s.barGroup)\n .attr('transform', getBarGroupsTransform)\n .style('opacity', 1)\n\n const barGroupsMerged = barGroupsEnter.merge(barGroups)\n smartTransition(barGroupsMerged, duration)\n .attr('transform', getBarGroupsTransform)\n .style('opacity', 1)\n\n const barGroupExit = barGroups.exit()\n .attr('class', s.barGroupExit)\n\n smartTransition(barGroupExit, duration)\n .style('opacity', 0)\n .remove()\n\n // Animate bars from exiting groups going down\n smartTransition(barGroupExit.selectAll(`.${s.bar}`), duration)\n .attr('transform', this.isVertical()\n ? `translate(0,${this._height / 3})`\n : `translate(${this._width / 6},0)`\n )\n\n // Render Bars\n const bars = barGroupsMerged\n .selectAll<SVGPathElement, StackedBarDataRecord<Datum>>(`.${s.bar}`)\n .data((d, j) => stacked.map((s, stackIndex) =>\n ({\n ...d,\n _index: j,\n _stacked: s[j],\n // Ending bar if the next stack is not the same as the current one\n _ending: (stackIndex === stacked.length - 1) ||\n ((stackIndex <= stacked.length - 1) && stacked[stackIndex + 1][j][0] !== s[j][1]),\n }))\n )\n\n const barsEnter = bars.enter().append('path')\n .attr('class', s.bar)\n .attr('d', (d, j) => this._getBarPath(d, j, true))\n .style('fill', (d, j) => getColor(d, config.color, j))\n\n const barsMerged = barsEnter.merge(bars)\n\n smartTransition(barsMerged, duration)\n .attr('d', (d, j) => this._getBarPath(d, j))\n .style('fill', (d, j) => getColor(d, config.color, j))\n .style('cursor', (d, j) => getString(d, config.cursor, j))\n\n smartTransition(bars.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n _getBarWidth (): number {\n const { config, datamodel: { data } } = this\n if (isEmpty(data)) return 0\n if (config.barWidth) return min([config.barWidth, config.barMaxWidth])\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const isOrdinal = this.dataScale.bandwidth\n const domain = (this.dataScale.domain ? this.dataScale.domain() : []) as number[]\n const domainLength = isOrdinal ? domain.length : domain[1] - domain[0]\n\n // If the dataStep property is provided the amount of data elements is calculates as domainLength / dataStep\n // otherwise we get the number of data elements within the domain range\n // Or if the scale is ordinal we use data.length\n let dataSize = (1 + domainLength / config.dataStep) ||\n (!isOrdinal && data.filter((d, i) => {\n const value = getNumber(d, config.x, i)\n return (value >= domain[0]) && (value <= domain[1])\n }).length) ||\n data.length\n\n // We increase the dataSize by 1 to take into account possible additional domain space\n if (!isOrdinal && dataSize >= 2) dataSize += 1\n\n const c = dataSize < 2 ? 1 : 1 - config.barPadding\n const barWidth = c * (this.isVertical() ? this._width : this._height) / dataSize\n\n return min([barWidth, config.barMaxWidth])\n }\n\n _getVisibleData (): Datum[] {\n const { config, datamodel: { data } } = this\n\n const groupWidth = this._getBarWidth()\n const halfGroupWidthPx = data.length < 2 ? 0 : groupWidth / 2\n\n const scale = this.dataScale\n const halfGroupWidth = Math.abs((scale.invert(halfGroupWidthPx) as number) - (scale.invert(0) as number))\n const filtered = data?.filter((d, i) => {\n const v = getNumber(d, config.x, i)\n const domain: number[] | Date[] = scale.domain()\n const domainMin = +domain[0]\n const domainMax = +domain[1]\n return (v >= (domainMin - halfGroupWidth)) && (v <= (domainMax + halfGroupWidth))\n })\n\n return filtered\n }\n\n _getBarPath (d: StackedBarDataRecord<Datum>, accessorIndex: number, isEntering = false): string {\n const { config } = this\n const yAccessors = this.getAccessors()\n const barWidth = this._getBarWidth()\n\n const isNegative = d._stacked[1] < 0\n const isEnding = d._ending // The most top bar or, if the value is negative, the most bottom bar\n const value = getNumber(d, yAccessors[accessorIndex], d._index)\n const height = isEntering ? 0 : Math.abs(this.valueScale(d._stacked[0]) - this.valueScale(d._stacked[1]))\n const h = !isEntering && config.barMinHeight1Px && (height < 1) && isFinite(value) && (value !== config.barMinHeightZeroValue) ? 1 : height\n const y = isEntering\n ? this.valueScale(0)\n : this.valueScale(isNegative ? d._stacked[0] : d._stacked[1]) - (height < 1 && config.barMinHeight1Px ? 1 : 0)\n\n const x = -barWidth / 2\n const width = barWidth\n\n const cornerRadius = config.roundedCorners\n ? isNumber(config.roundedCorners) ? +config.roundedCorners : width / 2\n : 0\n const cornerRadiusClamped = clamp(cornerRadius, 0, Math.min(height, width) / 2)\n const isNorthDirected = this.yScale.range()[0] > this.yScale.range()[1]\n\n return roundedRectPath({\n x: this.isVertical() ? x : y - h,\n y: this.isVertical() ? y + (isNorthDirected ? 0 : -h) : x,\n w: this.isVertical() ? width : h,\n h: this.isVertical() ? h : width,\n tl: isEnding && (this.isVertical()\n ? (!isNegative && isNorthDirected) || (isNegative && !isNorthDirected)\n : isNegative\n ),\n tr: isEnding && (this.isVertical()\n ? (!isNegative && isNorthDirected) || (isNegative && !isNorthDirected)\n : !isNegative\n ),\n br: isEnding && (this.isVertical()\n ? (isNegative && isNorthDirected) || (!isNegative && !isNorthDirected)\n : !isNegative\n ),\n bl: isEnding && (this.isVertical()\n ? (isNegative && isNorthDirected) || (!isNegative && !isNorthDirected)\n : isNegative\n ),\n r: cornerRadiusClamped,\n })\n }\n\n getValueScaleExtent (scaleByVisibleData: boolean): number[] {\n const { datamodel } = this\n const yAccessors = this.getAccessors()\n\n const data = scaleByVisibleData ? this._getVisibleData() : datamodel.data\n return getStackedExtent(data, ...yAccessors)\n }\n\n getDataScaleExtent (): number[] {\n const { config, datamodel } = this\n return getExtent(datamodel.data, config.x)\n }\n\n getYDataExtent (scaleByVisibleData: boolean): number[] {\n return this.isVertical() ? this.getValueScaleExtent(scaleByVisibleData) : this.getDataScaleExtent()\n }\n\n getXDataExtent (): number[] {\n return this.isVertical() ? this.getDataScaleExtent() : this.getValueScaleExtent(false)\n }\n}\n"],"names":["s.barGroup","barGroupExit","s.barGroupExit","s.bar","s"],"mappings":";;;;;;;;;;;AA0BM,MAAO,UAAkB,SAAQ,eAAwD,CAAA;AAW7F,IAAA,WAAA,CAAa,MAAyC,EAAA;AACpD,QAAA,KAAK,EAAE,CAAA;QAVC,IAAc,CAAA,cAAA,GAAG,uBAA2D,CAAA;AAC/E,QAAA,IAAA,CAAA,MAAM,GAAqC,IAAI,CAAC,cAAc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AAA;KACH;AAED,IAAA,mBAAmB,CAAE,kBAA2B,EAAA;AAC9C,QAAA,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;AAC1B,QAAA,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;AAEtC,QAAA,MAAM,IAAI,GAAG,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,GAAG,SAAS,CAAC,IAAI,CAAA;AACzE,QAAA,OAAO,gBAAgB,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,CAAA;KAC7C;IAED,kBAAkB,GAAA;AAChB,QAAA,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAClC,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;KAC3C;AAED,IAAA,cAAc,CAAE,kBAA2B,EAAA;QACzC,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAA;KACpG;IAED,cAAc,GAAA;QACZ,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAA;KACvF;;AArPM,UAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
@@ -1,5 +1,5 @@
1
1
  export declare type StackedBarDataRecord<D> = D & {
2
+ _index: number;
2
3
  _stacked: [number, number];
3
- _negative: boolean;
4
4
  _ending: boolean;
5
5
  };
@@ -5,11 +5,9 @@ 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` */
8
+ /** Follow the mouse cursor. Default: `true` */
10
9
  followCursor?: boolean;
11
- /** Allow the tooltip to be hovered over and interacted with when `followCursor` is set to `false`.
12
- * Default: `true` */
10
+ /** Allow the tooltip to be hovered over and interacted with. Default: `false` */
13
11
  allowHover?: boolean;
14
12
  /** Horizontal placement of the tooltip. Default: `Position.Auto` */
15
13
  horizontalPlacement?: Position | string | undefined;
@@ -62,5 +60,9 @@ export interface TooltipConfigInterface {
62
60
  };
63
61
  /** Custom class name for the tooltip. Default: `undefined` */
64
62
  className?: string;
63
+ /** Hide delay in milliseconds. Default: `undefined` */
64
+ hideDelay?: number;
65
+ /** Show delay in milliseconds. Default: `undefined` */
66
+ showDelay?: number;
65
67
  }
66
68
  export declare const TooltipDefaultConfig: TooltipConfigInterface;
@@ -5,7 +5,7 @@ const TooltipDefaultConfig = {
5
5
  components: [],
6
6
  container: undefined,
7
7
  followCursor: true,
8
- allowHover: true,
8
+ allowHover: false,
9
9
  horizontalPlacement: Position.Auto,
10
10
  horizontalShift: 0,
11
11
  verticalPlacement: Position.Top,
@@ -13,6 +13,8 @@ const TooltipDefaultConfig = {
13
13
  attributes: {},
14
14
  triggers: {},
15
15
  className: undefined,
16
+ showDelay: undefined,
17
+ hideDelay: undefined,
16
18
  };
17
19
 
18
20
  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 /** 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;;;;;"}
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. Default: `true` */\n followCursor?: boolean;\n /** Allow the tooltip to be hovered over and interacted with. Default: `false` */\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 /** Hide delay in milliseconds. Default: `undefined` */\n hideDelay?: number;\n /** Show delay in milliseconds. Default: `undefined` */\n showDelay?: number;\n}\n\nexport const TooltipDefaultConfig: TooltipConfigInterface = {\n components: [],\n container: undefined,\n followCursor: true,\n allowHover: false,\n horizontalPlacement: Position.Auto,\n horizontalShift: 0,\n verticalPlacement: Position.Top,\n verticalShift: 0,\n attributes: {},\n triggers: {},\n className: undefined,\n showDelay: undefined,\n hideDelay: undefined,\n}\n\n"],"names":[],"mappings":";;AAGA;AAmEa,MAAA,oBAAoB,GAA2B;AAC1D,IAAA,UAAU,EAAE,EAAE;AACd,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,UAAU,EAAE,KAAK;IACjB,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;AACpB,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,SAAS,EAAE,SAAS;;;;;"}
@@ -19,6 +19,8 @@ export declare class Tooltip {
19
19
  private _hoveredElement;
20
20
  private _position;
21
21
  private _overriddenHorizontalPlacement;
22
+ private _hideDelayTimeoutId;
23
+ private _showDelayTimeoutId;
22
24
  constructor(config?: TooltipConfigInterface);
23
25
  setConfig(config: TooltipConfigInterface): void;
24
26
  setContainer(container: HTMLElement): void;
@@ -26,14 +28,16 @@ export declare class Tooltip {
26
28
  hasContainer(): boolean;
27
29
  setComponents(components: ComponentCore<unknown>[]): void;
28
30
  update(): void;
29
- /** Show the tooltip by providing content and position */
31
+ /** Show the tooltip immediately by providing content and position */
30
32
  show(html: string | HTMLElement | null | void, pos: {
31
33
  x: number;
32
34
  y: number;
33
35
  }): void;
34
- /** Hide the tooltip */
36
+ private _hide;
37
+ /** Hides the tooltip after `hideDelay` */
35
38
  hide(): void;
36
- /** Simply displays the tooltip with its previous content on position */
39
+ private _display;
40
+ /** Simply display the tooltip with its previous content on position, taking into account `showDelay` */
37
41
  display(): void;
38
42
  place(pos: {
39
43
  x: number;
@@ -13,7 +13,10 @@ 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).attr('class', root);
16
+ this.div = select(this.element)
17
+ .attr('class', root)
18
+ .classed(show, false)
19
+ .classed(hidden, true);
17
20
  this.setConfig(config);
18
21
  this.components = this.config.components;
19
22
  // Set up MutationObserver to automatically re-position the tooltip
@@ -66,13 +69,12 @@ class Tooltip {
66
69
  return;
67
70
  this._setUpEventsThrottled();
68
71
  }
69
- /** Show the tooltip by providing content and position */
72
+ /** Show the tooltip immediately by providing content and position */
70
73
  show(html, pos) {
71
74
  this.render(html);
72
75
  this.place(pos);
73
76
  }
74
- /** Hide the tooltip */
75
- hide() {
77
+ _hide() {
76
78
  this.div
77
79
  .classed(show, false) // The `show` class triggers the opacity transition
78
80
  .on('transitionend', () => {
@@ -82,13 +84,39 @@ class Tooltip {
82
84
  });
83
85
  this._isShown = false;
84
86
  }
85
- /** Simply displays the tooltip with its previous content on position */
86
- display() {
87
+ /** Hides the tooltip after `hideDelay` */
88
+ hide() {
89
+ window.clearTimeout(this._showDelayTimeoutId);
90
+ if (this.config.hideDelay) {
91
+ window.clearTimeout(this._hideDelayTimeoutId);
92
+ this._hideDelayTimeoutId = setTimeout(() => this._hide(), this.config.hideDelay);
93
+ }
94
+ else {
95
+ this._hide();
96
+ }
97
+ }
98
+ _display() {
99
+ window.clearTimeout(this._hideDelayTimeoutId);
87
100
  this.div
88
101
  .classed(hidden, false) // The `hidden` class sets `display: none;`
89
102
  .classed(show, true); // The `show` class triggers the opacity transition
90
103
  this._isShown = true;
91
104
  }
105
+ /** Simply display the tooltip with its previous content on position, taking into account `showDelay` */
106
+ display() {
107
+ if (this._isShown)
108
+ return;
109
+ if (this.config.showDelay) {
110
+ window.clearTimeout(this._showDelayTimeoutId);
111
+ this._showDelayTimeoutId = setTimeout(() => {
112
+ this._display();
113
+ this.place({ x: this._position[0], y: this._position[1] });
114
+ }, this.config.showDelay);
115
+ }
116
+ else {
117
+ this._display();
118
+ }
119
+ }
92
120
  place(pos) {
93
121
  this._position = [pos.x, pos.y];
94
122
  if (!this.hasContainer()) {
@@ -202,7 +230,7 @@ class Tooltip {
202
230
  }
203
231
  this.div
204
232
  .classed((_a = config.className) !== null && _a !== void 0 ? _a : '', Boolean(config.className))
205
- .classed(nonInteractive, !config.allowHover || config.followCursor);
233
+ .classed(nonInteractive, !config.allowHover);
206
234
  // Remove the previous class name if it was set
207
235
  if ((prevConfig === null || prevConfig === void 0 ? void 0 : prevConfig.className) && prevConfig.className !== config.className) {
208
236
  this.div.classed(prevConfig.className, false);
@@ -303,9 +331,9 @@ class Tooltip {
303
331
  });
304
332
  });
305
333
  // Set up Tooltip hover
306
- if (config.allowHover && !config.followCursor) {
334
+ if (config.allowHover) {
307
335
  this.div
308
- .on('mouseenter.tooltip', this.display.bind(this))
336
+ .on('mouseenter.tooltip', this._display.bind(this))
309
337
  .on('mouseleave.tooltip', this.hide.bind(this));
310
338
  }
311
339
  else {
@@ -325,6 +353,8 @@ class Tooltip {
325
353
  destroy() {
326
354
  var _a;
327
355
  this._mutationObserver.disconnect();
356
+ window.clearTimeout(this._hideDelayTimeoutId);
357
+ window.clearTimeout(this._showDelayTimeoutId);
328
358
  (_a = this.div) === null || _a === void 0 ? void 0 : _a.remove();
329
359
  }
330
360
  }
@@ -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 private _mutationObserver: MutationObserver\n private _hoveredElement: HTMLElement | SVGElement\n private _position: [number, number]\n private _overriddenHorizontalPlacement: Position.Left | Position.Right | string | undefined\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 // Reset `this._overriddenHorizontalPlacement` if the `horizontalPlacement` has changed\n if (this.prevConfig.horizontalPlacement !== this.config.horizontalPlacement) {\n this.overrideHorizontalPlacement(undefined)\n }\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 = this._overriddenHorizontalPlacement ||\n (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 = this._overriddenHorizontalPlacement || (\n 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\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 /** Allows to override the horizontal placement of the tooltip which is useful when you want to define custom positioning behavior.\n * This method has been added for Crosshair to allow it position tooltip left or right of the crosshair line\n * (see the `_showTooltip` method of the Crosshair component).\n */\n public overrideHorizontalPlacement (placement: Position.Left | Position.Right | string | undefined): void {\n this._overriddenHorizontalPlacement = placement\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;AAiBlB,IAAA,WAAA,CAAa,SAAiC,EAAE,EAAA;QAdtC,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,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AE,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;;AApXM,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 private _overriddenHorizontalPlacement: Position.Left | Position.Right | string | undefined\n private _hideDelayTimeoutId: ReturnType<typeof setTimeout> | undefined\n private _showDelayTimeoutId: ReturnType<typeof setTimeout> | undefined\n\n constructor (config: TooltipConfigInterface = {}) {\n this.element = document.createElement('div')\n this.div = select(this.element)\n .attr('class', s.root)\n .classed(s.show, false)\n .classed(s.hidden, true)\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 // Reset `this._overriddenHorizontalPlacement` if the `horizontalPlacement` has changed\n if (this.prevConfig.horizontalPlacement !== this.config.horizontalPlacement) {\n this.overrideHorizontalPlacement(undefined)\n }\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 immediately 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 private _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 /** Hides the tooltip after `hideDelay` */\n public hide (): void {\n window.clearTimeout(this._showDelayTimeoutId)\n if (this.config.hideDelay) {\n window.clearTimeout(this._hideDelayTimeoutId)\n this._hideDelayTimeoutId = setTimeout(() => this._hide(), this.config.hideDelay)\n } else {\n this._hide()\n }\n }\n\n private _display (): void {\n window.clearTimeout(this._hideDelayTimeoutId)\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 /** Simply display the tooltip with its previous content on position, taking into account `showDelay` */\n public display (): void {\n if (this._isShown) return\n\n if (this.config.showDelay) {\n window.clearTimeout(this._showDelayTimeoutId)\n this._showDelayTimeoutId = setTimeout(() => {\n this._display()\n this.place({ x: this._position[0], y: this._position[1] })\n }, this.config.showDelay)\n } else {\n this._display()\n }\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 = this._overriddenHorizontalPlacement ||\n (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 = this._overriddenHorizontalPlacement || (\n 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\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 /** Allows to override the horizontal placement of the tooltip which is useful when you want to define custom positioning behavior.\n * This method has been added for Crosshair to allow it position tooltip left or right of the crosshair line\n * (see the `_showTooltip` method of the Crosshair component).\n */\n public overrideHorizontalPlacement (placement: Position.Left | Position.Right | string | undefined): void {\n this._overriddenHorizontalPlacement = placement\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)\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) {\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 window.clearTimeout(this._hideDelayTimeoutId)\n window.clearTimeout(this._showDelayTimeoutId)\n this.div?.remove()\n }\n}\n"],"names":["s.root","s.show","s.hidden","s.nonInteractive","s.positionFixed","s"],"mappings":";;;;;;;MAiBa,OAAO,CAAA;AAmBlB,IAAA,WAAA,CAAa,SAAiC,EAAE,EAAA;QAhBtC,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;QAUtB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAC5C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAC5B,aAAA,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC;AACrB,aAAA,OAAO,CAACC,IAAM,EAAE,KAAK,CAAC;AACtB,aAAA,OA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CAAA;KACnB;;AApZM,OAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
package/components.d.ts CHANGED
@@ -27,6 +27,7 @@ export { FreeBrush } from './components/free-brush';
27
27
  export { XYLabels } from './components/xy-labels';
28
28
  export { NestedDonut } from './components/nested-donut';
29
29
  export { Annotations } from "./components/annotations";
30
+ export * from './components/donut/constants';
30
31
  export type { LineConfigInterface } from './components/line/config';
31
32
  export type { StackedBarConfigInterface } from './components/stacked-bar/config';
32
33
  export type { GroupedBarConfigInterface } from './components/grouped-bar/config';
package/components.js CHANGED
@@ -25,6 +25,7 @@ export { FreeBrush } from './components/free-brush/index.js';
25
25
  export { XYLabels } from './components/xy-labels/index.js';
26
26
  export { NestedDonut } from './components/nested-donut/index.js';
27
27
  export { Annotations } from './components/annotations/index.js';
28
+ export { DONUT_HALF_ANGLE_RANGES, DONUT_HALF_ANGLE_RANGE_BOTTOM, DONUT_HALF_ANGLE_RANGE_LEFT, DONUT_HALF_ANGLE_RANGE_RIGHT, DONUT_HALF_ANGLE_RANGE_TOP } from './components/donut/constants.js';
28
29
 
29
30
  // Core
30
31
  //# sourceMappingURL=components.js.map
package/components.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sources":["../src/components.ts"],"sourcesContent":["// Core\nexport { ComponentCore } from 'core/component'\nexport type { ComponentConfigInterface } from 'core/component/config'\nexport { XYComponentCore } from 'core/xy-component'\nexport type { XYComponentConfigInterface } from 'core/xy-component/config'\n\n// Components\nexport { Tooltip } from 'components/tooltip'\nexport { Line } from './components/line'\nexport { StackedBar } from './components/stacked-bar'\nexport { GroupedBar } from './components/grouped-bar'\nexport { Axis } from './components/axis'\nexport { Scatter } from './components/scatter'\nexport { Brush } from './components/brush'\nexport { BulletLegend } from './components/bullet-legend'\nexport { FlowLegend } from './components/flow-legend'\nexport { Crosshair } from './components/crosshair'\nexport { Timeline } from './components/timeline'\nexport { Sankey } from './components/sankey'\nexport { Area } from './components/area'\nexport { TopoJSONMap } from './components/topojson-map'\nexport { LeafletMap } from './components/leaflet-map'\nexport { MapLibreArcticDark, MapLibreArcticLight } from './components/leaflet-map/renderer/map-style'\nexport { LeafletFlowMap } from './components/leaflet-flow-map'\nexport { ChordDiagram } from './components/chord-diagram'\nexport { Graph } from './components/graph'\nexport { VisControls } from './components/vis-controls'\nexport { Donut } from './components/donut'\nexport { FreeBrush } from './components/free-brush'\nexport { XYLabels } from './components/xy-labels'\nexport { NestedDonut } from './components/nested-donut'\nexport { Annotations } from 'components/annotations'\n\n// Config Interfaces\nexport type { LineConfigInterface } from './components/line/config'\nexport type { StackedBarConfigInterface } from './components/stacked-bar/config'\nexport type { GroupedBarConfigInterface } from './components/grouped-bar/config'\nexport type { ScatterConfigInterface } from './components/scatter/config'\nexport type { TooltipConfigInterface } from './components/tooltip/config'\nexport type { BrushConfigInterface } from './components/brush/config'\nexport type { AxisConfigInterface } from './components/axis/config'\nexport type { BulletLegendConfigInterface } from './components/bullet-legend/config'\nexport type { FlowLegendConfigInterface } from './components/flow-legend/config'\nexport type { CrosshairConfigInterface } from './components/crosshair/config'\nexport type { TimelineConfigInterface } from './components/timeline/config'\nexport type { SankeyConfigInterface } from './components/sankey/config'\nexport type { AreaConfigInterface } from './components/area/config'\nexport type { TopoJSONMapConfigInterface } from './components/topojson-map/config'\nexport type { LeafletMapConfigInterface } from './components/leaflet-map/config'\nexport type { LeafletFlowMapConfigInterface } from './components/leaflet-flow-map/config'\nexport type { ChordDiagramConfigInterface } from './components/chord-diagram/config'\nexport type { GraphConfigInterface } from './components/graph/config'\nexport type { VisControlsConfigInterface } from './components/vis-controls/config'\nexport type { DonutConfigInterface } from './components/donut/config'\nexport type { FreeBrushConfigInterface } from './components/free-brush/config'\nexport type { XYLabelsConfigInterface } from './components/xy-labels/config'\nexport type { NestedDonutConfigInterface } from './components/nested-donut/config'\nexport type { AnnotationsConfigInterface } from './components/annotations/config'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA"}
1
+ {"version":3,"file":"components.js","sources":["../src/components.ts"],"sourcesContent":["// Core\nexport { ComponentCore } from 'core/component'\nexport type { ComponentConfigInterface } from 'core/component/config'\nexport { XYComponentCore } from 'core/xy-component'\nexport type { XYComponentConfigInterface } from 'core/xy-component/config'\n\n// Components\nexport { Tooltip } from 'components/tooltip'\nexport { Line } from './components/line'\nexport { StackedBar } from './components/stacked-bar'\nexport { GroupedBar } from './components/grouped-bar'\nexport { Axis } from './components/axis'\nexport { Scatter } from './components/scatter'\nexport { Brush } from './components/brush'\nexport { BulletLegend } from './components/bullet-legend'\nexport { FlowLegend } from './components/flow-legend'\nexport { Crosshair } from './components/crosshair'\nexport { Timeline } from './components/timeline'\nexport { Sankey } from './components/sankey'\nexport { Area } from './components/area'\nexport { TopoJSONMap } from './components/topojson-map'\nexport { LeafletMap } from './components/leaflet-map'\nexport { MapLibreArcticDark, MapLibreArcticLight } from './components/leaflet-map/renderer/map-style'\nexport { LeafletFlowMap } from './components/leaflet-flow-map'\nexport { ChordDiagram } from './components/chord-diagram'\nexport { Graph } from './components/graph'\nexport { VisControls } from './components/vis-controls'\nexport { Donut } from './components/donut'\nexport { FreeBrush } from './components/free-brush'\nexport { XYLabels } from './components/xy-labels'\nexport { NestedDonut } from './components/nested-donut'\nexport { Annotations } from 'components/annotations'\n\n// Constants\nexport * from './components/donut/constants'\n\n// Config Interfaces\nexport type { LineConfigInterface } from './components/line/config'\nexport type { StackedBarConfigInterface } from './components/stacked-bar/config'\nexport type { GroupedBarConfigInterface } from './components/grouped-bar/config'\nexport type { ScatterConfigInterface } from './components/scatter/config'\nexport type { TooltipConfigInterface } from './components/tooltip/config'\nexport type { BrushConfigInterface } from './components/brush/config'\nexport type { AxisConfigInterface } from './components/axis/config'\nexport type { BulletLegendConfigInterface } from './components/bullet-legend/config'\nexport type { FlowLegendConfigInterface } from './components/flow-legend/config'\nexport type { CrosshairConfigInterface } from './components/crosshair/config'\nexport type { TimelineConfigInterface } from './components/timeline/config'\nexport type { SankeyConfigInterface } from './components/sankey/config'\nexport type { AreaConfigInterface } from './components/area/config'\nexport type { TopoJSONMapConfigInterface } from './components/topojson-map/config'\nexport type { LeafletMapConfigInterface } from './components/leaflet-map/config'\nexport type { LeafletFlowMapConfigInterface } from './components/leaflet-flow-map/config'\nexport type { ChordDiagramConfigInterface } from './components/chord-diagram/config'\nexport type { GraphConfigInterface } from './components/graph/config'\nexport type { VisControlsConfigInterface } from './components/vis-controls/config'\nexport type { DonutConfigInterface } from './components/donut/config'\nexport type { FreeBrushConfigInterface } from './components/free-brush/config'\nexport type { XYLabelsConfigInterface } from './components/xy-labels/config'\nexport type { NestedDonutConfigInterface } from './components/nested-donut/config'\nexport type { AnnotationsConfigInterface } from './components/annotations/config'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA"}
@@ -10,11 +10,11 @@ export declare class GraphDataModel<N extends GraphInputNode, L extends GraphInp
10
10
  private _nodes;
11
11
  private _links;
12
12
  private _inputNodesMap;
13
- private _nodeIds;
13
+ private _nodesMap;
14
14
  nodeId: ((n: N) => string | undefined);
15
15
  linkId: ((n: L) => string | undefined);
16
16
  nodeSort: ((a: N, b: N) => number);
17
- getNodeFromId(id: string | number): OutNode;
17
+ getNodeById(id: string | number): OutNode;
18
18
  get data(): GraphData<N, L>;
19
19
  set data(inputData: GraphData<N, L>);
20
20
  get nodes(): OutNode[];
@@ -23,4 +23,5 @@ export declare class GraphDataModel<N extends GraphInputNode, L extends GraphInp
23
23
  get nonConnectedNodes(): OutNode[];
24
24
  private findNode;
25
25
  private transferState;
26
+ setNodeStateById(id: string, state: Record<string, any>): void;
26
27
  }
@@ -7,13 +7,13 @@ class GraphDataModel extends CoreDataModel {
7
7
  this._nodes = [];
8
8
  this._links = [];
9
9
  this._inputNodesMap = new Map();
10
- this._nodeIds = new Map();
10
+ this._nodesMap = new Map();
11
11
  // Model configuration
12
12
  this.nodeId = n => (isString(n.id) || isFinite(n.id)) ? `${n.id}` : undefined;
13
13
  this.linkId = l => (isString(l.id) || isFinite(l.id)) ? `${l.id}` : undefined;
14
14
  }
15
- getNodeFromId(id) {
16
- return this._nodeIds.get(id);
15
+ getNodeById(id) {
16
+ return this._nodesMap.get(id);
17
17
  }
18
18
  get data() {
19
19
  return this._data;
@@ -26,7 +26,8 @@ class GraphDataModel extends CoreDataModel {
26
26
  const prevNodes = this.nodes;
27
27
  const prevLinks = this.links;
28
28
  this._inputNodesMap.clear();
29
- this._nodeIds.clear();
29
+ this._nodesMap.clear();
30
+ // Todo: Figure out why TypeScript complains about types
30
31
  const nodes = cloneDeep((_a = inputData === null || inputData === void 0 ? void 0 : inputData.nodes) !== null && _a !== void 0 ? _a : []);
31
32
  const links = cloneDeep((_b = inputData === null || inputData === void 0 ? void 0 : inputData.links) !== null && _b !== void 0 ? _b : []);
32
33
  // Every node or link can have a private state used for rendering needs
@@ -38,7 +39,7 @@ class GraphDataModel extends CoreDataModel {
38
39
  node._index = i;
39
40
  node._id = this.nodeId(node) || `${i}`;
40
41
  this._inputNodesMap.set(node, inputData.nodes[i]);
41
- this._nodeIds.set(node._id, node);
42
+ this._nodesMap.set(node._id, node);
42
43
  });
43
44
  // Sort nodes
44
45
  if (isFunction(this.nodeSort))
@@ -94,7 +95,7 @@ class GraphDataModel extends CoreDataModel {
94
95
  else if (isObject(nodeIdentifier))
95
96
  foundNode = nodes.find(node => isEqual(this._inputNodesMap.get(node), nodeIdentifier));
96
97
  if (!foundNode) {
97
- console.warn(`Node ${nodeIdentifier} is missing from the nodes list`);
98
+ console.warn(`Unovis | Graph Data Model: Node ${nodeIdentifier} is missing from the nodes list`);
98
99
  }
99
100
  return foundNode;
100
101
  }
@@ -107,6 +108,14 @@ class GraphDataModel extends CoreDataModel {
107
108
  item._state = {};
108
109
  }
109
110
  }
111
+ setNodeStateById(id, state) {
112
+ const node = this.getNodeById(id);
113
+ if (!node) {
114
+ console.warn(`Unovis | Graph Data Model: Node ${id} not found`);
115
+ return;
116
+ }
117
+ node._state = state;
118
+ }
110
119
  }
111
120
 
112
121
  export { GraphDataModel };