@unovis/ts 1.4.0-alpha.9 → 1.4.0-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.
- package/components/annotations/config.d.ts +19 -0
- package/components/annotations/config.js +6 -0
- package/components/annotations/config.js.map +1 -0
- package/components/annotations/index.d.ts +24 -0
- package/components/annotations/index.js +117 -0
- package/components/annotations/index.js.map +1 -0
- package/components/annotations/style.d.ts +13 -0
- package/components/annotations/style.js +43 -0
- package/components/annotations/style.js.map +1 -0
- package/components/annotations/types.d.ts +43 -0
- package/components/annotations/types.js +8 -0
- package/components/annotations/types.js.map +1 -0
- package/components/area/config.d.ts +1 -1
- package/components/area/config.js.map +1 -1
- package/components/area/index.js.map +1 -1
- package/components/bullet-legend/config.d.ts +4 -2
- package/components/bullet-legend/config.js +1 -2
- package/components/bullet-legend/config.js.map +1 -1
- package/components/bullet-legend/index.js +15 -17
- package/components/bullet-legend/index.js.map +1 -1
- package/components/bullet-legend/modules/shape.d.ts +1 -2
- package/components/bullet-legend/modules/shape.js +39 -48
- package/components/bullet-legend/modules/shape.js.map +1 -1
- package/components/bullet-legend/style.js +2 -5
- package/components/bullet-legend/style.js.map +1 -1
- package/components/bullet-legend/types.d.ts +14 -5
- package/components/bullet-legend/types.js +4 -6
- package/components/bullet-legend/types.js.map +1 -1
- package/components/graph/config.d.ts +15 -22
- package/components/graph/config.js +2 -4
- package/components/graph/config.js.map +1 -1
- package/components/graph/index.d.ts +2 -7
- package/components/graph/index.js +116 -117
- package/components/graph/index.js.map +1 -1
- package/components/graph/modules/layout.js +19 -30
- package/components/graph/modules/layout.js.map +1 -1
- package/components/graph/modules/link/helper.d.ts +6 -4
- package/components/graph/modules/link/helper.js +25 -15
- package/components/graph/modules/link/helper.js.map +1 -1
- package/components/graph/modules/link/index.d.ts +3 -3
- package/components/graph/modules/link/index.js +89 -111
- package/components/graph/modules/link/index.js.map +1 -1
- package/components/graph/modules/link/style.d.ts +5 -5
- package/components/graph/modules/link/style.js +22 -26
- package/components/graph/modules/link/style.js.map +1 -1
- package/components/graph/modules/node/helper.d.ts +0 -1
- package/components/graph/modules/node/helper.js +1 -4
- package/components/graph/modules/node/helper.js.map +1 -1
- package/components/graph/modules/node/index.js +11 -28
- package/components/graph/modules/node/index.js.map +1 -1
- package/components/graph/modules/node/style.d.ts +1 -1
- package/components/graph/modules/node/style.js +6 -13
- package/components/graph/modules/node/style.js.map +1 -1
- package/components/graph/modules/shape.d.ts +2 -0
- package/components/graph/modules/shape.js +9 -7
- package/components/graph/modules/shape.js.map +1 -1
- package/components/graph/types.d.ts +5 -63
- package/components/graph/types.js +0 -1
- package/components/graph/types.js.map +1 -1
- package/components/nested-donut/config.d.ts +1 -0
- package/components/nested-donut/config.js +1 -1
- package/components/nested-donut/config.js.map +1 -1
- package/components/nested-donut/index.js +16 -10
- package/components/nested-donut/index.js.map +1 -1
- package/components/stacked-bar/index.js.map +1 -1
- package/components/tooltip/config.d.ts +1 -1
- package/components/tooltip/config.js.map +1 -1
- package/components/tooltip/index.js +1 -3
- package/components/tooltip/index.js.map +1 -1
- package/components/vis-controls/index.d.ts +0 -3
- package/components/vis-controls/index.js +1 -6
- package/components/vis-controls/index.js.map +1 -1
- package/components.d.ts +2 -0
- package/components.js +1 -0
- package/components.js.map +1 -1
- package/containers/single-container/config.d.ts +3 -0
- package/containers/single-container/config.js.map +1 -1
- package/containers/single-container/index.js +10 -1
- package/containers/single-container/index.js.map +1 -1
- package/containers/xy-container/config.d.ts +3 -0
- package/containers/xy-container/config.js +1 -1
- package/containers/xy-container/config.js.map +1 -1
- package/containers/xy-container/index.js +17 -5
- package/containers/xy-container/index.js.map +1 -1
- package/core/component/index.d.ts +3 -3
- package/core/component/index.js +1 -1
- package/core/component/index.js.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types/misc.d.ts +1 -0
- package/types/scale.d.ts +3 -2
- package/types/scale.js +2 -1
- package/types/scale.js.map +1 -1
- package/types.d.ts +1 -0
- package/types.js +1 -0
- package/types.js.map +1 -1
- package/utils/misc.d.ts +2 -1
- package/utils/misc.js +13 -1
- package/utils/misc.js.map +1 -1
- package/utils/svg.d.ts +0 -3
- package/utils/text.js.map +1 -1
- package/utils/svg.js +0 -61
- package/utils/svg.js.map +0 -1
|
@@ -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,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAC5C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAC5B,aAAA,IAAI,CAAC,OAAO,EAAEA,OAAS,CAAC,CAAA;AAE3B,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;KACzC;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AAC,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\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 (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 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,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,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Selection } from 'd3-selection';
|
|
2
2
|
import { VisControlItemInterface } from './types';
|
|
3
3
|
import { VisControlsConfigInterface } from './config';
|
|
4
|
-
import * as s from './style';
|
|
5
4
|
export declare class VisControls {
|
|
6
|
-
static selectors: typeof s;
|
|
7
5
|
div: Selection<HTMLDivElement, unknown, null, undefined>;
|
|
8
6
|
element: HTMLDivElement;
|
|
9
7
|
protected _defaultConfig: VisControlsConfigInterface;
|
|
@@ -14,5 +12,4 @@ export declare class VisControls {
|
|
|
14
12
|
update(config: VisControlsConfigInterface): void;
|
|
15
13
|
render(): void;
|
|
16
14
|
_onItemClick(event: MouseEvent, item: VisControlItemInterface): void;
|
|
17
|
-
destroy(): void;
|
|
18
15
|
}
|
|
@@ -2,7 +2,6 @@ import { select } from 'd3-selection';
|
|
|
2
2
|
import { merge } from '../../utils/data.js';
|
|
3
3
|
import { VisControlsOrientation } from './types.js';
|
|
4
4
|
import { VisControlsDefaultConfig } from './config.js';
|
|
5
|
-
import * as style from './style.js';
|
|
6
5
|
import { root, items, horizontalItems, item, itemButton, borderLeft, borderTop, borderRight, borderBottom, disabled } from './style.js';
|
|
7
6
|
|
|
8
7
|
class VisControls {
|
|
@@ -50,11 +49,7 @@ class VisControls {
|
|
|
50
49
|
var _a;
|
|
51
50
|
(_a = item.callback) === null || _a === void 0 ? void 0 : _a.call(item, event);
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
this.div.remove();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
VisControls.selectors = style;
|
|
52
|
+
}
|
|
58
53
|
|
|
59
54
|
export { VisControls };
|
|
60
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/vis-controls/index.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Local Types\nimport { VisControlItemInterface, VisControlsOrientation } from './types'\n\n// Config\nimport { VisControlsDefaultConfig, VisControlsConfigInterface } from './config'\n\n// Style\nimport * as s from './style'\n\nexport class VisControls {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/vis-controls/index.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Local Types\nimport { VisControlItemInterface, VisControlsOrientation } from './types'\n\n// Config\nimport { VisControlsDefaultConfig, VisControlsConfigInterface } from './config'\n\n// Style\nimport * as s from './style'\n\nexport class VisControls {\n div: Selection<HTMLDivElement, unknown, null, undefined>\n element: HTMLDivElement\n protected _defaultConfig = VisControlsDefaultConfig as VisControlsConfigInterface\n public config: VisControlsConfigInterface = this._defaultConfig\n\n protected _container: HTMLElement\n protected _items: Selection<HTMLDivElement, unknown, null, undefined>\n\n constructor (element: HTMLElement, config?: VisControlsConfigInterface) {\n this._container = element\n\n this.div = select(this._container)\n .append('div')\n .attr('class', s.root)\n this.element = this.div.node()\n this._items = this.div.append('div')\n .attr('class', s.items)\n\n if (config) this.update(config)\n }\n\n update (config: VisControlsConfigInterface): void {\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config: { items, orientation } } = this\n this._items\n .classed(s.horizontalItems, orientation === VisControlsOrientation.Horizontal)\n const controlItems = this._items.selectAll<HTMLDivElement, VisControlItemInterface>(`.${s.item}`)\n .data(items)\n\n const controlItemsEnter = controlItems.enter()\n .append('div')\n .attr('class', s.item)\n .on('click', this._onItemClick.bind(this))\n\n controlItemsEnter.append('button')\n .attr('class', s.itemButton)\n\n const controlItemsMerged = controlItemsEnter.merge(controlItems)\n controlItemsMerged\n .classed(s.borderLeft, d => d.borderLeft)\n .classed(s.borderTop, d => d.borderTop)\n .classed(s.borderRight, d => d.borderRight)\n .classed(s.borderBottom, d => d.borderBottom)\n .classed(s.disabled, d => d.disabled)\n controlItemsMerged.select(`.${s.itemButton}`)\n .html(item => item.icon)\n\n controlItems.exit().remove()\n }\n\n _onItemClick (event: MouseEvent, item: VisControlItemInterface): void {\n item.callback?.(event)\n }\n}\n"],"names":["s.root","s.items","s.horizontalItems","s.item","s.itemButton","s.borderLeft","s.borderTop","s.borderRight","s.borderBottom","s.disabled"],"mappings":";;;;;;MAca,WAAW,CAAA;IAStB,WAAa,CAAA,OAAoB,EAAE,MAAmC,EAAA;QAN5D,IAAc,CAAA,cAAA,GAAG,wBAAsD,CAAA;AAC1E,QAAA,IAAA,CAAA,MAAM,GAA+B,IAAI,CAAC,cAAc,CAAA;AAM7D,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;QAEzB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;aAC/B,MAAM,CAAC,KAAK,CAAC;AACb,aAAA,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;AACjC,aAAA,IAAI,CAAC,OAAO,EAAEC,KAAO,CAAC,CAAA;AAEzB,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;KAChC;AAED,IAAA,MAAM,CAAE,MAAkC,EAAA;QACxC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;QAChD,IAAI,CAAC,MAAM,EAAE,CAAA;KACd;IAED,MAAM,GAAA;QACJ,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,IAAI,CAAA;AAC/C,QAAA,IAAI,CAAC,MAAM;aACR,OAAO,CAACC,eAAiB,EAAE,WAAW,KAAK,sBAAsB,CAAC,UAAU,CAA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AQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAb,IAAI,EAAY,KAAK,CAAC,CAAA;KACvB;AACF;;;;"}
|
package/components.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { Donut } from './components/donut';
|
|
|
26
26
|
export { FreeBrush } from './components/free-brush';
|
|
27
27
|
export { XYLabels } from './components/xy-labels';
|
|
28
28
|
export { NestedDonut } from './components/nested-donut';
|
|
29
|
+
export { Annotations } from "./components/annotations";
|
|
29
30
|
export type { LineConfigInterface } from './components/line/config';
|
|
30
31
|
export type { StackedBarConfigInterface } from './components/stacked-bar/config';
|
|
31
32
|
export type { GroupedBarConfigInterface } from './components/grouped-bar/config';
|
|
@@ -49,3 +50,4 @@ export type { DonutConfigInterface } from './components/donut/config';
|
|
|
49
50
|
export type { FreeBrushConfigInterface } from './components/free-brush/config';
|
|
50
51
|
export type { XYLabelsConfigInterface } from './components/xy-labels/config';
|
|
51
52
|
export type { NestedDonutConfigInterface } from './components/nested-donut/config';
|
|
53
|
+
export type { AnnotationsConfigInterface } from './components/annotations/config';
|
package/components.js
CHANGED
|
@@ -24,6 +24,7 @@ export { Donut } from './components/donut/index.js';
|
|
|
24
24
|
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
|
+
export { Annotations } from './components/annotations/index.js';
|
|
27
28
|
|
|
28
29
|
// Core
|
|
29
30
|
//# 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'\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'\n"],"names":[],"mappings":"
|
|
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,10 +1,13 @@
|
|
|
1
1
|
import { ContainerConfigInterface } from "../../core/container/config";
|
|
2
2
|
import { ComponentCore } from "../../core/component";
|
|
3
3
|
import { Tooltip } from "../../components/tooltip";
|
|
4
|
+
import { Annotations } from "../../components/annotations";
|
|
4
5
|
export interface SingleContainerConfigInterface<Datum> extends ContainerConfigInterface {
|
|
5
6
|
/** Visualization component. Default: `undefined` */
|
|
6
7
|
component?: ComponentCore<Datum>;
|
|
7
8
|
/** Tooltip component. Default: `undefined` */
|
|
8
9
|
tooltip?: Tooltip;
|
|
10
|
+
/** Annotations component. Default: `undefined` */
|
|
11
|
+
annotations?: Annotations | undefined;
|
|
9
12
|
}
|
|
10
13
|
export declare const SingleContainerDefaultConfig: SingleContainerConfigInterface<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/containers/single-container/config.ts"],"sourcesContent":["// Core\nimport { ContainerDefaultConfig, ContainerConfigInterface } from 'core/container/config'\nimport { ComponentCore } from 'core/component'\nimport { Tooltip } from 'components/tooltip'\n\nexport interface SingleContainerConfigInterface<Datum> extends ContainerConfigInterface {\n /** Visualization component. Default: `undefined` */\n component?: ComponentCore<Datum>;\n /** Tooltip component. Default: `undefined` */\n tooltip?: Tooltip;\n}\n\nexport const SingleContainerDefaultConfig: SingleContainerConfigInterface<unknown> = {\n ...ContainerDefaultConfig,\n tooltip: undefined,\n}\n"],"names":[],"mappings":";;AAAA;
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/containers/single-container/config.ts"],"sourcesContent":["// Core\nimport { ContainerDefaultConfig, ContainerConfigInterface } from 'core/container/config'\nimport { ComponentCore } from 'core/component'\nimport { Tooltip } from 'components/tooltip'\nimport { Annotations } from 'components/annotations'\n\nexport interface SingleContainerConfigInterface<Datum> extends ContainerConfigInterface {\n /** Visualization component. Default: `undefined` */\n component?: ComponentCore<Datum>;\n /** Tooltip component. Default: `undefined` */\n tooltip?: Tooltip;\n /** Annotations component. Default: `undefined` */\n annotations?: Annotations | undefined;\n}\n\nexport const SingleContainerDefaultConfig: SingleContainerConfigInterface<unknown> = {\n ...ContainerDefaultConfig,\n tooltip: undefined,\n}\n"],"names":[],"mappings":";;AAAA;AAea,MAAA,4BAA4B,GACpC,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,sBAAsB,KACzB,OAAO,EAAE,SAAS,EAAA;;;;"}
|
|
@@ -43,6 +43,10 @@ class SingleContainer extends ContainerCore {
|
|
|
43
43
|
tooltip.setContainer(this._container);
|
|
44
44
|
tooltip.setComponents([this.component]);
|
|
45
45
|
}
|
|
46
|
+
const annotations = containerConfig.annotations;
|
|
47
|
+
if (annotations) {
|
|
48
|
+
this.element.appendChild(annotations.element);
|
|
49
|
+
}
|
|
46
50
|
// Defs
|
|
47
51
|
this.element.appendChild(this._svgDefs.node());
|
|
48
52
|
if (!preventRender)
|
|
@@ -71,14 +75,18 @@ class SingleContainer extends ContainerCore {
|
|
|
71
75
|
return this.width / componentWidth;
|
|
72
76
|
}
|
|
73
77
|
_preRender() {
|
|
78
|
+
var _a;
|
|
74
79
|
super._preRender();
|
|
75
80
|
this.component.setSize(this.width, this.height, this.containerWidth, this.containerHeight);
|
|
81
|
+
(_a = this.config.annotations) === null || _a === void 0 ? void 0 : _a.setSize(this.width, this.height, this.containerWidth, this.containerHeight);
|
|
76
82
|
}
|
|
77
83
|
_render(duration) {
|
|
84
|
+
var _a;
|
|
78
85
|
const { config, component } = this;
|
|
79
86
|
super._render(duration);
|
|
80
87
|
component.g.attr('transform', `translate(${config.margin.left},${config.margin.top})`);
|
|
81
88
|
component.render(duration);
|
|
89
|
+
(_a = config.annotations) === null || _a === void 0 ? void 0 : _a.render(duration);
|
|
82
90
|
if (config.tooltip)
|
|
83
91
|
config.tooltip.update();
|
|
84
92
|
}
|
|
@@ -125,11 +133,12 @@ class SingleContainer extends ContainerCore {
|
|
|
125
133
|
(_a = config.tooltip) === null || _a === void 0 ? void 0 : _a.hide();
|
|
126
134
|
}
|
|
127
135
|
destroy() {
|
|
128
|
-
var _a;
|
|
136
|
+
var _a, _b;
|
|
129
137
|
const { component, config } = this;
|
|
130
138
|
super.destroy();
|
|
131
139
|
component === null || component === void 0 ? void 0 : component.destroy();
|
|
132
140
|
(_a = config.tooltip) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
141
|
+
(_b = config.annotations) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
133
142
|
}
|
|
134
143
|
}
|
|
135
144
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/containers/single-container/index.ts"],"sourcesContent":["// Global CSS variables (side effects import)\nimport 'styles/index'\n\n// Core\nimport { ContainerCore } from 'core/container'\nimport { ComponentCore } from 'core/component'\nimport { ComponentConfigInterface } from 'core/component/config'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\n\n// Types\nimport { Sizing, ExtendedSizeComponent } from 'types/component'\n\n// Config\nimport { SingleContainerDefaultConfig, SingleContainerConfigInterface } from './config'\n\nexport class SingleContainer<Data> extends ContainerCore {\n public component: ComponentCore<Data>\n public config: SingleContainerConfigInterface<Data>\n protected _defaultConfig = SingleContainerDefaultConfig as SingleContainerConfigInterface<Data>\n\n constructor (element: HTMLElement, config?: SingleContainerConfigInterface<Data>, data?: Data) {\n super(element)\n\n if (config) {\n this.updateContainer(config, true)\n this.component = config.component\n }\n\n if (data) {\n this.setData(data, true)\n }\n\n // Render if component exists and has data\n if (this.component?.datamodel.data) this.render()\n }\n\n public setData (data: Data, preventRender?: boolean): void {\n const { config } = this\n\n if (this.component) this.component.setData(data)\n if (!preventRender) this.render()\n config.tooltip?.hide()\n }\n\n public updateContainer (containerConfig: SingleContainerConfigInterface<Data>, preventRender?: boolean): void {\n super.updateContainer(containerConfig)\n this._removeAllChildren()\n\n this.component = containerConfig.component\n if (containerConfig.sizing) this.component.sizing = containerConfig.sizing\n this.element.appendChild(this.component.element)\n\n const tooltip = containerConfig.tooltip\n if (tooltip) {\n if (!tooltip.hasContainer()) tooltip.setContainer(this._container)\n tooltip.setComponents([this.component])\n }\n\n // Defs\n this.element.appendChild(this._svgDefs.node())\n\n if (!preventRender) this.render()\n }\n\n public updateComponent (componentConfig: ComponentConfigInterface, preventRender?: boolean): void {\n this.component.setConfig(componentConfig)\n if (!preventRender) this.render()\n }\n\n public update (\n containerConfig: SingleContainerConfigInterface<Data>,\n componentConfig?: ComponentConfigInterface,\n data?: Data\n ): void {\n if (containerConfig) this.updateContainer(containerConfig, true)\n if (componentConfig) this.updateComponent(componentConfig, true)\n if (data) this.setData(data, true)\n this.render()\n }\n\n public getFitWidthScale (): number {\n const { config, component } = this\n\n const extendedSizeComponent = component as ExtendedSizeComponent\n if (!extendedSizeComponent.getWidth) return 1\n\n const componentWidth = extendedSizeComponent.getWidth() + config.margin.left + config.margin.right\n return this.width / componentWidth\n }\n\n protected _preRender (): void {\n super._preRender()\n this.component.setSize(this.width, this.height, this.containerWidth, this.containerHeight)\n }\n\n protected _render (duration?: number): void {\n const { config, component } = this\n super._render(duration)\n\n component.g.attr('transform', `translate(${config.margin.left},${config.margin.top})`)\n component.render(duration)\n\n if (config.tooltip) config.tooltip.update()\n }\n\n // Re-defining the `render()` function to handle different sizing techniques (`Sizing.Extend` and `Sizing.FitWidth`)\n // Not calling `super.render()` because we don't want it to interfere with setting the SVG size here.\n public render (duration = this.config.duration): void {\n const { config, component } = this\n\n if (config.sizing === Sizing.Extend || config.sizing === Sizing.FitWidth) {\n const fitToWidth = config.sizing === Sizing.FitWidth\n const extendedSizeComponent = component as ExtendedSizeComponent\n\n const componentWidth = extendedSizeComponent.getWidth() + config.margin.left + config.margin.right\n const componentHeight = extendedSizeComponent.getHeight() + config.margin.top + config.margin.bottom\n const scale = fitToWidth ? this.getFitWidthScale() : 1\n\n const currentWidth = this.svg.attr('width')\n const currentHeight = this.svg.attr('height')\n const scaledWidth = componentWidth * scale\n const scaledHeight = componentHeight * scale\n const animated = currentWidth || currentHeight\n\n smartTransition(this.svg, animated ? duration : 0)\n .attr('width', scaledWidth)\n .attr('height', scaledHeight)\n .attr('viewBox', `${0} ${0} ${componentWidth} ${fitToWidth ? scaledHeight : componentHeight}`)\n .attr('preserveAspectRatio', 'xMinYMin')\n } else {\n this.svg\n .attr('width', this.config.width || this.containerWidth)\n .attr('height', this.config.height || this.containerHeight)\n }\n\n // Set up Resize Observer\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 protected _onResize (): void {\n const { config } = this\n super._onResize()\n config.tooltip?.hide()\n }\n\n public destroy (): void {\n const { component, config } = this\n super.destroy()\n\n component?.destroy()\n config.tooltip?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CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAO,EAAE,CAAA;KAC1B;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/containers/single-container/index.ts"],"sourcesContent":["// Global CSS variables (side effects import)\nimport 'styles/index'\n\n// Core\nimport { ContainerCore } from 'core/container'\nimport { ComponentCore } from 'core/component'\nimport { ComponentConfigInterface } from 'core/component/config'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\n\n// Types\nimport { Sizing, ExtendedSizeComponent } from 'types/component'\n\n// Config\nimport { SingleContainerDefaultConfig, SingleContainerConfigInterface } from './config'\n\nexport class SingleContainer<Data> extends ContainerCore {\n public component: ComponentCore<Data>\n public config: SingleContainerConfigInterface<Data>\n protected _defaultConfig = SingleContainerDefaultConfig as SingleContainerConfigInterface<Data>\n\n constructor (element: HTMLElement, config?: SingleContainerConfigInterface<Data>, data?: Data) {\n super(element)\n\n if (config) {\n this.updateContainer(config, true)\n this.component = config.component\n }\n\n if (data) {\n this.setData(data, true)\n }\n\n // Render if component exists and has data\n if (this.component?.datamodel.data) this.render()\n }\n\n public setData (data: Data, preventRender?: boolean): void {\n const { config } = this\n\n if (this.component) this.component.setData(data)\n if (!preventRender) this.render()\n config.tooltip?.hide()\n }\n\n public updateContainer (containerConfig: SingleContainerConfigInterface<Data>, preventRender?: boolean): void {\n super.updateContainer(containerConfig)\n this._removeAllChildren()\n\n this.component = containerConfig.component\n if (containerConfig.sizing) this.component.sizing = containerConfig.sizing\n this.element.appendChild(this.component.element)\n\n const tooltip = containerConfig.tooltip\n if (tooltip) {\n if (!tooltip.hasContainer()) tooltip.setContainer(this._container)\n tooltip.setComponents([this.component])\n }\n\n const annotations = containerConfig.annotations\n if (annotations) {\n this.element.appendChild(annotations.element)\n }\n\n // Defs\n this.element.appendChild(this._svgDefs.node())\n\n if (!preventRender) this.render()\n }\n\n public updateComponent (componentConfig: ComponentConfigInterface, preventRender?: boolean): void {\n this.component.setConfig(componentConfig)\n if (!preventRender) this.render()\n }\n\n public update (\n containerConfig: SingleContainerConfigInterface<Data>,\n componentConfig?: ComponentConfigInterface,\n data?: Data\n ): void {\n if (containerConfig) this.updateContainer(containerConfig, true)\n if (componentConfig) this.updateComponent(componentConfig, true)\n if (data) this.setData(data, true)\n this.render()\n }\n\n public getFitWidthScale (): number {\n const { config, component } = this\n\n const extendedSizeComponent = component as ExtendedSizeComponent\n if (!extendedSizeComponent.getWidth) return 1\n\n const componentWidth = extendedSizeComponent.getWidth() + config.margin.left + config.margin.right\n return this.width / componentWidth\n }\n\n protected _preRender (): void {\n super._preRender()\n this.component.setSize(this.width, this.height, this.containerWidth, this.containerHeight)\n this.config.annotations?.setSize(this.width, this.height, this.containerWidth, this.containerHeight)\n }\n\n protected _render (duration?: number): void {\n const { config, component } = this\n super._render(duration)\n\n component.g.attr('transform', `translate(${config.margin.left},${config.margin.top})`)\n component.render(duration)\n config.annotations?.render(duration)\n\n if (config.tooltip) config.tooltip.update()\n }\n\n // Re-defining the `render()` function to handle different sizing techniques (`Sizing.Extend` and `Sizing.FitWidth`)\n // Not calling `super.render()` because we don't want it to interfere with setting the SVG size here.\n public render (duration = this.config.duration): void {\n const { config, component } = this\n\n if (config.sizing === Sizing.Extend || config.sizing === Sizing.FitWidth) {\n const fitToWidth = config.sizing === Sizing.FitWidth\n const extendedSizeComponent = component as ExtendedSizeComponent\n\n const componentWidth = extendedSizeComponent.getWidth() + config.margin.left + config.margin.right\n const componentHeight = extendedSizeComponent.getHeight() + config.margin.top + config.margin.bottom\n const scale = fitToWidth ? this.getFitWidthScale() : 1\n\n const currentWidth = this.svg.attr('width')\n const currentHeight = this.svg.attr('height')\n const scaledWidth = componentWidth * scale\n const scaledHeight = componentHeight * scale\n const animated = currentWidth || currentHeight\n\n smartTransition(this.svg, animated ? duration : 0)\n .attr('width', scaledWidth)\n .attr('height', scaledHeight)\n .attr('viewBox', `${0} ${0} ${componentWidth} ${fitToWidth ? scaledHeight : componentHeight}`)\n .attr('preserveAspectRatio', 'xMinYMin')\n } else {\n this.svg\n .attr('width', this.config.width || this.containerWidth)\n .attr('height', this.config.height || this.containerHeight)\n }\n\n // Set up Resize Observer\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 protected _onResize (): void {\n const { config } = this\n super._onResize()\n config.tooltip?.hide()\n }\n\n public destroy (): void {\n const { component, config } = this\n super.destroy()\n\n component?.destroy()\n config.tooltip?.destroy()\n config.annotations?.destroy()\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;AAiBM,MAAO,eAAsB,SAAQ,aAAa,CAAA;AAKtD,IAAA,WAAA,CAAa,OAAoB,EAAE,MAA6C,EAAE,IAAW,EAAA;;QAC3F,KAAK,CAAC,OAAO,CAAC,CAAA;QAHN,IAAc,CAAA,cAAA,GAAG,4BAAoE,CAAA;AAK7F,QAAA,IAAI,MAAM,EAAE;AACV,YAAA,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAClC,YAAA,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;AAClC,SAAA;AAED,QAAA,IAAI,IAAI,EAAE;AACR,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACzB,SAAA;;AAGD,QAAA,IAAI,MAAA,IAAI,CAAC,SAAS,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,SAAS,CAAC,IAAI;YAAE,IAAI,CAAC,MAAM,EAAE,CAAA;KAClD;IAEM,OAAO,CAAE,IAAU,EAAE,aAAuB,EAAA;;AACjD,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,IAAI,IAAI,CAAC,SAAS;AAAE,YAAA,IAAI,CAAC,SAA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AAA;;QAGD,IAAI,CAAC,IAAI,CAAC,eAAe;YAAE,IAAI,CAAC,oBAAoB,EAAE,CAAA;;AAGtD,QAAA,oBAAoB,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;AACnD,QAAA,IAAI,CAAC,wBAAwB,GAAG,qBAAqB,CAAC,MAAK;YACzD,IAAI,CAAC,UAAU,EAAE,CAAA;AACjB,YAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AACxB,SAAC,CAAC,CAAA;KACH;IAES,SAAS,GAAA;;AACjB,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QACvB,KAAK,CAAC,SAAS,EAAE,CAAA;AACjB,QAAA,CAAA,EAAA,GAAA,MAAM,CAAC,OAAO,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAI,EAAE,CAAA;KACvB;IAEM,OAAO,GAAA;;AACZ,QAAA,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAClC,KAAK,CAAC,OAAO,EAAE,CAAA;AAEf,QAAA,SAAS,aAAT,SAAS,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAT,SAAS,CAAE,OAAO,EAAE,CAAA;AACpB,QAAA,CAAA,EAAA,GAAA,MAAM,CAAC,OAAO,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAO,EAAE,CAAA;AACzB,QAAA,CAAA,EAAA,GAAA,MAAM,CAAC,WAAW,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAO,EAAE,CAAA;KAC9B;AACF;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { XYComponentCore } from "../../core/xy-component";
|
|
2
2
|
import { ContainerConfigInterface } from "../../core/container/config";
|
|
3
|
+
import { Annotations } from "../../components/annotations";
|
|
3
4
|
import { Tooltip } from "../../components/tooltip";
|
|
4
5
|
import { Axis } from "../../components/axis";
|
|
5
6
|
import { Crosshair } from "../../components/crosshair";
|
|
@@ -77,5 +78,7 @@ export interface XYContainerConfigInterface<Datum> extends ContainerConfigInterf
|
|
|
77
78
|
preventEmptyDomain?: boolean | null;
|
|
78
79
|
/** Sets the Y scale domain based on the current X scale domain (not the whole dataset). Default: `false` */
|
|
79
80
|
scaleByDomain?: boolean;
|
|
81
|
+
/** Annotations component. Default: `undefined` */
|
|
82
|
+
annotations?: Annotations | undefined;
|
|
80
83
|
}
|
|
81
84
|
export declare const XYContainerDefaultConfig: XYContainerConfigInterface<unknown>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContainerDefaultConfig } from '../../core/container/config.js';
|
|
2
2
|
import { Direction } from '../../types/direction.js';
|
|
3
3
|
|
|
4
|
-
const XYContainerDefaultConfig = Object.assign(Object.assign({}, ContainerDefaultConfig), { components: [], tooltip: undefined, crosshair: undefined, xAxis: undefined, yAxis: undefined, autoMargin: true, xScale: undefined, xDomain: undefined, xDomainMinConstraint: undefined, xDomainMaxConstraint: undefined, xRange: undefined, yScale: undefined, yDomain: undefined, yDomainMinConstraint: undefined, yDomainMaxConstraint: undefined, yRange: undefined, yDirection: Direction.North, preventEmptyDomain: null, scaleByDomain: false });
|
|
4
|
+
const XYContainerDefaultConfig = Object.assign(Object.assign({}, ContainerDefaultConfig), { components: [], tooltip: undefined, crosshair: undefined, xAxis: undefined, yAxis: undefined, autoMargin: true, xScale: undefined, xDomain: undefined, xDomainMinConstraint: undefined, xDomainMaxConstraint: undefined, xRange: undefined, yScale: undefined, yDomain: undefined, yDomainMinConstraint: undefined, yDomainMaxConstraint: undefined, yRange: undefined, yDirection: Direction.North, preventEmptyDomain: null, scaleByDomain: false, annotations: undefined });
|
|
5
5
|
|
|
6
6
|
export { XYContainerDefaultConfig };
|
|
7
7
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/containers/xy-container/config.ts"],"sourcesContent":["// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { ContainerDefaultConfig, ContainerConfigInterface } from 'core/container/config'\nimport { Tooltip } from 'components/tooltip'\
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/containers/xy-container/config.ts"],"sourcesContent":["// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { ContainerDefaultConfig, ContainerConfigInterface } from 'core/container/config'\n\n// Components\nimport { Annotations } from 'components/annotations'\nimport { Tooltip } from 'components/tooltip'\nimport { Axis } from 'components/axis'\nimport { Crosshair } from 'components/crosshair'\n\n// Types\nimport { ContinuousScale } from 'types/scale'\nimport { Direction } from 'types/direction'\n\nexport interface XYContainerConfigInterface<Datum> extends ContainerConfigInterface {\n /** An array of visualization components. Default: `[]` */\n components?: XYComponentCore<Datum>[];\n\n /** Scale for X dimension, e.g. Scale.scaleLinear().\n * If set, this value will override the components' xScale and they will have a single shared xScale instance.\n * By default the components have their own scale instances but their `domain` and `range` values are synchronized.\n * Default: `undefined` */\n xScale?: ContinuousScale;\n /** Scale domain (data extent) for X dimension. By default this value is calculated automatically based on data. */\n xDomain?: [number | undefined, number | undefined];\n /** Constraint the minimum value of the X scale domain. Useful when the data is plotted along the X axis.\n * For example, imagine that you have a chart with dynamic data that has negative values. When values are small\n * (let's say in the range of [-0.01, 0]), you might still want the chart to display some meaningful value range (e.g. [-1, 0]). That can\n * be achieved by setting `xDomainMinConstraint` to `[undefined, -1]`. In addition to that, if you want to cut off the\n * values that are too low (let's say lower than -100), you can set the constraint to `[-100, -1]`\n * Default: `undefined` */\n xDomainMinConstraint?: [number | undefined, number | undefined];\n /** Constraint the minimum value of the X scale domain. Useful when the data is plotted along the X axis.\n * For example, imagine that you have a chart with dynamic data. When values are small\n * (let's say < 0.01), you might still want the chart to display some meaningful value range (e.g. [0, 1]). That can\n * be achieved by setting `xDomainMaxConstraint` to `[1, undefined]`. In addition to that, if you want to cut off the\n * values that are too high (let's say higher than 100), you can set the constraint to `[1, 100]`\n * Default: `undefined` */\n xDomainMaxConstraint?: [number | undefined, number | undefined];\n /** Force set the X scale range (in the screen space). By default the range is calculated automatically based on the\n * chart's set up */\n xRange?: [number, number];\n\n /** Scale for Y dimension, e.g. Scale.scaleLinear().\n * If set, this value will override the components' yScale and they will have a single shared yScale instance.\n * By default the components have their own scale instances but their `domain` and `range` values are synchronized.\n * Default: `undefined` */\n yScale?: ContinuousScale;\n /** Scale domain (data extent) for Y dimension. By default this value is calculated automatically based on data. */\n yDomain?: [number | undefined, number | undefined];\n /** Constraint the minimum value of the Y scale domain.\n * For example, imagine that you have a chart with dynamic data that has negative values. When values are small\n * (let's say in the range of [-0.01, 0]), you might still want the chart to display some meaningful value range (e.g. [-1, 0]). That can\n * be achieved by setting `yDomainMinConstraint` to `[undefined, -1]`. In addition to that, if you want to cut off the\n * values that are too low (let's say lower than -100), you can set the constraint to `[-100, -1]`\n * Default: `undefined` */\n yDomainMinConstraint?: [number | undefined, number | undefined];\n /** Constraint the minimum value of the Y scale domain.\n * For example, imagine that you have a chart with dynamic data. When values are small\n * (let's say < 0.01), you might still want the chart to display some meaningful value range (e.g. [0, 1]). That can\n * be achieved by setting `yDomainMaxConstraint` to `[1, undefined]`. In addition to that, if you want to cut off the\n * values that are too high (let's say higher than 100), you can set the constraint to `[1, 100]`\n * Default: `undefined` */\n yDomainMaxConstraint?: [number | undefined, number | undefined];\n /** Force set the Y scale range (in the screen space). By default the range is calculated automatically based on the\n * chart's set up */\n yRange?: [number, number];\n /** Y Axis direction. Default: `Direction.North` */\n yDirection?: Direction.South | Direction.North | string;\n\n /** X Axis component instance. Default: `undefined` */\n xAxis?: Axis<Datum>;\n /** Y Axis component instance. Default: `undefined` */\n yAxis?: Axis<Datum>;\n /** Enables automatic calculation of chart margins based on the size of the axes. Default: `true` */\n autoMargin?: boolean;\n /** Tooltip component. Default: `undefined` */\n tooltip?: Tooltip | undefined;\n /** Crosshair component. Default: `undefined` */\n crosshair?: Crosshair<Datum> | undefined;\n /** Prevents the chart domain from being empty (when domain's min and max values are equal).\n * That usually happens when all the data values are equal or when there's no data.\n * Setting to `true` will automatically extend the domain by `+1` when the domain is empty (domain start equals domain end).\n * Setting to `null` will extend the empty X domain, but only when there's no data.\n * Setting to `false` will keep the domain as is.\n * Default: `null` */\n preventEmptyDomain?: boolean | null;\n /** Sets the Y scale domain based on the current X scale domain (not the whole dataset). Default: `false` */\n scaleByDomain?: boolean;\n /** Annotations component. Default: `undefined` */\n annotations?: Annotations | undefined;\n}\n\n\nexport const XYContainerDefaultConfig: XYContainerConfigInterface<unknown> = {\n ...ContainerDefaultConfig,\n components: [],\n tooltip: undefined,\n crosshair: undefined,\n xAxis: undefined,\n yAxis: undefined,\n autoMargin: true,\n\n xScale: undefined,\n xDomain: undefined,\n xDomainMinConstraint: undefined,\n xDomainMaxConstraint: undefined,\n xRange: undefined,\n\n yScale: undefined,\n yDomain: undefined,\n yDomainMinConstraint: undefined,\n yDomainMaxConstraint: undefined,\n yRange: undefined,\n yDirection: Direction.North,\n\n preventEmptyDomain: null,\n scaleByDomain: false,\n annotations: undefined,\n}\n\n"],"names":[],"mappings":";;;AA8Fa,MAAA,wBAAwB,mCAChC,sBAAsB,CAAA,EAAA,EACzB,UAAU,EAAE,EAAE,EACd,OAAO,EAAE,SAAS,EAClB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,IAAI,EAEhB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,SAAS,EAClB,oBAAoB,EAAE,SAAS,EAC/B,oBAAoB,EAAE,SAAS,EAC/B,MAAM,EAAE,SAAS,EAEjB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,SAAS,EAClB,oBAAoB,EAAE,SAAS,EAC/B,oBAAoB,EAAE,SAAS,EAC/B,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,SAAS,CAAC,KAAK,EAE3B,kBAAkB,EAAE,IAAI,EACxB,aAAa,EAAE,KAAK,EACpB,WAAW,EAAE,SAAS;;;;"}
|
|
@@ -6,7 +6,7 @@ import { CoreDataModel } from '../../data-models/core.js';
|
|
|
6
6
|
import { AxisType } from '../../components/axis/types.js';
|
|
7
7
|
import { ScaleDimension } from '../../types/scale.js';
|
|
8
8
|
import { Direction } from '../../types/direction.js';
|
|
9
|
-
import { clamp,
|
|
9
|
+
import { clamp, clean, flatten } from '../../utils/data.js';
|
|
10
10
|
import { guid } from '../../utils/misc.js';
|
|
11
11
|
import { XYContainerDefaultConfig } from './config.js';
|
|
12
12
|
|
|
@@ -113,6 +113,11 @@ class XYContainer extends ContainerCore {
|
|
|
113
113
|
crosshair.tooltip = tooltip;
|
|
114
114
|
this.element.appendChild(crosshair.element);
|
|
115
115
|
}
|
|
116
|
+
// Set up annotations
|
|
117
|
+
const annotations = containerConfig.annotations;
|
|
118
|
+
if (annotations) {
|
|
119
|
+
this.element.appendChild(annotations.element);
|
|
120
|
+
}
|
|
116
121
|
// Clipping path
|
|
117
122
|
this.element.appendChild(this._clipPath.node());
|
|
118
123
|
// Defs
|
|
@@ -149,11 +154,16 @@ class XYContainer extends ContainerCore {
|
|
|
149
154
|
if (config.autoMargin) {
|
|
150
155
|
this._setAutoMargin();
|
|
151
156
|
}
|
|
157
|
+
// Pass size to the components
|
|
158
|
+
const components = clean([...this.components, config.xAxis, config.yAxis, config.crosshair, config.annotations]);
|
|
159
|
+
for (const c of components) {
|
|
160
|
+
c.setSize(this.width, this.height, this.containerWidth, this.containerHeight);
|
|
161
|
+
}
|
|
152
162
|
// Update Scales of all the components at once to calculate required paddings and sync them
|
|
153
163
|
this._updateScales(...this.components, config.xAxis, config.yAxis, config.crosshair);
|
|
154
164
|
}
|
|
155
165
|
_render(customDuration) {
|
|
156
|
-
var _a, _b, _c;
|
|
166
|
+
var _a, _b, _c, _d, _e;
|
|
157
167
|
const { config } = this;
|
|
158
168
|
super._render();
|
|
159
169
|
// Get chart total margin after auto margin calculations
|
|
@@ -166,7 +176,7 @@ class XYContainer extends ContainerCore {
|
|
|
166
176
|
c.render(customDuration);
|
|
167
177
|
}
|
|
168
178
|
this._renderAxes(this._firstRender ? 0 : customDuration);
|
|
169
|
-
// Clip
|
|
179
|
+
// Clip RectsetSize
|
|
170
180
|
// Extending the clipping path to allow small overflow (e.g. Line will looks better that way when it touches the edges)
|
|
171
181
|
const clipPathExtension = 2;
|
|
172
182
|
this._clipPath.select('rect')
|
|
@@ -195,6 +205,8 @@ class XYContainer extends ContainerCore {
|
|
|
195
205
|
.style('-webkit-clip-path', `url(#${this._clipPathId})`);
|
|
196
206
|
crosshair.hide();
|
|
197
207
|
}
|
|
208
|
+
(_d = config.annotations) === null || _d === void 0 ? void 0 : _d.g.attr('transform', `translate(${margin.left},${margin.top})`);
|
|
209
|
+
(_e = config.annotations) === null || _e === void 0 ? void 0 : _e.render();
|
|
198
210
|
this._firstRender = false;
|
|
199
211
|
}
|
|
200
212
|
_updateScales(...components) {
|
|
@@ -254,7 +266,6 @@ class XYContainer extends ContainerCore {
|
|
|
254
266
|
if (isYDirectionSouth)
|
|
255
267
|
yRange.reverse();
|
|
256
268
|
for (const c of components) {
|
|
257
|
-
c.setSize(this.width, this.height, this.containerWidth, this.containerHeight);
|
|
258
269
|
c.setScaleRange(ScaleDimension.X, (_e = config.xRange) !== null && _e !== void 0 ? _e : xRange);
|
|
259
270
|
c.setScaleRange(ScaleDimension.Y, (_f = config.yRange) !== null && _f !== void 0 ? _f : yRange);
|
|
260
271
|
}
|
|
@@ -325,12 +336,13 @@ class XYContainer extends ContainerCore {
|
|
|
325
336
|
};
|
|
326
337
|
}
|
|
327
338
|
destroy() {
|
|
328
|
-
const { components, config: { tooltip, crosshair, xAxis, yAxis } } = this;
|
|
339
|
+
const { components, config: { tooltip, crosshair, annotations, xAxis, yAxis } } = this;
|
|
329
340
|
super.destroy();
|
|
330
341
|
for (const c of components)
|
|
331
342
|
c === null || c === void 0 ? void 0 : c.destroy();
|
|
332
343
|
tooltip === null || tooltip === void 0 ? void 0 : tooltip.destroy();
|
|
333
344
|
crosshair === null || crosshair === void 0 ? void 0 : crosshair.destroy();
|
|
345
|
+
annotations === null || annotations === void 0 ? void 0 : annotations.destroy();
|
|
334
346
|
xAxis === null || xAxis === void 0 ? void 0 : xAxis.destroy();
|
|
335
347
|
yAxis === null || yAxis === void 0 ? void 0 : yAxis.destroy();
|
|
336
348
|
}
|