@unovis/ts 1.6.2-pre.7 → 1.6.2
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/tooltip/index.js +2 -2
- package/components/tooltip/index.js.map +1 -1
- package/components/treemap/config.d.ts +17 -10
- package/components/treemap/config.js +2 -1
- package/components/treemap/config.js.map +1 -1
- package/components/treemap/index.d.ts +0 -2
- package/components/treemap/index.js +78 -91
- package/components/treemap/index.js.map +1 -1
- package/components/treemap/style.d.ts +3 -8
- package/components/treemap/style.js +10 -15
- package/components/treemap/style.js.map +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils/color.d.ts +1 -0
- package/utils/color.js +7 -1
- package/utils/color.js.map +1 -1
- package/utils/index.js +1 -1
|
@@ -225,8 +225,8 @@ class Tooltip {
|
|
|
225
225
|
if (node !== html)
|
|
226
226
|
this.div.html('').append(() => html);
|
|
227
227
|
}
|
|
228
|
-
else if (html) {
|
|
229
|
-
this.div.html(html);
|
|
228
|
+
else if (html !== null) {
|
|
229
|
+
this.div.html(html || '');
|
|
230
230
|
}
|
|
231
231
|
this.div
|
|
232
232
|
.classed((_a = config.className) !== null && _a !== void 0 ? _a : '', Boolean(config.className))
|
|
@@ -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 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 { config: currentConfig } = this // get latest config because it could have been changed after the event was triggered\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(currentConfig.triggers)) {\n const template = currentConfig.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 (currentConfig.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,G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AAa;YAAE,OAAM;QAE1B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,IAAI,IAAG;AACxC,YAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,SAAC,CAAC,CAAA;KACH;IAEM,OAAO,GAAA;;AACZ,QAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAA;AACnC,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;AAC7C,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;AAC7C,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,EAAE,CAAA;KACnB;;AArZM,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 !== null) {\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 { config: currentConfig } = this // get latest config because it could have been changed after the event was triggered\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(currentConfig.triggers)) {\n const template = currentConfig.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 (currentConfig.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,QAA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AAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,SAAC,CAAC,CAAA;KACH;IAEM,OAAO,GAAA;;AACZ,QAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAA;AACnC,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;AAC7C,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;AAC7C,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,EAAE,CAAA;KACnB;;AArZM,OAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { ComponentConfigInterface } from "../../core/component/config";
|
|
2
2
|
import { ColorAccessor, NumericAccessor, StringAccessor } from "../../types/accessor";
|
|
3
|
+
import { FitMode, TrimMode } from "../../types/text";
|
|
3
4
|
import { TreemapNode } from './types';
|
|
4
5
|
export interface TreemapConfigInterface<Datum> extends ComponentConfigInterface {
|
|
5
6
|
id?: ((d: Datum, i: number) => string | number);
|
|
6
7
|
value?: NumericAccessor<Datum>;
|
|
7
8
|
/** Array of accessor functions to defined the nested groups. Default: `[]` */
|
|
8
9
|
layers: StringAccessor<Datum>[];
|
|
9
|
-
/**
|
|
10
|
+
/** @deprecated Define `tileLabel` instead.
|
|
11
|
+
* A function that accepts a value number and returns a string. Default: `(value: number) => `${value}`` */
|
|
10
12
|
numberFormat?: (value: number) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Function to generate the label text for each tile. Receives the `TreemapNode` and returns a `string`.
|
|
15
|
+
* Default: shows key and formatted value (e.g., "label: value").
|
|
16
|
+
*/
|
|
17
|
+
tileLabel?: (node: TreemapNode<Datum>) => string;
|
|
11
18
|
/** Color accessor function for tiles. Default: `undefined` */
|
|
12
19
|
tileColor?: ColorAccessor<TreemapNode<Datum>>;
|
|
13
20
|
/** Padding passed to D3 treemap layout. Default: `2` */
|
|
@@ -24,6 +31,10 @@ export interface TreemapConfigInterface<Datum> extends ComponentConfigInterface
|
|
|
24
31
|
labelOffsetX?: number;
|
|
25
32
|
/** Label offset in the Y direction. Default: `4` */
|
|
26
33
|
labelOffsetY?: number;
|
|
34
|
+
/** How labels should fit within tiles: wrap or trim. Applicable only for leaf nodes. Default: `FitMode.Wrap` */
|
|
35
|
+
labelFit?: FitMode;
|
|
36
|
+
/** Label trimming mode. Default: `TrimMode.Middle` */
|
|
37
|
+
labelTrimMode?: TrimMode;
|
|
27
38
|
/** Border radius of the tiles in pixels. Default: `2` */
|
|
28
39
|
tileBorderRadius?: number;
|
|
29
40
|
/** Minimum fraction of width for border radius. Default: `1/8` */
|
|
@@ -32,21 +43,17 @@ export interface TreemapConfigInterface<Datum> extends ComponentConfigInterface
|
|
|
32
43
|
enableLightnessVariance?: boolean;
|
|
33
44
|
/** Enable font size variation for leaf node labels based on value. Default: `false` */
|
|
34
45
|
enableTileLabelFontSizeVariation?: boolean;
|
|
35
|
-
/** Small font size for leaf labels (used when enableTileLabelFontSizeVariation is true). Default: `8` */
|
|
46
|
+
/** Small font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `8` */
|
|
36
47
|
tileLabelSmallFontSize?: number;
|
|
37
|
-
/** Medium font size for leaf labels (used when enableTileLabelFontSizeVariation is true). Default: `12` */
|
|
48
|
+
/** Medium font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `12` */
|
|
38
49
|
tileLabelMediumFontSize?: number;
|
|
39
|
-
/** Large font size for leaf labels (used when enableTileLabelFontSizeVariation is true). Default: `24` */
|
|
50
|
+
/** Large font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `24` */
|
|
40
51
|
tileLabelLargeFontSize?: number;
|
|
41
52
|
/** Flag for showing cursor:pointer to indicate leaf tiles are clickable. Default: `undefined` */
|
|
42
53
|
showTileClickAffordance?: boolean;
|
|
43
|
-
/** Amount of lightness variation applied to sibling tiles when enableLightnessVariance is true
|
|
54
|
+
/** Amount of lightness variation applied to sibling tiles when `enableLightnessVariance` is `true`. Default: `0.08` */
|
|
44
55
|
lightnessVariationAmount?: number;
|
|
56
|
+
/** Minimum size for labels in pixels. Default: `20` */
|
|
45
57
|
minTileSizeForLabel?: number;
|
|
46
|
-
/**
|
|
47
|
-
* Function to generate the label text for each tile. Receives the TreemapNode and returns a string.
|
|
48
|
-
* Default: shows key and formatted value (e.g., "label: value").
|
|
49
|
-
*/
|
|
50
|
-
tileLabel?: (node: TreemapNode<Datum>) => string;
|
|
51
58
|
}
|
|
52
59
|
export declare const TreemapDefaultConfig: TreemapConfigInterface<unknown>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ComponentDefaultConfig } from '../../core/component/config.js';
|
|
2
|
+
import { FitMode, TrimMode } from '../../types/text.js';
|
|
2
3
|
|
|
3
|
-
const TreemapDefaultConfig = Object.assign(Object.assign({}, ComponentDefaultConfig), { id: (d, i) => { var _a; return (_a = d.id) !== null && _a !== void 0 ? _a : i; }, value: undefined, tileColor: undefined, layers: [], tilePadding: 2, tilePaddingTop: undefined, labelInternalNodes: false, labelOffsetX: 4, labelOffsetY: 4, tileBorderRadius: 2, tileBorderRadiusFactor: 1 / 8, enableLightnessVariance: false, enableTileLabelFontSizeVariation: true, tileLabelSmallFontSize: 8, tileLabelMediumFontSize: 12, tileLabelLargeFontSize: 22, showTileClickAffordance: false, lightnessVariationAmount: 0.08, minTileSizeForLabel: 20, tileLabel:
|
|
4
|
+
const TreemapDefaultConfig = Object.assign(Object.assign({}, ComponentDefaultConfig), { id: (d, i) => { var _a; return (_a = d.id) !== null && _a !== void 0 ? _a : i; }, value: undefined, tileColor: undefined, layers: [], tilePadding: 2, tilePaddingTop: undefined, labelInternalNodes: false, labelOffsetX: 4, labelOffsetY: 4, labelFit: FitMode.Wrap, labelTrimMode: TrimMode.Middle, tileBorderRadius: 2, tileBorderRadiusFactor: 1 / 8, enableLightnessVariance: false, enableTileLabelFontSizeVariation: true, tileLabelSmallFontSize: 8, tileLabelMediumFontSize: 12, tileLabelLargeFontSize: 22, showTileClickAffordance: false, lightnessVariationAmount: 0.08, minTileSizeForLabel: 20, numberFormat: (value) => `${value}`, tileLabel: function (d) { return `${d.data.key}: ${this.numberFormat(d.value)}`; } });
|
|
4
5
|
|
|
5
6
|
export { TreemapDefaultConfig };
|
|
6
7
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/treemap/config.ts"],"sourcesContent":["import { ComponentConfigInterface, ComponentDefaultConfig } from 'core/component/config'\nimport { ColorAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\nimport { TreemapNode } from './types'\n\nexport interface TreemapConfigInterface<Datum> extends ComponentConfigInterface {\n id?: ((d: Datum, i: number) => string | number);\n /* Numeric accessor for segment size value. Default: `undefined`. */\n value?: NumericAccessor<Datum>;\n\n /** Array of accessor functions to defined the nested groups. Default: `[]` */\n layers: StringAccessor<Datum>[];\n\n /** A function that accepts a value number and returns a string. Default: `
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/treemap/config.ts"],"sourcesContent":["import { ComponentConfigInterface, ComponentDefaultConfig } from 'core/component/config'\nimport { ColorAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\nimport { FitMode, TrimMode } from 'types/text'\nimport { TreemapNode } from './types'\n\nexport interface TreemapConfigInterface<Datum> extends ComponentConfigInterface {\n id?: ((d: Datum, i: number) => string | number);\n /* Numeric accessor for segment size value. Default: `undefined`. */\n value?: NumericAccessor<Datum>;\n\n /** Array of accessor functions to defined the nested groups. Default: `[]` */\n layers: StringAccessor<Datum>[];\n\n /** @deprecated Define `tileLabel` instead.\n * A function that accepts a value number and returns a string. Default: `(value: number) => `${value}`` */\n numberFormat?: (value: number) => string;\n\n /**\n * Function to generate the label text for each tile. Receives the `TreemapNode` and returns a `string`.\n * Default: shows key and formatted value (e.g., \"label: value\").\n */\n tileLabel?: (node: TreemapNode<Datum>) => string;\n\n /** Color accessor function for tiles. Default: `undefined` */\n tileColor?: ColorAccessor<TreemapNode<Datum>>;\n\n /** Padding passed to D3 treemap layout. Default: `2` */\n tilePadding?: number;\n\n /**\n * Top padding passed to D3 treemap layout.\n * Useful to make room for internal node labels.\n * Default: `undefined`\n */\n tilePaddingTop?: number;\n\n /** Label internal nodes. Default: `false` */\n labelInternalNodes?: boolean;\n\n /** Label offset in the X direction. Default: `4` */\n labelOffsetX?: number;\n\n /** Label offset in the Y direction. Default: `4` */\n labelOffsetY?: number;\n\n /** How labels should fit within tiles: wrap or trim. Applicable only for leaf nodes. Default: `FitMode.Wrap` */\n labelFit?: FitMode;\n\n /** Label trimming mode. Default: `TrimMode.Middle` */\n labelTrimMode?: TrimMode;\n\n /** Border radius of the tiles in pixels. Default: `2` */\n tileBorderRadius?: number;\n\n /** Minimum fraction of width for border radius. Default: `1/8` */\n tileBorderRadiusFactor?: number;\n\n /** Enable lightness variance for sibling tiles. Default: `false` */\n enableLightnessVariance?: boolean;\n\n /** Enable font size variation for leaf node labels based on value. Default: `false` */\n enableTileLabelFontSizeVariation?: boolean;\n\n /** Small font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `8` */\n tileLabelSmallFontSize?: number;\n\n /** Medium font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `12` */\n tileLabelMediumFontSize?: number;\n\n /** Large font size for leaf labels (used when `enableTileLabelFontSizeVariation` is `true`). Default: `24` */\n tileLabelLargeFontSize?: number;\n\n\n /** Flag for showing cursor:pointer to indicate leaf tiles are clickable. Default: `undefined` */\n showTileClickAffordance?: boolean;\n\n /** Amount of lightness variation applied to sibling tiles when `enableLightnessVariance` is `true`. Default: `0.08` */\n lightnessVariationAmount?: number;\n\n /** Minimum size for labels in pixels. Default: `20` */\n minTileSizeForLabel?: number;\n}\n\nexport const TreemapDefaultConfig: TreemapConfigInterface<unknown> = {\n ...ComponentDefaultConfig,\n id: (d: unknown, i: number): string | number => (d as { id: string }).id ?? i,\n value: undefined,\n tileColor: undefined,\n layers: [],\n tilePadding: 2,\n tilePaddingTop: undefined,\n labelInternalNodes: false,\n labelOffsetX: 4,\n labelOffsetY: 4,\n labelFit: FitMode.Wrap,\n labelTrimMode: TrimMode.Middle,\n tileBorderRadius: 2,\n tileBorderRadiusFactor: 1 / 8,\n enableLightnessVariance: false,\n enableTileLabelFontSizeVariation: true,\n tileLabelSmallFontSize: 8,\n tileLabelMediumFontSize: 12,\n tileLabelLargeFontSize: 22,\n showTileClickAffordance: false,\n lightnessVariationAmount: 0.08,\n minTileSizeForLabel: 20,\n numberFormat: (value: number) => `${value}`,\n tileLabel: function (d: TreemapNode<unknown>): string { return `${d.data.key}: ${this.numberFormat(d.value)}` },\n}\n"],"names":[],"mappings":";;;AAmFO,MAAM,oBAAoB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC5B,sBAAsB,CACzB,EAAA,EAAA,EAAE,EAAE,CAAC,CAAU,EAAE,CAAS,eAAsB,OAAA,CAAA,EAAA,GAAC,CAAoB,CAAC,EAAE,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,CAAC,CAAA,EAAA,EAC7E,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,EAAE,EACV,WAAW,EAAE,CAAC,EACd,cAAc,EAAE,SAAS,EACzB,kBAAkB,EAAE,KAAK,EACzB,YAAY,EAAE,CAAC,EACf,YAAY,EAAE,CAAC,EACf,QAAQ,EAAE,OAAO,CAAC,IAAI,EACtB,aAAa,EAAE,QAAQ,CAAC,MAAM,EAC9B,gBAAgB,EAAE,CAAC,EACnB,sBAAsB,EAAE,CAAC,GAAG,CAAC,EAC7B,uBAAuB,EAAE,KAAK,EAC9B,gCAAgC,EAAE,IAAI,EACtC,sBAAsB,EAAE,CAAC,EACzB,uBAAuB,EAAE,EAAE,EAC3B,sBAAsB,EAAE,EAAE,EAC1B,uBAAuB,EAAE,KAAK,EAC9B,wBAAwB,EAAE,IAAI,EAC9B,mBAAmB,EAAE,EAAE,EACvB,YAAY,EAAE,CAAC,KAAa,KAAK,GAAG,KAAK,CAAA,CAAE,EAC3C,SAAS,EAAE,UAAU,CAAuB,EAAY,EAAA,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAA,EAAA,EAAK,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAE,CAAA,CAAA,EAAE;;;;"}
|
|
@@ -7,8 +7,6 @@ export declare class Treemap<Datum> extends ComponentCore<Datum[], TreemapConfig
|
|
|
7
7
|
static selectors: typeof s;
|
|
8
8
|
protected _defaultConfig: TreemapConfigInterface<Datum>;
|
|
9
9
|
config: TreemapConfigInterface<Datum>;
|
|
10
|
-
/** Default number format for tile labels. */
|
|
11
|
-
private _defaultNumberFormat;
|
|
12
10
|
datamodel: SeriesDataModel<Datum>;
|
|
13
11
|
tiles: Selection<SVGGElement, unknown, SVGGElement, unknown>;
|
|
14
12
|
private _isTileLargeEnough;
|
|
@@ -5,14 +5,15 @@ import { scaleLinear, scaleThreshold } from 'd3-scale';
|
|
|
5
5
|
import { hsl } from 'd3-color';
|
|
6
6
|
import { ComponentCore } from '../../core/component/index.js';
|
|
7
7
|
import { SeriesDataModel } from '../../data-models/series.js';
|
|
8
|
-
import { getColor, getHexValue, brighter } from '../../utils/color.js';
|
|
8
|
+
import { getColor, getHexValue, brighter, isColorDark } from '../../utils/color.js';
|
|
9
9
|
import { isNumber, getString, getNumber } from '../../utils/data.js';
|
|
10
10
|
import { smartTransition } from '../../utils/d3.js';
|
|
11
|
-
import { trimSVGText } from '../../utils/text.js';
|
|
12
|
-
import {
|
|
11
|
+
import { wrapSVGText, trimSVGText } from '../../utils/text.js';
|
|
12
|
+
import { cssvar } from '../../utils/style.js';
|
|
13
|
+
import { FitMode } from '../../types/text.js';
|
|
13
14
|
import { TreemapDefaultConfig } from './config.js';
|
|
14
15
|
import * as style from './style.js';
|
|
15
|
-
import { tiles, tileGroup, tile, clickableTile, labelGroup, label, internalLabel } from './style.js';
|
|
16
|
+
import { tiles, tileGroup, tile, clickableTile, labelGroup, label, variables, internalLabel } from './style.js';
|
|
16
17
|
|
|
17
18
|
class Treemap extends ComponentCore {
|
|
18
19
|
constructor(config) {
|
|
@@ -24,10 +25,6 @@ class Treemap extends ComponentCore {
|
|
|
24
25
|
this.setConfig(config);
|
|
25
26
|
this.tiles = this.g.append('g').attr('class', tiles);
|
|
26
27
|
}
|
|
27
|
-
/** Default number format for tile labels. */
|
|
28
|
-
_defaultNumberFormat(value) {
|
|
29
|
-
return `${value}`;
|
|
30
|
-
}
|
|
31
28
|
_isTileLargeEnough(d) {
|
|
32
29
|
const w = d.x1 - d.x0;
|
|
33
30
|
const h = d.y1 - d.y0;
|
|
@@ -44,11 +41,9 @@ class Treemap extends ComponentCore {
|
|
|
44
41
|
return this.config.lightnessVariationAmount * ((maxValue - node.value) / (maxValue - minValue));
|
|
45
42
|
}
|
|
46
43
|
_render(customDuration) {
|
|
47
|
-
var _a
|
|
44
|
+
var _a;
|
|
48
45
|
super._render(customDuration);
|
|
49
46
|
const { config, datamodel: { data }, _width, _height } = this;
|
|
50
|
-
const { numberFormat } = config;
|
|
51
|
-
const formatNumber = numberFormat !== null && numberFormat !== void 0 ? numberFormat : this._defaultNumberFormat.bind(this);
|
|
52
47
|
const duration = isNumber(customDuration) ? customDuration : config.duration;
|
|
53
48
|
if (!((_a = config.layers) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
54
49
|
console.warn('Unovis | Treemap: No layers defined');
|
|
@@ -66,7 +61,7 @@ class Treemap extends ComponentCore {
|
|
|
66
61
|
const rootNode = hierarchy(nestedData);
|
|
67
62
|
// Compute the aggregation
|
|
68
63
|
if (config.value) {
|
|
69
|
-
rootNode.sum(index =>
|
|
64
|
+
rootNode.sum(index => isNumber(index) && getNumber(data[index], config.value, index));
|
|
70
65
|
}
|
|
71
66
|
else {
|
|
72
67
|
rootNode.count();
|
|
@@ -127,36 +122,33 @@ class Treemap extends ComponentCore {
|
|
|
127
122
|
config.tileLabelMediumFontSize,
|
|
128
123
|
config.tileLabelLargeFontSize,
|
|
129
124
|
]);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const siblings = node.parent.children;
|
|
145
|
-
const lightnessAdjustment = this._getTileLightness(node, siblings);
|
|
146
|
-
hslColor.l = Math.min(1, hslColor.l + lightnessAdjustment);
|
|
147
|
-
}
|
|
148
|
-
// Brightness increase for depth
|
|
149
|
-
node._fill = brighter(hslColor.toString(), brightnessIncrease(node.depth));
|
|
125
|
+
const visibleTiles = descendants.filter(d => d.depth > 0);
|
|
126
|
+
const firstLevelTiles = visibleTiles.filter(d => d.depth === 1);
|
|
127
|
+
const nonFirstLevelTiles = visibleTiles.filter(d => d.depth > 1);
|
|
128
|
+
// Set the fill color for the first level tiles
|
|
129
|
+
firstLevelTiles.forEach((d, i) => {
|
|
130
|
+
d._fill = getColor(d, config.tileColor, i);
|
|
131
|
+
});
|
|
132
|
+
// Set the fill color for the non-first level tiles
|
|
133
|
+
nonFirstLevelTiles.forEach((d, i) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const providedColor = getColor(d, config.tileColor, i, true);
|
|
136
|
+
if (providedColor) {
|
|
137
|
+
d._fill = providedColor;
|
|
138
|
+
return;
|
|
150
139
|
}
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
const hslColor = hsl(getHexValue((_a = d.parent) === null || _a === void 0 ? void 0 : _a._fill, this.element));
|
|
141
|
+
if (config.enableLightnessVariance && !d.children && d.parent) {
|
|
142
|
+
const siblings = d.parent.children;
|
|
143
|
+
const lightnessAdjustment = this._getTileLightness(d, siblings);
|
|
144
|
+
hslColor.l = Math.min(1, hslColor.l + lightnessAdjustment);
|
|
153
145
|
}
|
|
146
|
+
d._fill = brighter(hslColor.toString(), brightnessIncrease(d.depth));
|
|
154
147
|
});
|
|
155
148
|
// Render tiles
|
|
156
|
-
const visibleNodes = descendants.filter(d => d.depth > 0);
|
|
157
149
|
const tiles = this.tiles
|
|
158
150
|
.selectAll(`g.${tileGroup}`)
|
|
159
|
-
.data(
|
|
151
|
+
.data(visibleTiles, d => `${d.data.key}-${d.depth}`);
|
|
160
152
|
const tilesEnter = tiles
|
|
161
153
|
.enter()
|
|
162
154
|
.append('g')
|
|
@@ -168,92 +160,87 @@ class Treemap extends ComponentCore {
|
|
|
168
160
|
// This ensures that the tile border radius is not
|
|
169
161
|
// larger than the tile size, which makes small tiles
|
|
170
162
|
// look better.
|
|
171
|
-
const
|
|
172
|
-
//
|
|
163
|
+
const getTileBorderRadius = (d) => Math.min(config.tileBorderRadius, (d.x1 - d.x0) * config.tileBorderRadiusFactor);
|
|
164
|
+
// Add clipPath elements
|
|
173
165
|
tilesEnter
|
|
166
|
+
.append('clipPath')
|
|
167
|
+
.attr('id', d => `clip-${this.uid}-${d._id}`)
|
|
168
|
+
.append('rect')
|
|
169
|
+
.attr('rx', getTileBorderRadius)
|
|
170
|
+
.attr('ry', getTileBorderRadius);
|
|
171
|
+
// Tile rectangles
|
|
172
|
+
const tileRects = tilesEnter
|
|
174
173
|
.append('rect')
|
|
175
174
|
.classed(tile, true)
|
|
176
|
-
// Make the leaf tiles clickable if a click handler is provided
|
|
177
175
|
.classed(clickableTile, d => config.showTileClickAffordance && !d.children)
|
|
178
|
-
.attr('rx',
|
|
179
|
-
.attr('ry',
|
|
180
|
-
// Initialize tile positions so that the initial transition is smooth
|
|
176
|
+
.attr('rx', getTileBorderRadius)
|
|
177
|
+
.attr('ry', getTileBorderRadius)
|
|
181
178
|
.attr('x', d => d.x0)
|
|
182
179
|
.attr('y', d => d.y0)
|
|
183
180
|
.attr('width', d => d.x1 - d.x0)
|
|
184
181
|
.attr('height', d => d.y1 - d.y0)
|
|
185
|
-
.style('fill', d =>
|
|
182
|
+
.style('fill', d => d._fill)
|
|
186
183
|
.style('opacity', 0)
|
|
187
184
|
.style('cursor', config.showTileClickAffordance ? d => !d.children ? 'pointer' : null : null);
|
|
188
|
-
|
|
189
|
-
smartTransition(mergedTiles.select(`rect.${tile}`), duration)
|
|
190
|
-
.style('fill', d => { var _a; return (_a = d._fill) !== null && _a !== void 0 ? _a : getColor(d, config.tileColor); })
|
|
191
|
-
.style('opacity', 1)
|
|
192
|
-
.attr('x', d => d.x0)
|
|
193
|
-
.attr('y', d => d.y0)
|
|
194
|
-
.attr('width', d => d.x1 - d.x0)
|
|
195
|
-
.attr('height', d => d.y1 - d.y0);
|
|
196
|
-
// Update clipPath rects
|
|
197
|
-
let svg = this.g.node();
|
|
198
|
-
while (svg && !(svg instanceof SVGSVGElement))
|
|
199
|
-
svg = svg.parentElement;
|
|
200
|
-
const defs = svg ? (select(svg).select('defs').empty() ? select(svg).append('defs') : select(svg).select('defs')) : null;
|
|
201
|
-
if (!defs)
|
|
202
|
-
return;
|
|
203
|
-
const defsSelection = defs;
|
|
204
|
-
const clipPaths = defsSelection.selectAll('clipPath')
|
|
205
|
-
.data(visibleNodes, (d) => d._id);
|
|
206
|
-
clipPaths.enter()
|
|
207
|
-
.append('clipPath')
|
|
208
|
-
.attr('id', (d) => `clip-${d._id}`)
|
|
209
|
-
.append('rect')
|
|
210
|
-
.attr('x', (d) => d.x0)
|
|
211
|
-
.attr('y', (d) => d.y0)
|
|
212
|
-
.attr('width', (d) => Math.max(0.1, d.x1 - d.x0))
|
|
213
|
-
.attr('height', (d) => Math.max(0.1, d.y1 - d.y0))
|
|
214
|
-
.attr('rx', rx)
|
|
215
|
-
.attr('ry', rx);
|
|
216
|
-
clipPaths.exit().remove();
|
|
185
|
+
tileRects.append('title');
|
|
217
186
|
tilesEnter
|
|
218
187
|
.append('g')
|
|
219
188
|
.attr('class', labelGroup)
|
|
189
|
+
.attr('clip-path', d => `url(#clip-${this.uid}-${d._id})`)
|
|
220
190
|
.attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`)
|
|
191
|
+
.style('opacity', 0)
|
|
221
192
|
.append('text')
|
|
222
193
|
.attr('class', label)
|
|
223
194
|
.attr('x', 0)
|
|
224
|
-
.attr('y', 0)
|
|
225
|
-
|
|
226
|
-
const
|
|
195
|
+
.attr('y', 0);
|
|
196
|
+
const mergedTiles = tiles.merge(tilesEnter);
|
|
197
|
+
const tileRectsMerged = mergedTiles.select(`rect.${tile}`);
|
|
198
|
+
smartTransition(tileRectsMerged, duration)
|
|
199
|
+
.style('fill', d => d._fill)
|
|
200
|
+
.style('opacity', 1)
|
|
201
|
+
.attr('x', d => d.x0)
|
|
202
|
+
.attr('y', d => d.y0)
|
|
203
|
+
.attr('width', d => d.x1 - d.x0)
|
|
204
|
+
.attr('height', d => d.y1 - d.y0);
|
|
205
|
+
tileRectsMerged.select('title')
|
|
206
|
+
.text(d => config.tileLabel(d));
|
|
207
|
+
// Update clipPath rects
|
|
208
|
+
mergedTiles.select('clipPath rect')
|
|
209
|
+
.attr('width', d => d.x1 - d.x0 - 2 * config.labelOffsetX)
|
|
210
|
+
.attr('height', d => d.y1 - d.y0 - 2 * config.labelOffsetY);
|
|
227
211
|
const textSelection = mergedTiles.selectAll(`g.${labelGroup} text`);
|
|
228
212
|
textSelection
|
|
229
|
-
.text(d =>
|
|
230
|
-
.
|
|
213
|
+
.text(d => config.tileLabel(d))
|
|
214
|
+
.attr('title', d => config.tileLabel(d))
|
|
215
|
+
.property('font-size-px', d => {
|
|
231
216
|
var _a;
|
|
232
217
|
const sqrtVal = Math.sqrt((_a = d.value) !== null && _a !== void 0 ? _a : 0);
|
|
233
218
|
return config.enableTileLabelFontSizeVariation && !d.children
|
|
234
|
-
?
|
|
235
|
-
:
|
|
219
|
+
? fontSizeScale(sqrtVal)
|
|
220
|
+
: null; // Use the default css variable value
|
|
236
221
|
})
|
|
237
|
-
.
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
.style('font-size', (_, i, els) => `${select(els[i]).property('font-size-px')}px`)
|
|
223
|
+
.style('fill', d => cssvar(isColorDark(d._fill) ? variables.treemapLabelTextColorLight : variables.treemapLabelTextColor));
|
|
224
|
+
// Fit label (wrap or trim)
|
|
225
|
+
textSelection.each((d, i, els) => {
|
|
240
226
|
var _a;
|
|
241
|
-
const
|
|
227
|
+
const isLeafNode = !d.children;
|
|
228
|
+
const el = els[i];
|
|
229
|
+
const text = select(el);
|
|
242
230
|
const tileWidth = d.x1 - d.x0 - ((_a = config.labelOffsetX) !== null && _a !== void 0 ? _a : 0) * 2;
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
231
|
+
const fontSize = parseFloat(text.property('font-size-px')) || parseFloat(window.getComputedStyle(el).fontSize);
|
|
232
|
+
if (config.labelFit === FitMode.Wrap && isLeafNode) {
|
|
233
|
+
wrapSVGText(text, tileWidth);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
trimSVGText(text, tileWidth, config.labelTrimMode, true, fontSize);
|
|
247
237
|
}
|
|
248
|
-
trimSVGText(text, tileWidth, TrimMode.End, true, fontSize);
|
|
249
|
-
text.attr('title', fullLabel);
|
|
250
|
-
text.selectAll('tspan').attr('dominant-baseline', 'middle');
|
|
251
238
|
});
|
|
252
239
|
// Transition group position
|
|
253
240
|
smartTransition(mergedTiles.select(`g.${labelGroup}`), duration)
|
|
254
241
|
.attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`);
|
|
255
242
|
// Transition text opacity only (fade-in)
|
|
256
|
-
smartTransition(mergedTiles.select(`g.${labelGroup}
|
|
243
|
+
smartTransition(mergedTiles.select(`g.${labelGroup}`), duration)
|
|
257
244
|
.style('opacity', 1);
|
|
258
245
|
// Hide labels that don't meet criteria
|
|
259
246
|
mergedTiles.select(`text.${label}`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/treemap/index.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { hierarchy, HierarchyNode, treemap } from 'd3-hierarchy'\nimport { group, max, extent } from 'd3-array'\nimport { scaleLinear, scaleThreshold } from 'd3-scale'\nimport { hsl } from 'd3-color'\nimport { ComponentCore } from 'core/component'\nimport { SeriesDataModel } from 'data-models/series'\nimport { getColor, brighter, getHexValue } from 'utils/color'\nimport { getString, getNumber, isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { trimSVGText } from 'utils/text'\nimport { TrimMode } from 'types/text'\nimport { TreemapConfigInterface, TreemapDefaultConfig } from './config'\nimport { TreemapDatum, TreemapNode } from './types'\nimport * as s from './style'\n\nexport class Treemap<Datum> extends ComponentCore<Datum[], TreemapConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = TreemapDefaultConfig as TreemapConfigInterface<Datum>\n public config: TreemapConfigInterface<Datum> = this._defaultConfig\n\n /** Default number format for tile labels. */\n private _defaultNumberFormat (value: number): string {\n return `${value}`\n }\n\n datamodel: SeriesDataModel<Datum> = new SeriesDataModel()\n tiles: Selection<SVGGElement, unknown, SVGGElement, unknown>\n\n private _isTileLargeEnough (d: TreemapNode<Datum>): boolean {\n const w = d.x1 - d.x0\n const h = d.y1 - d.y0\n return (w >= this.config.minTileSizeForLabel) && (h >= this.config.minTileSizeForLabel)\n }\n\n private _getTileLightness (node: TreemapNode<Datum>, siblings: TreemapNode<Datum>[]): number {\n // Get the value extent of the sibling group\n const [minValue, maxValue] = extent(siblings, d => d.value)\n\n // If there's no range or no value, return default lightness\n if (minValue === maxValue || !node.value) return 0\n\n // Calculate relative position in the range (0 to 1)\n // Larger values will be closer to 0 (darker)\n return this.config.lightnessVariationAmount * ((maxValue - node.value) / (maxValue - minValue))\n }\n\n constructor (config?: TreemapConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n this.tiles = this.g.append('g').attr('class', s.tiles)\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data }, _width, _height } = this\n const { numberFormat } = config\n const formatNumber = numberFormat ?? this._defaultNumberFormat.bind(this)\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n if (!config.layers?.length) {\n console.warn('Unovis | Treemap: No layers defined')\n return\n }\n\n // Map each layer accessor function to get string values from the data array\n const layerAccessors = config.layers.map(layerAccessor => {\n return (i: number) => getString(data[i], layerAccessor, i)\n })\n\n // Group the data indices by the layer accessors to create a hierarchical structure\n const nestedData = group(data.keys(), ...layerAccessors as [(d: number) => string])\n\n // Create the hierarchy from the grouped data,\n // which by itself is not quite right because there is an extra\n // level of nesting that we don't want, just above the leaf nodes.\n const rootNode = hierarchy(nestedData)\n\n // Compute the aggregation\n if (config.value) {\n rootNode.sum(index => typeof index === 'number' && getNumber(data[index], config.value, index))\n } else {\n rootNode.count()\n }\n\n // Fix the hierarchy by removing the extra level of nesting\n rootNode.each(node => {\n if (!node.children && node.parent) {\n node.parent.children = null\n }\n })\n\n const treemapLayout = treemap()\n .size([_width, _height])\n .round(true)\n .padding(config.tilePadding)\n\n // Apply padding to the top of each tile,\n // but not for the root node.\n if (this.config.tilePaddingTop !== undefined) {\n treemapLayout.paddingTop(d => d.parent ? config.tilePaddingTop : 0)\n }\n\n // Compute the treemap layout\n const treemapData = treemapLayout(rootNode) as TreemapNode<Datum>\n\n // Process the resulting hierarchy into the type we need\n let nodeId = 0\n treemapData.each(node => {\n const n = node as unknown as HierarchyNode<[string, number[]]>\n // Generate unique IDs for each node\n node._id = `node-${nodeId++}`\n\n const treemapDatum: TreemapDatum<Datum> = {\n key: n.data[0],\n }\n\n // Populate the index and datum for leaf nodes\n const isLeafNode = !n.children\n if (isLeafNode) {\n treemapDatum.index = n.data[1][0]\n treemapDatum.datum = data[treemapDatum.index]\n }\n\n node.data = treemapDatum\n })\n\n const descendants = treemapData.descendants()\n\n // Set up the brightness increase scale based on depth\n const maxDepth = max(descendants, d => d.depth)\n\n const brightnessIncrease = scaleLinear()\n .domain([1, maxDepth])\n .range([0, 1])\n\n // Get all leaf node values and calculate their square roots\n // (since area is proportional to value)\n const leafValues = descendants.filter(d => !d.children).map(d => d.value)\n const maxLeafValue = Math.sqrt(max(leafValues)) || 0\n // Divide the range into three equal intervals based on the square root of values\n // This accounts for the fact that area is proportional to value\n const fontSizeScale = scaleThreshold<number, number>()\n .domain([\n maxLeafValue / 3, // First third of the max value\n (maxLeafValue * 2) / 3, // Second third of the max value\n ])\n .range([\n config.tileLabelSmallFontSize,\n config.tileLabelMediumFontSize,\n config.tileLabelLargeFontSize,\n ])\n\n // First pass: Set base colors without considering tileColor config\n treemapData.eachBefore((node) => {\n // Get base color: user accessor or default\n let color = config.tileColor\n ? getColor(node, config.tileColor)\n : getColor(node, undefined, node.parent?.children?.indexOf(node), node.depth !== 1)\n\n // Fallback to parent color if needed\n color = color ?? (node.parent as TreemapNode<Datum>)?._fill\n\n const hexColor = color ? getHexValue(color, this.g.node()) : null\n\n if (hexColor) {\n const hslColor = hsl(hexColor)\n\n // Lightness adjustment for siblings (if enabled)\n if (config.enableLightnessVariance && !node.children && node.parent) {\n const siblings = node.parent.children\n const lightnessAdjustment = this._getTileLightness(node, siblings)\n hslColor.l = Math.min(1, hslColor.l + lightnessAdjustment)\n }\n\n // Brightness increase for depth\n node._fill = brighter(hslColor.toString(), brightnessIncrease(node.depth))\n } else {\n node._fill = null\n }\n })\n\n // Render tiles\n const visibleNodes = descendants.filter(d => d.depth > 0)\n const tiles = this.tiles\n .selectAll<SVGGElement, TreemapNode<Datum>>(`g.${s.tileGroup}`)\n .data(visibleNodes, d => `${d.data.key}-${d.depth}`)\n\n const tilesEnter = tiles\n .enter()\n .append('g')\n .attr('class', s.tileGroup)\n\n // Computes the rect border radius for a given tile.\n // The rx and ry values are the minimum of the tile\n // border radius and some fraction the width of the tile,\n // based on the tileBorderRadiusFactor config.\n // This ensures that the tile border radius is not\n // larger than the tile size, which makes small tiles\n // look better.\n const rx = (d: TreemapNode<Datum>): number =>\n Math.min(config.tileBorderRadius, (d.x1 - d.x0) * config.tileBorderRadiusFactor)\n\n // Tile rectangles\n tilesEnter\n .append('rect')\n .classed(s.tile, true)\n\n // Make the leaf tiles clickable if a click handler is provided\n .classed(s.clickableTile, d => config.showTileClickAffordance && !d.children)\n\n .attr('rx', rx)\n .attr('ry', rx)\n // Initialize tile positions so that the initial transition is smooth\n .attr('x', d => d.x0)\n .attr('y', d => d.y0)\n .attr('width', d => d.x1 - d.x0)\n .attr('height', d => d.y1 - d.y0)\n .style('fill', d => d._fill ?? getColor(d, config.tileColor))\n .style('opacity', 0)\n .style('cursor', config.showTileClickAffordance ? d => !d.children ? 'pointer' : null : null)\n\n\n const mergedTiles = tiles.merge(tilesEnter)\n\n smartTransition(mergedTiles.select(`rect.${s.tile}`), duration)\n .style('fill', d => d._fill ?? getColor(d, config.tileColor))\n .style('opacity', 1)\n .attr('x', d => d.x0)\n .attr('y', d => d.y0)\n .attr('width', d => d.x1 - d.x0)\n .attr('height', d => d.y1 - d.y0)\n\n // Update clipPath rects\n let svg: Element | null = this.g.node()\n while (svg && !(svg instanceof SVGSVGElement)) svg = svg.parentElement\n const defs = svg ? (select(svg).select('defs').empty() ? select(svg).append('defs') : select(svg).select('defs')) : null\n if (!defs) return\n const defsSelection = (defs as Selection<SVGDefsElement, unknown, null, undefined>)\n const clipPaths = defsSelection.selectAll<SVGClipPathElement, TreemapNode<Datum>>('clipPath')\n .data(visibleNodes, (d: TreemapNode<Datum>) => d._id)\n\n clipPaths.enter()\n .append('clipPath')\n .attr('id', (d: TreemapNode<Datum>) => `clip-${d._id}`)\n .append('rect')\n .attr('x', (d: TreemapNode<Datum>) => d.x0)\n .attr('y', (d: TreemapNode<Datum>) => d.y0)\n .attr('width', (d: TreemapNode<Datum>) => Math.max(0.1, d.x1 - d.x0))\n .attr('height', (d: TreemapNode<Datum>) => Math.max(0.1, d.y1 - d.y0))\n .attr('rx', rx)\n .attr('ry', rx)\n\n clipPaths.exit().remove()\n\n tilesEnter\n .append('g')\n .attr('class', s.labelGroup)\n .attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`)\n .append('text')\n .attr('class', s.label)\n .attr('x', 0)\n .attr('y', 0)\n .style('opacity', 0)\n\n const getTileLabel = config.tileLabel ?? ((d: TreemapNode<Datum>) => `${d.data.key}: ${formatNumber(d.value)}`)\n const textSelection = mergedTiles.selectAll<SVGTextElement, TreemapNode<Datum>>(`g.${s.labelGroup} text`)\n textSelection\n .text(d => getTileLabel(d))\n .style('font-size', function (d) {\n const sqrtVal = Math.sqrt(d.value ?? 0)\n return config.enableTileLabelFontSizeVariation && !d.children\n ? `${fontSizeScale(sqrtVal)}px`\n : `${fontSizeScale.range()[1]}px`\n })\n .attr('dominant-baseline', 'middle')\n\n // Trim label and set dominant-baseline for tspans in one pass\n textSelection.each((d, i, nodes) => {\n const text = select(nodes[i] as SVGTextElement)\n const tileWidth = d.x1 - d.x0 - (config.labelOffsetX ?? 0) * 2\n const fullLabel = text.text()\n let fontSize = parseFloat(text.style('font-size'))\n if (!fontSize) {\n fontSize = parseFloat(window.getComputedStyle(nodes[i] as SVGTextElement).fontSize)\n }\n trimSVGText(text, tileWidth, TrimMode.End, true, fontSize)\n text.attr('title', fullLabel)\n text.selectAll('tspan').attr('dominant-baseline', 'middle')\n })\n\n // Transition group position\n smartTransition(mergedTiles.select(`g.${s.labelGroup}`), duration)\n .attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`)\n\n // Transition text opacity only (fade-in)\n smartTransition(mergedTiles.select(`g.${s.labelGroup} text`), duration)\n .style('opacity', 1)\n\n // Hide labels that don't meet criteria\n mergedTiles.select(`text.${s.label}`)\n .style('display', d => {\n const isAllowedNode = config.labelInternalNodes ? true : !d.children\n return isAllowedNode && this._isTileLargeEnough(d) ? null : 'none'\n })\n // Make the internal labels semibold via class\n .attr('class', d => d.children ? `${s.label} ${s.internalLabel}` : s.label)\n\n smartTransition(tiles.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n}\n"],"names":["s.tiles","s.tileGroup","s.tile","s.clickableTile","s.labelGroup","s.label","s.internalLabel","s"],"mappings":";;;;;;;;;;;;;;;;AAgBM,MAAO,OAAe,SAAQ,aAAqD,CAAA;AA+BvF,IAAA,WAAA,CAAa,MAAsC,EAAA;AACjD,QAAA,KAAK,EAAE,CAAA;QA9BC,IAAc,CAAA,cAAA,GAAG,oBAAqD,CAAA;AACzE,QAAA,IAAA,CAAA,MAAM,GAAkC,IAAI,CAAC,cAAc,CAAA;AAOlE,QAAA,IAAA,CAAA,SAAS,GAA2B,IAAI,eAAe,EAAE,CAAA;AAuBvD,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,EAAEA,KAAO,CAAC,CAAA;KACvD;;AA7BO,IAAA,oBAAoB,CAAE,KAAa,EAAA;QACzC,OAAO,CAAA,EAAG,KAAK,CAAA,CAAE,CAAA;KAClB;AAKO,IAAA,kBAAkB,CAAE,CAAqB,EAAA;QAC/C,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAA;QACrB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAA;AACrB,QAAA,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;KACxF;IAEO,iBAAiB,CAAE,IAAwB,EAAE,QAA8B,EAAA;;AA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AC,CAAA,EAAA,EAAKA,UAAY,CAAA,KAAA,CAAO,CAAC,EAAE,QAAQ,CAAC;AACpE,aAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;;QAGtB,WAAW,CAAC,MAAM,CAAC,CAAA,KAAA,EAAQC,KAAO,EAAE,CAAC;AAClC,aAAA,KAAK,CAAC,SAAS,EAAE,CAAC,IAAG;AACpB,YAAA,MAAM,aAAa,GAAG,MAAM,CAAC,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAA;AACpE,YAAA,OAAO,aAAa,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAAA;AACpE,SAAC,CAAC;;AAED,aAAA,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAA,EAAGA,KAAO,CAAA,CAAA,EAAIC,aAAe,CAAA,CAAE,GAAGD,KAAO,CAAC,CAAA;AAE7E,QAAA,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC;AACpC,aAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AACnB,aAAA,MAAM,EAAE,CAAA;KACZ;;AAtSM,OAAS,CAAA,SAAA,GAAGE,KAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/treemap/index.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { hierarchy, HierarchyNode, treemap } from 'd3-hierarchy'\nimport { group, max, extent } from 'd3-array'\nimport { scaleLinear, scaleThreshold } from 'd3-scale'\nimport { hsl } from 'd3-color'\n\n// Core\nimport { ComponentCore } from 'core/component'\n\n// Data Model\nimport { SeriesDataModel } from 'data-models/series'\n\n// Utils\nimport { getColor, brighter, getHexValue, isColorDark } from 'utils/color'\nimport { getString, getNumber, isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { trimSVGText, wrapSVGText } from 'utils/text'\nimport { cssvar } from 'utils/style'\n\n// Types\nimport { FitMode } from 'types/text'\n\n// Config\nimport { TreemapConfigInterface, TreemapDefaultConfig } from './config'\n\n// Local Types\nimport { TreemapDatum, TreemapNode } from './types'\n\n// Styles\nimport * as s from './style'\n\nexport class Treemap<Datum> extends ComponentCore<Datum[], TreemapConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = TreemapDefaultConfig as TreemapConfigInterface<Datum>\n public config: TreemapConfigInterface<Datum> = this._defaultConfig\n\n datamodel: SeriesDataModel<Datum> = new SeriesDataModel()\n tiles: Selection<SVGGElement, unknown, SVGGElement, unknown>\n\n private _isTileLargeEnough (d: TreemapNode<Datum>): boolean {\n const w = d.x1 - d.x0\n const h = d.y1 - d.y0\n return (w >= this.config.minTileSizeForLabel) && (h >= this.config.minTileSizeForLabel)\n }\n\n private _getTileLightness (node: TreemapNode<Datum>, siblings: TreemapNode<Datum>[]): number {\n // Get the value extent of the sibling group\n const [minValue, maxValue] = extent(siblings, d => d.value)\n\n // If there's no range or no value, return default lightness\n if (minValue === maxValue || !node.value) return 0\n\n // Calculate relative position in the range (0 to 1)\n // Larger values will be closer to 0 (darker)\n return this.config.lightnessVariationAmount * ((maxValue - node.value) / (maxValue - minValue))\n }\n\n constructor (config?: TreemapConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n this.tiles = this.g.append('g').attr('class', s.tiles)\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data }, _width, _height } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n if (!config.layers?.length) {\n console.warn('Unovis | Treemap: No layers defined')\n return\n }\n\n // Map each layer accessor function to get string values from the data array\n const layerAccessors = config.layers.map(layerAccessor => {\n return (i: number) => getString(data[i], layerAccessor, i)\n })\n\n // Group the data indices by the layer accessors to create a hierarchical structure\n const nestedData = group(data.keys(), ...layerAccessors as [(d: number) => string])\n\n // Create the hierarchy from the grouped data,\n // which by itself is not quite right because there is an extra\n // level of nesting that we don't want, just above the leaf nodes.\n const rootNode = hierarchy(nestedData)\n\n // Compute the aggregation\n if (config.value) {\n rootNode.sum(index => isNumber(index) && getNumber(data[index], config.value, index))\n } else {\n rootNode.count()\n }\n\n // Fix the hierarchy by removing the extra level of nesting\n rootNode.each(node => {\n if (!node.children && node.parent) {\n node.parent.children = null\n }\n })\n\n const treemapLayout = treemap()\n .size([_width, _height])\n .round(true)\n .padding(config.tilePadding)\n\n // Apply padding to the top of each tile,\n // but not for the root node.\n if (this.config.tilePaddingTop !== undefined) {\n treemapLayout.paddingTop(d => d.parent ? config.tilePaddingTop : 0)\n }\n\n // Compute the treemap layout\n const treemapData = treemapLayout(rootNode) as TreemapNode<Datum>\n\n // Process the resulting hierarchy into the type we need\n let nodeId = 0\n treemapData.each(node => {\n const n = node as unknown as HierarchyNode<[string, number[]]>\n // Generate unique IDs for each node\n node._id = `node-${nodeId++}`\n\n const treemapDatum: TreemapDatum<Datum> = {\n key: n.data[0],\n }\n\n // Populate the index and datum for leaf nodes\n const isLeafNode = !n.children\n if (isLeafNode) {\n treemapDatum.index = n.data[1][0]\n treemapDatum.datum = data[treemapDatum.index]\n }\n\n node.data = treemapDatum\n })\n\n const descendants = treemapData.descendants()\n\n // Set up the brightness increase scale based on depth\n const maxDepth = max(descendants, d => d.depth)\n\n const brightnessIncrease = scaleLinear()\n .domain([1, maxDepth])\n .range([0, 1])\n\n // Get all leaf node values and calculate their square roots\n // (since area is proportional to value)\n const leafValues = descendants.filter(d => !d.children).map(d => d.value)\n const maxLeafValue = Math.sqrt(max(leafValues)) || 0\n // Divide the range into three equal intervals based on the square root of values\n // This accounts for the fact that area is proportional to value\n const fontSizeScale = scaleThreshold<number, number>()\n .domain([\n maxLeafValue / 3, // First third of the max value\n (maxLeafValue * 2) / 3, // Second third of the max value\n ])\n .range([\n config.tileLabelSmallFontSize,\n config.tileLabelMediumFontSize,\n config.tileLabelLargeFontSize,\n ])\n\n const visibleTiles = descendants.filter(d => d.depth > 0)\n const firstLevelTiles = visibleTiles.filter(d => d.depth === 1)\n const nonFirstLevelTiles = visibleTiles.filter(d => d.depth > 1)\n\n // Set the fill color for the first level tiles\n firstLevelTiles.forEach((d, i) => {\n d._fill = getColor(d, config.tileColor, i)\n })\n\n // Set the fill color for the non-first level tiles\n nonFirstLevelTiles.forEach((d, i) => {\n const providedColor = getColor(d, config.tileColor, i, true)\n if (providedColor) {\n d._fill = providedColor\n return\n }\n\n const hslColor = hsl(getHexValue(d.parent?._fill, this.element))\n\n if (config.enableLightnessVariance && !d.children && d.parent) {\n const siblings = d.parent.children\n const lightnessAdjustment = this._getTileLightness(d, siblings)\n hslColor.l = Math.min(1, hslColor.l + lightnessAdjustment)\n }\n\n d._fill = brighter(hslColor.toString(), brightnessIncrease(d.depth))\n })\n\n\n // Render tiles\n const tiles = this.tiles\n .selectAll<SVGGElement, TreemapNode<Datum>>(`g.${s.tileGroup}`)\n .data(visibleTiles, d => `${d.data.key}-${d.depth}`)\n\n const tilesEnter = tiles\n .enter()\n .append('g')\n .attr('class', s.tileGroup)\n\n // Computes the rect border radius for a given tile.\n // The rx and ry values are the minimum of the tile\n // border radius and some fraction the width of the tile,\n // based on the tileBorderRadiusFactor config.\n // This ensures that the tile border radius is not\n // larger than the tile size, which makes small tiles\n // look better.\n const getTileBorderRadius = (d: TreemapNode<Datum>): number =>\n Math.min(config.tileBorderRadius, (d.x1 - d.x0) * config.tileBorderRadiusFactor)\n\n // Add clipPath elements\n tilesEnter\n .append('clipPath')\n .attr('id', d => `clip-${this.uid}-${d._id}`)\n .append('rect')\n .attr('rx', getTileBorderRadius)\n .attr('ry', getTileBorderRadius)\n\n // Tile rectangles\n const tileRects = tilesEnter\n .append('rect')\n .classed(s.tile, true)\n .classed(s.clickableTile, d => config.showTileClickAffordance && !d.children)\n .attr('rx', getTileBorderRadius)\n .attr('ry', getTileBorderRadius)\n .attr('x', d => d.x0)\n .attr('y', d => d.y0)\n .attr('width', d => d.x1 - d.x0)\n .attr('height', d => d.y1 - d.y0)\n .style('fill', d => d._fill)\n .style('opacity', 0)\n .style('cursor', config.showTileClickAffordance ? d => !d.children ? 'pointer' : null : null)\n\n tileRects.append('title')\n\n tilesEnter\n .append('g')\n .attr('class', s.labelGroup)\n .attr('clip-path', d => `url(#clip-${this.uid}-${d._id})`)\n .attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`)\n .style('opacity', 0)\n .append('text')\n .attr('class', s.label)\n .attr('x', 0)\n .attr('y', 0)\n\n const mergedTiles = tiles.merge(tilesEnter)\n const tileRectsMerged = mergedTiles.select(`rect.${s.tile}`)\n smartTransition(tileRectsMerged, duration)\n .style('fill', d => d._fill)\n .style('opacity', 1)\n .attr('x', d => d.x0)\n .attr('y', d => d.y0)\n .attr('width', d => d.x1 - d.x0)\n .attr('height', d => d.y1 - d.y0)\n\n tileRectsMerged.select('title')\n .text(d => config.tileLabel(d))\n\n // Update clipPath rects\n mergedTiles.select('clipPath rect')\n .attr('width', d => d.x1 - d.x0 - 2 * config.labelOffsetX)\n .attr('height', d => d.y1 - d.y0 - 2 * config.labelOffsetY)\n\n const textSelection = mergedTiles.selectAll<SVGTextElement, TreemapNode<Datum>>(`g.${s.labelGroup} text`)\n textSelection\n .text(d => config.tileLabel(d))\n .attr('title', d => config.tileLabel(d))\n .property('font-size-px', d => {\n const sqrtVal = Math.sqrt(d.value ?? 0)\n return config.enableTileLabelFontSizeVariation && !d.children\n ? fontSizeScale(sqrtVal)\n : null // Use the default css variable value\n })\n .style('font-size', (_, i, els) => `${select(els[i]).property('font-size-px')}px`)\n .style('fill', d => cssvar(\n isColorDark(d._fill) ? s.variables.treemapLabelTextColorLight : s.variables.treemapLabelTextColor)\n )\n\n // Fit label (wrap or trim)\n textSelection.each((d, i, els) => {\n const isLeafNode = !d.children\n const el = els[i] as SVGTextElement\n const text = select(el)\n const tileWidth = d.x1 - d.x0 - (config.labelOffsetX ?? 0) * 2\n const fontSize = parseFloat(text.property('font-size-px')) || parseFloat(window.getComputedStyle(el).fontSize)\n\n if (config.labelFit === FitMode.Wrap && isLeafNode) {\n wrapSVGText(text, tileWidth)\n } else {\n trimSVGText(text, tileWidth, config.labelTrimMode, true, fontSize)\n }\n })\n\n // Transition group position\n smartTransition(mergedTiles.select(`g.${s.labelGroup}`), duration)\n .attr('transform', d => `translate(${d.x0 + config.labelOffsetX},${d.y0 + config.labelOffsetY})`)\n\n // Transition text opacity only (fade-in)\n smartTransition(mergedTiles.select(`g.${s.labelGroup}`), duration)\n .style('opacity', 1)\n\n // Hide labels that don't meet criteria\n mergedTiles.select(`text.${s.label}`)\n .style('display', d => {\n const isAllowedNode = config.labelInternalNodes ? true : !d.children\n return isAllowedNode && this._isTileLargeEnough(d) ? null : 'none'\n })\n // Make the internal labels semibold via class\n .attr('class', d => d.children ? `${s.label} ${s.internalLabel}` : s.label)\n\n smartTransition(tiles.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n}\n"],"names":["s.tiles","s.tileGroup","s.tile","s.clickableTile","s.labelGroup","s.label","s.variables","s.internalLabel","s"],"mappings":";;;;;;;;;;;;;;;;;AA+BM,MAAO,OAAe,SAAQ,aAAqD,CAAA;AA0BvF,IAAA,WAAA,CAAa,MAAsC,EAAA;AACjD,QAAA,KAAK,EAAE,CAAA;QAzBC,IAAc,CAAA,cAAA,GAAG,oBAAqD,CAAA;AACzE,QAAA,IAAA,CAAA,MAAM,GAAkC,IAAI,CAAC,cAAc,CAAA;AAElE,QAAA,IAAA,CAAA,SAAS,GAA2B,IAAI,eAAe,EAAE,CAAA;AAuBvD,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,EAAEA,KAAO,CAAC,CAAA;KACvD;AAtBO,IAAA,kBAAkB,CAAE,CAAqB,EAAA;QAC/C,MAAM,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AGG,KAAC;;;;"}
|
|
@@ -4,16 +4,11 @@ export declare const variables: {
|
|
|
4
4
|
treemapTileStrokeWidth: "--vis-treemap-tile-stroke-width";
|
|
5
5
|
treemapTileHoverStrokeColor: "--vis-treemap-tile-hover-stroke-color";
|
|
6
6
|
treemapTileHoverStrokeOpacity: "--vis-treemap-tile-hover-stroke-opacity";
|
|
7
|
-
treemapTileFillColor: "--vis-treemap-tile-fill-color";
|
|
8
|
-
treemapTileBackgroundColor: "--vis-treemap-tile-background-color";
|
|
9
|
-
treemapTileCursor: "--vis-treemap-tile-cursor";
|
|
10
|
-
treemapLabelTextColor: "--vis-treemap-label-text-color";
|
|
11
|
-
treemapLabelFontSize: "--vis-treemap-label-font-size";
|
|
12
7
|
treemapLabelOpacity: "--vis-treemap-label-opacity";
|
|
13
8
|
treemapLabelFontWeight: "--vis-treemap-label-font-weight";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
treemapLabelTextColor: "--vis-treemap-label-text-color";
|
|
10
|
+
treemapLabelTextColorLight: "--vis-treemap-label-text-color-light";
|
|
11
|
+
treemapLabelFontSize: "--vis-treemap-label-font-size";
|
|
17
12
|
};
|
|
18
13
|
export declare const tiles: string;
|
|
19
14
|
export declare const tileGroup: string;
|
|
@@ -6,18 +6,12 @@ const cssVarDefaults = {
|
|
|
6
6
|
'--vis-treemap-tile-stroke-width': '2px',
|
|
7
7
|
'--vis-treemap-tile-hover-stroke-color': '#fff',
|
|
8
8
|
'--vis-treemap-tile-hover-stroke-opacity': 0,
|
|
9
|
-
|
|
10
|
-
'--vis-treemap-tile-background-color': '#fff',
|
|
11
|
-
'--vis-treemap-tile-cursor': 'default',
|
|
12
|
-
'--vis-treemap-label-text-color': '#000',
|
|
13
|
-
'--vis-treemap-label-font-size': '12px',
|
|
14
|
-
/* Label opacity */
|
|
9
|
+
/* Labels */
|
|
15
10
|
'--vis-treemap-label-opacity': 0.8,
|
|
16
11
|
'--vis-treemap-label-font-weight': 'normal',
|
|
17
|
-
|
|
18
|
-
'--vis-
|
|
19
|
-
'--vis-
|
|
20
|
-
'--vis-dark-treemap-label-text-color': '#5b5f6d',
|
|
12
|
+
'--vis-treemap-label-text-color': '#000',
|
|
13
|
+
'--vis-treemap-label-text-color-light': '#fff',
|
|
14
|
+
'--vis-treemap-label-font-size': '12px',
|
|
21
15
|
};
|
|
22
16
|
const root = css `
|
|
23
17
|
label: treemap-component;
|
|
@@ -36,7 +30,7 @@ const tile = css `
|
|
|
36
30
|
stroke-opacity: 0;
|
|
37
31
|
|
|
38
32
|
&:hover {
|
|
39
|
-
stroke-opacity: var(
|
|
33
|
+
stroke-opacity: var(${variables.treemapTileHoverStrokeOpacity})
|
|
40
34
|
}
|
|
41
35
|
`;
|
|
42
36
|
// The leaf tiles are clickable
|
|
@@ -53,12 +47,13 @@ const label = css `
|
|
|
53
47
|
dominant-baseline: hanging;
|
|
54
48
|
user-select: none;
|
|
55
49
|
pointer-events: none;
|
|
56
|
-
font-size: var(
|
|
57
|
-
opacity: var(
|
|
58
|
-
fill: var(
|
|
59
|
-
font-weight: var(
|
|
50
|
+
font-size: var(${variables.treemapLabelFontSize});
|
|
51
|
+
opacity: var(${variables.treemapLabelOpacity});
|
|
52
|
+
fill: var(${variables.treemapLabelTextColor});
|
|
53
|
+
font-weight: var(${variables.treemapLabelFontWeight});
|
|
60
54
|
`;
|
|
61
55
|
const internalLabel = css `
|
|
56
|
+
label: internal-label;
|
|
62
57
|
font-weight: 500;
|
|
63
58
|
`;
|
|
64
59
|
const labelGroup = css `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sources":["../../../src/components/treemap/style.ts"],"sourcesContent":["import { css } from '@emotion/css'\n\n// Utils\nimport { getCssVarNames, injectGlobalCssVariables } from 'utils/style'\n\nconst cssVarDefaults = {\n '--vis-treemap-tile-stroke-color': '#fff',\n '--vis-treemap-tile-stroke-width': '2px',\n '--vis-treemap-tile-hover-stroke-color': '#fff',\n '--vis-treemap-tile-hover-stroke-opacity': 0,\n
|
|
1
|
+
{"version":3,"file":"style.js","sources":["../../../src/components/treemap/style.ts"],"sourcesContent":["import { css } from '@emotion/css'\n\n// Utils\nimport { getCssVarNames, injectGlobalCssVariables } from 'utils/style'\n\nconst cssVarDefaults = {\n '--vis-treemap-tile-stroke-color': '#fff',\n '--vis-treemap-tile-stroke-width': '2px',\n '--vis-treemap-tile-hover-stroke-color': '#fff',\n '--vis-treemap-tile-hover-stroke-opacity': 0,\n\n /* Labels */\n '--vis-treemap-label-opacity': 0.8,\n '--vis-treemap-label-font-weight': 'normal',\n '--vis-treemap-label-text-color': '#000',\n '--vis-treemap-label-text-color-light': '#fff',\n '--vis-treemap-label-font-size': '12px',\n}\n\nexport const root = css`\n label: treemap-component;\n`\n\nexport const variables = getCssVarNames(cssVarDefaults)\ninjectGlobalCssVariables(cssVarDefaults, root)\n\nexport const tiles = css`\n label: g-tiles;\n`\n\nexport const tileGroup = css`\n label: tile-group;\n`\n\nexport const tile = css`\n label: tile;\n stroke: var(${variables.treemapTileHoverStrokeColor});\n stroke-opacity: 0;\n\n &:hover {\n stroke-opacity: var(${variables.treemapTileHoverStrokeOpacity})\n }\n`\n\n// The leaf tiles are clickable\nexport const clickableTile = css`\n label: clickable-tile;\n cursor: pointer;\n`\n\nexport const tileForeground = css`\n label: tile-foreground;\n`\n\nexport const label = css`\n label: label;\n text-anchor: start;\n dominant-baseline: hanging;\n user-select: none;\n pointer-events: none;\n font-size: var(${variables.treemapLabelFontSize});\n opacity: var(${variables.treemapLabelOpacity});\n fill: var(${variables.treemapLabelTextColor});\n font-weight: var(${variables.treemapLabelFontWeight});\n`\n\nexport const internalLabel = css`\n label: internal-label;\n font-weight: 500;\n`\n\nexport const labelGroup = css`\n label: label-group;\n`\n"],"names":[],"mappings":";;;AAKA,MAAM,cAAc,GAAG;AACrB,IAAA,iCAAiC,EAAE,MAAM;AACzC,IAAA,iCAAiC,EAAE,KAAK;AACxC,IAAA,uCAAuC,EAAE,MAAM;AAC/C,IAAA,yCAAyC,EAAE,CAAC;;AAG5C,IAAA,6BAA6B,EAAE,GAAG;AAClC,IAAA,iCAAiC,EAAE,QAAQ;AAC3C,IAAA,gCAAgC,EAAE,MAAM;AACxC,IAAA,sCAAsC,EAAE,MAAM;AAC9C,IAAA,+BAA+B,EAAE,MAAM;CACxC,CAAA;AAEM,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;EAEtB;MAEY,SAAS,GAAG,cAAc,CAAC,cAAc,EAAC;AACvD,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;AAEvC,MAAM,KAAK,GAAG,GAAG,CAAA,CAAA;;EAEvB;AAEM,MAAM,SAAS,GAAG,GAAG,CAAA,CAAA;;EAE3B;AAEM,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;AAEP,cAAA,EAAA,SAAS,CAAC,2BAA2B,CAAA;;;;AAI3B,wBAAA,EAAA,SAAS,CAAC,6BAA6B,CAAA;;EAEhE;AAED;AACO,MAAM,aAAa,GAAG,GAAG,CAAA,CAAA;;;EAG/B;AAEM,MAAM,cAAc,GAAG,GAAG,CAAA,CAAA;;EAEhC;AAEM,MAAM,KAAK,GAAG,GAAG,CAAA,CAAA;;;;;;AAML,iBAAA,EAAA,SAAS,CAAC,oBAAoB,CAAA;AAChC,eAAA,EAAA,SAAS,CAAC,mBAAmB,CAAA;AAChC,YAAA,EAAA,SAAS,CAAC,qBAAqB,CAAA;AACxB,mBAAA,EAAA,SAAS,CAAC,sBAAsB,CAAA;EACpD;AAEM,MAAM,aAAa,GAAG,GAAG,CAAA,CAAA;;;EAG/B;AAEM,MAAM,UAAU,GAAG,GAAG,CAAA,CAAA;;;;;;"}
|
package/index.js
CHANGED
|
@@ -69,7 +69,7 @@ export { PlotbandLabelOrientation, PlotbandLabelPosition } from './components/pl
|
|
|
69
69
|
export { arrayOfIndices, clamp, clean, cloneDeep, countUnique, ensureArray, filterDataByRange, flatten, getBoolean, getExtent, getMax, getMin, getNearest, getNumber, getStackedData, getStackedExtent, getStackedValues, getString, getValue, groupBy, isAClassInstance, isArray, isEmpty, isEqual, isFunction, isNil, isNumber, isNumberWithinRange, isObject, isPlainObject, isString, isUndefined, merge, omit, shallowDiff, sortBy, throttle, unique, without } from './utils/data.js';
|
|
70
70
|
export { allowedSvgTextTags, escapeStringKeepHash, estimateStringPixelLength, estimateTextSize, estimateWrappedTextHeight, getPreciseStringLengthPx, getWrappedText, kebabCase, kebabCaseToCamel, renderTextIntoFrame, renderTextToSvgTextElement, splitString, textAlignToAnchor, trimSVGText, trimString, trimStringEnd, trimStringMiddle, trimStringStart, wrapSVGText } from './utils/text.js';
|
|
71
71
|
export { allowedSvgTags, getTransformValues, isStringSvg, sanitizeSvgString, transformValuesToString } from './utils/svg.js';
|
|
72
|
-
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, rgbToBrightness, rgbaToRgb } from './utils/color.js';
|
|
72
|
+
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, isColorDark, rgbToBrightness, rgbaToRgb } from './utils/color.js';
|
|
73
73
|
export { arrowPolylinePath, circlePath, convertLineToArc, polygon, roundedRectPath, scoreRectPath } from './utils/path.js';
|
|
74
74
|
export { getCSSVariableValue, getCSSVariableValueInPixels, getHref, getPixelValue, guid, isStringCSSVariable, parseUnit, rectIntersect, stringToHtmlId } from './utils/misc.js';
|
|
75
75
|
export { DefaultRange } from './utils/scale.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unovis/ts",
|
|
3
3
|
"description": "Modular data visualization framework for React, Angular, Svelte, Vue, Solid, and vanilla TypeScript or JavaScript",
|
|
4
|
-
"version": "1.6.2
|
|
4
|
+
"version": "1.6.2",
|
|
5
5
|
"packageManager": "npm@10.9.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/utils/color.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export declare function rgbaToRgb(rgba: string, backgroundColor?: string): RGBCo
|
|
|
18
18
|
* @returns The brightened color in hex format
|
|
19
19
|
*/
|
|
20
20
|
export declare function brighter(inputColor: string, amount: number): string;
|
|
21
|
+
export declare function isColorDark(color: string, threshold?: number): boolean;
|
|
21
22
|
export {};
|
package/utils/color.js
CHANGED
|
@@ -54,7 +54,13 @@ function brighter(inputColor, amount) {
|
|
|
54
54
|
if (!c)
|
|
55
55
|
return inputColor;
|
|
56
56
|
return c.brighter(amount).formatHex();
|
|
57
|
+
}
|
|
58
|
+
function isColorDark(color, threshold = 0.55) {
|
|
59
|
+
const hex = getHexValue(color, document.body);
|
|
60
|
+
if (!hex)
|
|
61
|
+
return false;
|
|
62
|
+
return hexToBrightness(hex) < threshold;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, rgbToBrightness, rgbaToRgb };
|
|
65
|
+
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, isColorDark, rgbToBrightness, rgbaToRgb };
|
|
60
66
|
//# sourceMappingURL=color.js.map
|
package/utils/color.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sources":["../../src/utils/color.ts"],"sourcesContent":["import { color, hcl } from 'd3-color'\n\n// Core\nimport { getCSSColorVariable } from 'styles/colors'\n\n// Utils\nimport { ColorAccessor, StringAccessor } from 'types/accessor'\nimport { getString, isNumber } from 'utils/data'\nimport { isStringCSSVariable, getCSSVariableValue } from 'utils/misc'\n\ntype RGBColor = { r: number; g: number; b: number }\n\n/** Retrieves color from the data if provided, fallbacks to CSS variables if the index was passed */\nexport function getColor<T> (\n d: T,\n accessor: ColorAccessor<T>,\n index?: number,\n dontFallbackToCssVar?: boolean\n): string | null {\n if (Array.isArray(accessor) && isFinite(index)) return accessor[index % accessor.length]\n\n const value = getString(d, accessor as StringAccessor<T>, index)\n return (value || ((isNumber(index) && !dontFallbackToCssVar) ? `var(${getCSSColorVariable(index)})` : null))\n}\n\nexport function hexToRgb (hex: string): RGBColor {\n const parsed = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex)\n return parsed ? {\n r: parseInt(parsed[1], 16),\n g: parseInt(parsed[2], 16),\n b: parseInt(parsed[3], 16),\n } : { r: 0, g: 0, b: 0 }\n}\n\nexport function rgbToBrightness (rgb: RGBColor): number {\n return (0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b) / 255\n}\n\nexport function hexToBrightness (hex: string): number {\n const rgb = hexToRgb(hex)\n return rgbToBrightness(rgb)\n}\n\nexport function getHexValue (s: string, context: HTMLElement | SVGElement): string {\n const hex = isStringCSSVariable(s) ? getCSSVariableValue(s, context) : s\n return color(hex)?.formatHex()\n}\n\nexport function rgbaToRgb (rgba: string, backgroundColor?: string): RGBColor {\n const rgb = color(rgba)?.rgb()\n if (!rgb || rgb.opacity === 1) return rgb\n const alpha = 1 - rgb.opacity\n const bg = color(backgroundColor ?? '#fff').rgb()\n return {\n r: Math.round((rgb.opacity * (rgb.r / 255) + (alpha * (bg.r / 255))) * 255),\n g: Math.round((rgb.opacity * (rgb.g / 255) + (alpha * (bg.g / 255))) * 255),\n b: Math.round((rgb.opacity * (rgb.b / 255) + (alpha * (bg.b / 255))) * 255),\n }\n}\n\n/**\n * Makes a color brighter by a certain amount\n * @param inputColor - The color to brighten (hex, rgb, or rgba)\n * @param amount - Amount to brighten by (0-1)\n * @returns The brightened color in hex format\n */\nexport function brighter (inputColor: string, amount: number): string {\n const c = hcl(inputColor)\n if (!c) return inputColor\n return c.brighter(amount).formatHex()\n}\n"],"names":[],"mappings":";;;;;AAYA;AACM,SAAU,QAAQ,CACtB,CAAI,EACJ,QAA0B,EAC1B,KAAc,EACd,oBAA8B,EAAA;IAE9B,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,MAA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C,IAAI,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;KAC5E,CAAA;AACH,CAAC;AAED;;;;;AAKG;AACa,SAAA,QAAQ,CAAE,UAAkB,EAAE,MAAc,EAAA;AAC1D,IAAA,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAA;AACzB,IAAA,IAAI,CAAC,CAAC;AAAE,QAAA,OAAO,UAAU,CAAA;IACzB,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAA;AACvC;;;;"}
|
|
1
|
+
{"version":3,"file":"color.js","sources":["../../src/utils/color.ts"],"sourcesContent":["import { color, hcl } from 'd3-color'\n\n// Core\nimport { getCSSColorVariable } from 'styles/colors'\n\n// Utils\nimport { ColorAccessor, StringAccessor } from 'types/accessor'\nimport { getString, isNumber } from 'utils/data'\nimport { isStringCSSVariable, getCSSVariableValue } from 'utils/misc'\n\ntype RGBColor = { r: number; g: number; b: number }\n\n/** Retrieves color from the data if provided, fallbacks to CSS variables if the index was passed */\nexport function getColor<T> (\n d: T,\n accessor: ColorAccessor<T>,\n index?: number,\n dontFallbackToCssVar?: boolean\n): string | null {\n if (Array.isArray(accessor) && isFinite(index)) return accessor[index % accessor.length]\n\n const value = getString(d, accessor as StringAccessor<T>, index)\n return (value || ((isNumber(index) && !dontFallbackToCssVar) ? `var(${getCSSColorVariable(index)})` : null))\n}\n\nexport function hexToRgb (hex: string): RGBColor {\n const parsed = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex)\n return parsed ? {\n r: parseInt(parsed[1], 16),\n g: parseInt(parsed[2], 16),\n b: parseInt(parsed[3], 16),\n } : { r: 0, g: 0, b: 0 }\n}\n\nexport function rgbToBrightness (rgb: RGBColor): number {\n return (0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b) / 255\n}\n\nexport function hexToBrightness (hex: string): number {\n const rgb = hexToRgb(hex)\n return rgbToBrightness(rgb)\n}\n\nexport function getHexValue (s: string, context: HTMLElement | SVGElement): string {\n const hex = isStringCSSVariable(s) ? getCSSVariableValue(s, context) : s\n return color(hex)?.formatHex()\n}\n\nexport function rgbaToRgb (rgba: string, backgroundColor?: string): RGBColor {\n const rgb = color(rgba)?.rgb()\n if (!rgb || rgb.opacity === 1) return rgb\n const alpha = 1 - rgb.opacity\n const bg = color(backgroundColor ?? '#fff').rgb()\n return {\n r: Math.round((rgb.opacity * (rgb.r / 255) + (alpha * (bg.r / 255))) * 255),\n g: Math.round((rgb.opacity * (rgb.g / 255) + (alpha * (bg.g / 255))) * 255),\n b: Math.round((rgb.opacity * (rgb.b / 255) + (alpha * (bg.b / 255))) * 255),\n }\n}\n\n/**\n * Makes a color brighter by a certain amount\n * @param inputColor - The color to brighten (hex, rgb, or rgba)\n * @param amount - Amount to brighten by (0-1)\n * @returns The brightened color in hex format\n */\nexport function brighter (inputColor: string, amount: number): string {\n const c = hcl(inputColor)\n if (!c) return inputColor\n return c.brighter(amount).formatHex()\n}\n\nexport function isColorDark (color: string, threshold = 0.55): boolean {\n const hex = getHexValue(color, document.body)\n if (!hex) return false\n return hexToBrightness(hex) < threshold\n}\n"],"names":[],"mappings":";;;;;AAYA;AACM,SAAU,QAAQ,CACtB,CAAI,EACJ,QAA0B,EAC1B,KAAc,EACd,oBAA8B,EAAA;IAE9B,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;IAExF,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,EAAE,QAA6B,EAAE,KAAK,CAAC,CAAA;AAChE,IAAA,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAO,IAAA,EAAA,mBAAmB,CAAC,KAAK,CAAC,CAAA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ACzB,IAAA,IAAI,CAAC,CAAC;AAAE,QAAA,OAAO,UAAU,CAAA;IACzB,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAA;AACvC,CAAC;SAEe,WAAW,CAAE,KAAa,EAAE,SAAS,GAAG,IAAI,EAAA;IAC1D,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC7C,IAAA,IAAI,CAAC,GAAG;AAAE,QAAA,OAAO,KAAK,CAAA;AACtB,IAAA,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AACzC;;;;"}
|
package/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { arrayOfIndices, clamp, clean, cloneDeep, countUnique, ensureArray, filterDataByRange, flatten, getBoolean, getExtent, getMax, getMin, getNearest, getNumber, getStackedData, getStackedExtent, getStackedValues, getString, getValue, groupBy, isAClassInstance, isArray, isEmpty, isEqual, isFunction, isNil, isNumber, isNumberWithinRange, isObject, isPlainObject, isString, isUndefined, merge, omit, shallowDiff, sortBy, throttle, unique, without } from './data.js';
|
|
2
2
|
export { allowedSvgTextTags, escapeStringKeepHash, estimateStringPixelLength, estimateTextSize, estimateWrappedTextHeight, getPreciseStringLengthPx, getWrappedText, kebabCase, kebabCaseToCamel, renderTextIntoFrame, renderTextToSvgTextElement, splitString, textAlignToAnchor, trimSVGText, trimString, trimStringEnd, trimStringMiddle, trimStringStart, wrapSVGText } from './text.js';
|
|
3
3
|
export { allowedSvgTags, getTransformValues, isStringSvg, sanitizeSvgString, transformValuesToString } from './svg.js';
|
|
4
|
-
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, rgbToBrightness, rgbaToRgb } from './color.js';
|
|
4
|
+
export { brighter, getColor, getHexValue, hexToBrightness, hexToRgb, isColorDark, rgbToBrightness, rgbaToRgb } from './color.js';
|
|
5
5
|
export { arrowPolylinePath, circlePath, convertLineToArc, polygon, roundedRectPath, scoreRectPath } from './path.js';
|
|
6
6
|
export { getCSSVariableValue, getCSSVariableValueInPixels, getHref, getPixelValue, guid, isStringCSSVariable, parseUnit, rectIntersect, stringToHtmlId } from './misc.js';
|
|
7
7
|
import './type.js';
|