@unovis/ts 1.1.1-beta.6 → 1.1.1-beta.8
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.
|
@@ -7,7 +7,7 @@ export declare class ContainerCore {
|
|
|
7
7
|
config: ContainerConfig;
|
|
8
8
|
protected _container: HTMLElement;
|
|
9
9
|
protected _requestedAnimationFrame: number;
|
|
10
|
-
|
|
10
|
+
protected _isFirstRender: boolean;
|
|
11
11
|
private _containerSize;
|
|
12
12
|
private _resizeObserver;
|
|
13
13
|
static DEFAULT_CONTAINER_HEIGHT: number;
|
package/core/container/index.js
CHANGED
|
@@ -24,14 +24,11 @@ class ContainerCore {
|
|
|
24
24
|
this.config = new ConfigModel().init(config);
|
|
25
25
|
}
|
|
26
26
|
_render(duration) {
|
|
27
|
-
if (this._isFirstRender) {
|
|
28
|
-
this._setUpResizeObserver();
|
|
29
|
-
this._isFirstRender = false;
|
|
30
|
-
}
|
|
31
27
|
if (this.config.svgDefs) {
|
|
32
28
|
this.svg.select('.svgDefs').remove();
|
|
33
29
|
this.svg.append('defs').attr('class', 'svgDefs').html(this.config.svgDefs);
|
|
34
30
|
}
|
|
31
|
+
this._isFirstRender = false;
|
|
35
32
|
}
|
|
36
33
|
render(duration = this.config.duration) {
|
|
37
34
|
const width = this.config.width || this.containerWidth;
|
|
@@ -42,6 +39,10 @@ class ContainerCore {
|
|
|
42
39
|
this.svg
|
|
43
40
|
.attr('width', width)
|
|
44
41
|
.attr('height', height);
|
|
42
|
+
// Set up Resize Observer. We do it in `render()` to capture container size change if it happened
|
|
43
|
+
// in the next animation frame after the initial `render` was called.
|
|
44
|
+
if (!this._resizeObserver)
|
|
45
|
+
this._setUpResizeObserver();
|
|
45
46
|
// Schedule the actual rendering in the next frame
|
|
46
47
|
cancelAnimationFrame(this._requestedAnimationFrame);
|
|
47
48
|
this._requestedAnimationFrame = requestAnimationFrame(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/core/container/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport { ResizeObserver } from '@juggle/resize-observer'\n\n// Types\nimport { Sizing } from 'types/component'\n\n// Utils\nimport { isEqual, clamp } from 'utils/data'\n\n// Config\nimport { ContainerConfig, ContainerConfigInterface } from './config'\n\nexport class ContainerCore {\n svg: Selection<SVGSVGElement, unknown, null, undefined>\n element: SVGSVGElement\n prevConfig: ContainerConfig\n config: ContainerConfig\n\n protected _container: HTMLElement\n protected _requestedAnimationFrame: number\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/core/container/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport { ResizeObserver } from '@juggle/resize-observer'\n\n// Types\nimport { Sizing } from 'types/component'\n\n// Utils\nimport { isEqual, clamp } from 'utils/data'\n\n// Config\nimport { ContainerConfig, ContainerConfigInterface } from './config'\n\nexport class ContainerCore {\n svg: Selection<SVGSVGElement, unknown, null, undefined>\n element: SVGSVGElement\n prevConfig: ContainerConfig\n config: ContainerConfig\n\n protected _container: HTMLElement\n protected _requestedAnimationFrame: number\n protected _isFirstRender = true\n private _containerSize: { width: number; height: number }\n private _resizeObserver: ResizeObserver | undefined\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static DEFAULT_CONTAINER_HEIGHT = 300\n\n constructor (element: HTMLElement) {\n this._requestedAnimationFrame = null\n this._container = element\n\n // Create SVG element for visualizations\n this.svg = select(this._container).append('svg')\n // We set `display` to `block` because inline elements have an invisible\n // inline space that adds 4px to the height of the container\n .style('display', 'block')\n .attr('xmlns', 'http://www.w3.org/2000/svg')\n .attr('height', ContainerCore.DEFAULT_CONTAINER_HEIGHT)\n\n this.element = this.svg.node()\n }\n\n updateContainer<T extends ContainerConfigInterface> (config: T): void {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const ConfigModel = (this.config.constructor as typeof ContainerConfig)\n this.prevConfig = this.config\n this.config = new ConfigModel().init(config)\n }\n\n _render (duration?: number): void {\n if (this.config.svgDefs) {\n this.svg.select('.svgDefs').remove()\n this.svg.append('defs').attr('class', 'svgDefs').html(this.config.svgDefs)\n }\n\n this._isFirstRender = false\n }\n\n render (duration = this.config.duration): void {\n const width = this.config.width || this.containerWidth\n const height = this.config.height || this.containerHeight\n\n // We set SVG size in `render()` instead of `_render()`, because the size values in pixels will become\n // available only in the next animation when being accessed via `element.clientWidth` and `element.clientHeight`,\n // and we rely on those values when setting width and size of the components.\n this.svg\n .attr('width', width)\n .attr('height', height)\n\n // Set up Resize Observer. We do it in `render()` to capture container size change if it happened\n // in the next animation frame after the initial `render` was called.\n if (!this._resizeObserver) this._setUpResizeObserver()\n\n // Schedule the actual rendering in the next frame\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._requestedAnimationFrame = requestAnimationFrame(() => {\n this._render(duration)\n })\n }\n\n get containerWidth (): number {\n return this.config.width\n ? this.element.clientWidth\n : clamp(this._container.clientWidth || this._container.getBoundingClientRect().width, 0, Number.POSITIVE_INFINITY)\n }\n\n get containerHeight (): number {\n return this.config.height\n ? this.element.clientHeight\n : clamp(this._container.clientHeight || this._container.getBoundingClientRect().height, 0, Number.POSITIVE_INFINITY)\n }\n\n get width (): number {\n return clamp(this.containerWidth - this.config.margin.left - this.config.margin.right, 0, Number.POSITIVE_INFINITY)\n }\n\n get height (): number {\n return clamp(this.containerHeight - this.config.margin.top - this.config.margin.bottom, 0, Number.POSITIVE_INFINITY)\n }\n\n removeAllChildren (): void {\n while (this.element.firstChild) {\n this.element.removeChild(this.element.firstChild)\n }\n }\n\n _onResize (): void {\n const { config } = this\n const redrawOnResize = config.sizing === Sizing.Fit || config.sizing === Sizing.FitWidth\n if (redrawOnResize) this.render(0)\n }\n\n _setUpResizeObserver (): void {\n const containerRect = this._container.getBoundingClientRect()\n this._containerSize = { width: containerRect.width, height: containerRect.height }\n\n this._resizeObserver = new ResizeObserver((entries, observer) => {\n const resizedContainerRect = this._container.getBoundingClientRect()\n const resizedContainerSize = { width: resizedContainerRect.width, height: resizedContainerRect.height }\n const hasSizeChanged = !isEqual(this._containerSize, resizedContainerSize)\n // Do resize only if element is attached to the DOM\n // will come in useful when some ancestor of container becomes detached\n if (hasSizeChanged && resizedContainerSize.width && resizedContainerSize.height) {\n this._containerSize = resizedContainerSize\n this._onResize()\n }\n })\n this._resizeObserver.observe(this._container)\n }\n\n destroy (): void {\n cancelAnimationFrame(this._requestedAnimationFrame)\n this._resizeObserver?.disconnect()\n this.svg.remove()\n }\n}\n"],"names":[],"mappings":";;;;;MAYa,aAAa,CAAA;AAexB,IAAA,WAAA,CAAa,OAAoB,EAAA;QAPvB,IAAc,CAAA,cAAA,GAAG,IAAI,CAAA;AAQ7B,QAAA,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAA;AACpC,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;;AAGzB,QAAA,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;;;AAG7C,aAAA,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC;AACzB,aAAA,IAAI,CAAC,OAAO,EAAE,4BAA4B,CAAC;AAC3C,aAAA,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAA;QAEzD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;KAC/B;AAED,IAAA,eAAe,CAAsC,MAAS,EAAA;;AAE5D,QAAA,MAAM,WAAW,GAAI,IAAI,CAAC,MAAM,CAAC,WAAsC,CAAA;AACvE,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;KAC7C;AAED,IAAA,OAAO,CAAE,QAAiB,EAAA;AACxB,QAAA,IAAI,IAAI,CAAC,MAAM,CAAC,OAA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2
|
"name": "@unovis/ts",
|
|
3
3
|
"description": "Modular data visualization framework for React, Angular, Svelte, and vanilla TypeScript or JavaScript",
|
|
4
|
-
"version": "1.1.1-beta.
|
|
4
|
+
"version": "1.1.1-beta.8",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/f5/unovis.git",
|