@elliemae/ds-dataviz 3.14.9 → 3.14.10
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/dist/cjs/graphs/Chart/config/useInternalMargins.js +1 -1
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js.map +1 -1
- package/dist/cjs/graphs/Chart/config/useScales.js +2 -1
- package/dist/cjs/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js +8 -15
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js +8 -3
- package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js.map +2 -2
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js +33 -23
- package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useInternalMargins.js +1 -1
- package/dist/esm/graphs/Chart/config/useInternalMargins.js.map +1 -1
- package/dist/esm/graphs/Chart/config/useScales.js +2 -1
- package/dist/esm/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js +8 -15
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js +8 -3
- package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js.map +2 -2
- package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js +34 -24
- package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
- package/dist/types/graphs/Chart/react-desc-prop-types.d.ts +2 -0
- package/package.json +4 -4
|
@@ -80,7 +80,7 @@ const useInternalMargins = ({
|
|
|
80
80
|
() => ({
|
|
81
81
|
bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,
|
|
82
82
|
top: Math.max(topLegendHeight, toolbarHeight) || 10,
|
|
83
|
-
right: rightLabelWidth + axisRightWidth + rightLegendWidth ||
|
|
83
|
+
right: rightLabelWidth + axisRightWidth + rightLegendWidth || 15,
|
|
84
84
|
left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10
|
|
85
85
|
}),
|
|
86
86
|
[
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/config/useInternalMargins.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useEffect, useState } from 'react';\nimport ResizeObserver from 'resize-observer-polyfill';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (\n ref: SVGGElement | null,\n { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 },\n) => {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setWidth(Math.ceil(entry.contentRect.width + offsetWidth));\n setHeight(Math.ceil(entry.contentRect.height + offsetHeight));\n });\n });\n\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [offsetHeight, offsetWidth, ref]);\n return { width, height };\n};\n\nexport const useInternalMargins = ({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n}: UseInternalMarginsT) => {\n // Toolbar\n const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });\n\n // Axis\n const { width: axisRightWidth } = useResizeObserver(axisRightRef, { offsetWidth: 10 });\n const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });\n const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });\n\n // Labels\n const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });\n const { width: rightLabelWidth } = useResizeObserver(rightLabel, { offsetWidth: 10 });\n const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);\n\n // Legends\n const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });\n const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {\n offsetHeight: 10,\n });\n const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);\n const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });\n\n const internalMargin = useMemo(\n () => ({\n bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,\n top: Math.max(topLegendHeight, toolbarHeight) || 10,\n right: rightLabelWidth + axisRightWidth + rightLegendWidth ||
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useEffect, useState } from 'react';\nimport ResizeObserver from 'resize-observer-polyfill';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (\n ref: SVGGElement | null,\n { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 },\n) => {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setWidth(Math.ceil(entry.contentRect.width + offsetWidth));\n setHeight(Math.ceil(entry.contentRect.height + offsetHeight));\n });\n });\n\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [offsetHeight, offsetWidth, ref]);\n return { width, height };\n};\n\nexport const useInternalMargins = ({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n}: UseInternalMarginsT) => {\n // Toolbar\n const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });\n\n // Axis\n const { width: axisRightWidth } = useResizeObserver(axisRightRef, { offsetWidth: 10 });\n const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });\n const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });\n\n // Labels\n const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });\n const { width: rightLabelWidth } = useResizeObserver(rightLabel, { offsetWidth: 10 });\n const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);\n\n // Legends\n const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });\n const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {\n offsetHeight: 10,\n });\n const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);\n const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });\n\n const internalMargin = useMemo(\n () => ({\n bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,\n top: Math.max(topLegendHeight, toolbarHeight) || 10,\n right: rightLabelWidth + axisRightWidth + rightLegendWidth || 15,\n left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10,\n }),\n\n [\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n toolbarHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n leftLegendWidth,\n ],\n );\n\n return useMemo(\n () => ({\n internalMargin,\n leftLegendHeight,\n leftLegendWidth,\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n }),\n [\n axisBottomHeight,\n toolbarHeight,\n leftLegendHeight,\n axisLeftWidth,\n axisRightWidth,\n bottomLabelHeight,\n bottomLegendHeight,\n internalMargin,\n leftLabelWidth,\n leftLegendWidth,\n rightLabelWidth,\n rightLegendWidth,\n topLegendHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,mBAA6C;AAC7C,sCAA2B;AAkB3B,MAAM,oBAAoB,CACxB,KACA,EAAE,eAAe,GAAG,cAAc,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,EAAE,MAC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|
}
|
|
@@ -177,7 +177,8 @@ const useScales = ({
|
|
|
177
177
|
if (axisProps?.type === "log")
|
|
178
178
|
return new import_scales.LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));
|
|
179
179
|
if (axisProps?.type === "band" || axis === "x" && axisProps?.type === void 0) {
|
|
180
|
-
|
|
180
|
+
const realRange = axis === "y" ? range.reverse() : range;
|
|
181
|
+
return new import_scales.BandScale(getScaleBand(getBandDomain(axisProps), realRange), axisProps);
|
|
181
182
|
}
|
|
182
183
|
return null;
|
|
183
184
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/config/useScales.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useCallback } from 'react';\nimport type { Series } from 'd3';\nimport { max, min, scaleLinear, scaleBand, scaleUtc, scaleOrdinal, scaleLog } from 'd3';\nimport type { DSChartT } from '../react-desc-prop-types';\nimport { getStackedIndex } from '../helpers';\nimport { COLOR_PALLET } from '../helpers/colorPallet';\nimport { TIME_OFFSET } from '../../constants';\nimport { BandScale, LinearScale, TimeLinearScale, LogScale } from '../scales';\ninterface UseScales {\n props: DSChartT.Props;\n innerHeight: number;\n innerWidth: number;\n stackedData: Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n currentData: DSChartT.InternalData;\n groups: string[];\n containerRatio: number;\n}\n\nexport const useScales = ({\n props,\n originalSeries: series,\n innerHeight,\n innerWidth,\n stackedData,\n currentData,\n containerRatio,\n}: UseScales) => {\n const { xAxis, yAxis, y2Axis, groups: stackedSeries, xScroll } = props;\n\n // const xScroll = xAxis.advanced?.pointSpacing?.value > 1;\n const yScroll = yAxis.advanced?.pointSpacing?.value > 1;\n\n const getBandDomain = useCallback(\n (axis: DSChartT.AxisT) => axis.cols ?? [...series[0].data.map((_, i) => i.toString())],\n [series],\n );\n\n const getPadding = (domainPadding: number | Array<number>) =>\n typeof domainPadding === 'number' ? [domainPadding, domainPadding] : domainPadding ?? [0, 0];\n\n const getLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const stackedDataFlatten = stackedData.filter((data) => data.scale === axisString).flat();\n const minStackedData = min(stackedDataFlatten, (layer) => min(layer, (sequence) => sequence[0]));\n const maxStackedData = max(stackedDataFlatten, (layer) => max(layer, (sequence) => sequence[1]));\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n if (typeof minStackedData === 'number') aux.push(minStackedData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (typeof end === 'number' || typeof end === 'object') aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n if (typeof maxStackedData === 'number') aux.push(maxStackedData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n if (typeof minRange === 'number' && typeof maxRange === 'number') {\n // @TODO fix this domain padding\n return [\n minRange - (maxRange - minRange) * (leftPadding ?? 0),\n maxRange + (maxRange - minRange) * (rightPadding ?? 0),\n ];\n }\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData, stackedData],\n );\n\n const getTimeLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n aux.push(begin);\n aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData],\n );\n\n // d3 scale functions\n const getScaleTime = (domain: Date[], range: number[]) => scaleUtc().domain(domain).range(range);\n\n const getScaleBand = (domain: string[], range: number[], padding = 0.2) =>\n scaleBand().domain(domain).range(range).padding(padding).paddingOuter(0.05);\n const getScaleLinear = (domain: number[], range: number[]) => scaleLinear().domain(domain).range(range);\n const getScaleLog = (domain: number[], range: number[]) => scaleLog().domain(domain).range(range);\n\n // dataviz scales\n\n const scaleFactory = useCallback(\n (axis: 'x' | 'y' | 'y2', axisProps: DSChartT.AxisT, range: number[]) => {\n if (!axisProps) return null;\n if (['time', 'datetime'].includes(axisProps?.type)) {\n return new TimeLinearScale(getScaleTime(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'linear' || (['y', 'y2'].includes(axis) && axisProps?.type === undefined)) {\n return new LinearScale(getScaleLinear(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'log') return new LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));\n\n if (axisProps?.type === 'band' || (axis === 'x' && axisProps?.type === undefined)) {\n return new BandScale(getScaleBand(getBandDomain(axisProps), range), axisProps);\n }\n return null;\n },\n [getBandDomain, getLinearDomain],\n );\n\n const xRangeFrom = useMemo(() => containerRatio * (xAxis?.plotRange?.[0] || 0), [containerRatio, xAxis?.plotRange]);\n const xRangeTo = useMemo(\n () => (innerWidth - (xAxis?.plotRange?.[1] || 0)) * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xAxis?.plotRange, xScroll],\n );\n\n const yRangeTo = useMemo(() => yAxis?.plotRange?.[0] || 0, [yAxis?.plotRange]);\n const yRangeFrom = useMemo(\n () => (innerHeight - (yAxis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yAxis?.plotRange, yScroll],\n );\n\n const y2RangeTo = useMemo(() => y2Axis?.plotRange?.[0] || 0, [y2Axis?.plotRange]);\n const y2RangeFrom = useMemo(\n () => (innerHeight - (y2Axis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, y2Axis?.plotRange, yScroll],\n );\n\n const xScale = useMemo(\n () => scaleFactory('x', xAxis, [xRangeFrom, xRangeTo]),\n [scaleFactory, xAxis, xRangeFrom, xRangeTo],\n );\n\n const yScale = useMemo(\n () => scaleFactory('y', yAxis, [yRangeFrom, yRangeTo]),\n [scaleFactory, yAxis, yRangeFrom, yRangeTo],\n );\n\n const y2Scale = useMemo(\n () => scaleFactory('y2', y2Axis, [y2RangeFrom, y2RangeTo]),\n [scaleFactory, y2Axis, y2RangeFrom, y2RangeTo],\n );\n\n const colorScale = useMemo(\n () =>\n scaleOrdinal()\n .domain(series.map((d) => d.name))\n .range(series.map((d) => COLOR_PALLET[d.color as keyof typeof COLOR_PALLET] ?? d.color))\n .unknown('red'),\n [series],\n );\n // get only groups bars to calculate the subgroup scale\n\n const subgroupsWithBars = useMemo(() => {\n const data = currentData\n .filter(\n (serie) => serie.type === 'bar' && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1),\n )\n .map((serie) => serie.name);\n\n if (stackedSeries?.length) {\n stackedSeries.forEach((stackedGroup, i) => {\n if (stackedGroup.length > 0) data.push(`stacked-data-${i}`);\n });\n }\n return data;\n }, [currentData, stackedSeries]);\n\n const getBandwidth = useCallback(() => {\n if (xScale?.type === 'BAND') {\n return xScale.getBandwidth();\n }\n if (yScale?.type === 'BAND') {\n return yScale?.getBandwidth();\n }\n // @todo explore this. is to create bars with a linear axis\n const bar = currentData.filter((serie) => serie.type === 'bar');\n const barsLength = bar.length;\n if (!barsLength) return;\n // we get the size of the bars using the length of the data or the ticks amounts\n // the biggest is the one we use to get the real width we need.\n // we are doing calculations only for x axis because we are not expecting\n // y axis linear cases.\n const divisor = Math.max(bar[0].data.length, xScale?.scale.ticks().length, xScale?.getTicks(innerWidth).length, 1);\n const leftMargin = xScale?.get(bar[0].data[0].value.x);\n const rightMargin = innerWidth * containerRatio - xScale?.get(bar[0].data[bar[0].data.length - 1].value.x);\n\n const width = (innerWidth - (leftMargin + rightMargin)) / divisor;\n if (containerRatio > 1) {\n return Math.max(0.5, width * containerRatio);\n }\n return Math.max(0.5, Math.trunc(width - width * 0.3));\n }, [currentData, innerWidth, containerRatio, xScale, yScale]);\n\n const subGroupScale = useMemo(\n () =>\n getBandwidth()\n ? scaleBand()\n .domain(subgroupsWithBars)\n .range([0, getBandwidth()])\n .paddingInner(0.55)\n .padding(0.2)\n .paddingOuter(0.01)\n : null,\n [getBandwidth, subgroupsWithBars],\n );\n\n return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqC;AAErC,gBAAmF;AAEnF,qBAAgC;AAChC,yBAA6B;AAC7B,uBAA4B;AAC5B,oBAAkE;AAgB3D,MAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAiB;AACf,QAAM,EAAE,OAAO,OAAO,QAAQ,QAAQ,eAAe,QAAQ,IAAI;AAGjE,QAAM,UAAU,MAAM,UAAU,cAAc,QAAQ;AAEtD,QAAM,oBAAgB;AAAA,IACpB,CAAC,SAAyB,KAAK,QAAQ,CAAC,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;AAAA,IACrF,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,aAAa,CAAC,kBAClB,OAAO,kBAAkB,WAAW,CAAC,eAAe,aAAa,IAAI,iBAAiB,CAAC,GAAG,CAAC;AAE7F,QAAM,sBAAkB;AAAA,IACtB,CAAC,MAAsB,eAAiC;AAGtD,YAAM,QAAQ,MAAM,cAAc,IAAI,KAAK,OAAO;AAClD,YAAM,MAAM,KAAK,OAAO;AACxB,YAAM,OAAO,YAEV,OAAO,CAA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;AACtE,UAAI,CAAC;AAAW,eAAO;AACvB,UAAI,CAAC,QAAQ,UAAU,EAAE,SAAS,WAAW,IAAI,GAAG;AAClD,eAAO,IAAI,8BAAgB,aAAa,gBAAgB,WAAW,IAAI,GAAG,KAAK,GAAG,SAAS;AAAA,MAC7F;AAEA,UAAI,WAAW,SAAS,YAAa,CAAC,KAAK,IAAI,EAAE,SAAS,IAAI,KAAK,WAAW,SAAS,QAAY;AACjG,eAAO,IAAI,0BAAY,eAAe,gBAAgB,WAAW,IAAI,GAAG,KAAK,GAAG,SAAS;AAAA,MAC3F;AAEA,UAAI,WAAW,SAAS;AAAO,eAAO,IAAI,uBAAS,YAAY,gBAAgB,WAAW,IAAI,GAAG,KAAK,CAAC;AAEvG,UAAI,WAAW,SAAS,UAAW,SAAS,OAAO,WAAW,SAAS,QAAY;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useCallback } from 'react';\nimport type { Series } from 'd3';\nimport { max, min, scaleLinear, scaleBand, scaleUtc, scaleOrdinal, scaleLog } from 'd3';\nimport type { DSChartT } from '../react-desc-prop-types';\nimport { getStackedIndex } from '../helpers';\nimport { COLOR_PALLET } from '../helpers/colorPallet';\nimport { TIME_OFFSET } from '../../constants';\nimport { BandScale, LinearScale, TimeLinearScale, LogScale } from '../scales';\ninterface UseScales {\n props: DSChartT.Props;\n innerHeight: number;\n innerWidth: number;\n stackedData: Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n currentData: DSChartT.InternalData;\n groups: string[];\n containerRatio: number;\n}\n\nexport const useScales = ({\n props,\n originalSeries: series,\n innerHeight,\n innerWidth,\n stackedData,\n currentData,\n containerRatio,\n}: UseScales) => {\n const { xAxis, yAxis, y2Axis, groups: stackedSeries, xScroll } = props;\n\n // const xScroll = xAxis.advanced?.pointSpacing?.value > 1;\n const yScroll = yAxis.advanced?.pointSpacing?.value > 1;\n\n const getBandDomain = useCallback(\n (axis: DSChartT.AxisT) => axis.cols ?? [...series[0].data.map((_, i) => i.toString())],\n [series],\n );\n\n const getPadding = (domainPadding: number | Array<number>) =>\n typeof domainPadding === 'number' ? [domainPadding, domainPadding] : domainPadding ?? [0, 0];\n\n const getLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const stackedDataFlatten = stackedData.filter((data) => data.scale === axisString).flat();\n const minStackedData = min(stackedDataFlatten, (layer) => min(layer, (sequence) => sequence[0]));\n const maxStackedData = max(stackedDataFlatten, (layer) => max(layer, (sequence) => sequence[1]));\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n if (typeof minStackedData === 'number') aux.push(minStackedData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (typeof end === 'number' || typeof end === 'object') aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n if (typeof maxStackedData === 'number') aux.push(maxStackedData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n if (typeof minRange === 'number' && typeof maxRange === 'number') {\n // @TODO fix this domain padding\n return [\n minRange - (maxRange - minRange) * (leftPadding ?? 0),\n maxRange + (maxRange - minRange) * (rightPadding ?? 0),\n ];\n }\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData, stackedData],\n );\n\n const getTimeLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n aux.push(begin);\n aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData],\n );\n\n // d3 scale functions\n const getScaleTime = (domain: Date[], range: number[]) => scaleUtc().domain(domain).range(range);\n\n const getScaleBand = (domain: string[], range: number[], padding = 0.2) =>\n scaleBand().domain(domain).range(range).padding(padding).paddingOuter(0.05);\n const getScaleLinear = (domain: number[], range: number[]) => scaleLinear().domain(domain).range(range);\n const getScaleLog = (domain: number[], range: number[]) => scaleLog().domain(domain).range(range);\n\n // dataviz scales\n\n const scaleFactory = useCallback(\n (axis: 'x' | 'y' | 'y2', axisProps: DSChartT.AxisT, range: number[]) => {\n if (!axisProps) return null;\n if (['time', 'datetime'].includes(axisProps?.type)) {\n return new TimeLinearScale(getScaleTime(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'linear' || (['y', 'y2'].includes(axis) && axisProps?.type === undefined)) {\n return new LinearScale(getScaleLinear(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'log') return new LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));\n\n if (axisProps?.type === 'band' || (axis === 'x' && axisProps?.type === undefined)) {\n // we need to reverse the range in case is a horizontal bar char\n const realRange = axis === 'y' ? range.reverse() : range;\n return new BandScale(getScaleBand(getBandDomain(axisProps), realRange), axisProps);\n }\n return null;\n },\n [getBandDomain, getLinearDomain],\n );\n\n const xRangeFrom = useMemo(() => containerRatio * (xAxis?.plotRange?.[0] || 0), [containerRatio, xAxis?.plotRange]);\n const xRangeTo = useMemo(\n () => (innerWidth - (xAxis?.plotRange?.[1] || 0)) * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xAxis?.plotRange, xScroll],\n );\n\n const yRangeTo = useMemo(() => yAxis?.plotRange?.[0] || 0, [yAxis?.plotRange]);\n const yRangeFrom = useMemo(\n () => (innerHeight - (yAxis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yAxis?.plotRange, yScroll],\n );\n\n const y2RangeTo = useMemo(() => y2Axis?.plotRange?.[0] || 0, [y2Axis?.plotRange]);\n const y2RangeFrom = useMemo(\n () => (innerHeight - (y2Axis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, y2Axis?.plotRange, yScroll],\n );\n\n const xScale = useMemo(\n () => scaleFactory('x', xAxis, [xRangeFrom, xRangeTo]),\n [scaleFactory, xAxis, xRangeFrom, xRangeTo],\n );\n\n const yScale = useMemo(\n () => scaleFactory('y', yAxis, [yRangeFrom, yRangeTo]),\n [scaleFactory, yAxis, yRangeFrom, yRangeTo],\n );\n\n const y2Scale = useMemo(\n () => scaleFactory('y2', y2Axis, [y2RangeFrom, y2RangeTo]),\n [scaleFactory, y2Axis, y2RangeFrom, y2RangeTo],\n );\n\n const colorScale = useMemo(\n () =>\n scaleOrdinal()\n .domain(series.map((d) => d.name))\n .range(series.map((d) => COLOR_PALLET[d.color as keyof typeof COLOR_PALLET] ?? d.color))\n .unknown('red'),\n [series],\n );\n // get only groups bars to calculate the subgroup scale\n\n const subgroupsWithBars = useMemo(() => {\n const data = currentData\n .filter(\n (serie) => serie.type === 'bar' && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1),\n )\n .map((serie) => serie.name);\n\n if (stackedSeries?.length) {\n stackedSeries.forEach((stackedGroup, i) => {\n if (stackedGroup.length > 0) data.push(`stacked-data-${i}`);\n });\n }\n return data;\n }, [currentData, stackedSeries]);\n\n const getBandwidth = useCallback(() => {\n if (xScale?.type === 'BAND') {\n return xScale.getBandwidth();\n }\n if (yScale?.type === 'BAND') {\n return yScale?.getBandwidth();\n }\n // @todo explore this. is to create bars with a linear axis\n const bar = currentData.filter((serie) => serie.type === 'bar');\n const barsLength = bar.length;\n if (!barsLength) return;\n // we get the size of the bars using the length of the data or the ticks amounts\n // the biggest is the one we use to get the real width we need.\n // we are doing calculations only for x axis because we are not expecting\n // y axis linear cases.\n const divisor = Math.max(bar[0].data.length, xScale?.scale.ticks().length, xScale?.getTicks(innerWidth).length, 1);\n const leftMargin = xScale?.get(bar[0].data[0].value.x);\n const rightMargin = innerWidth * containerRatio - xScale?.get(bar[0].data[bar[0].data.length - 1].value.x);\n\n const width = (innerWidth - (leftMargin + rightMargin)) / divisor;\n if (containerRatio > 1) {\n return Math.max(0.5, width * containerRatio);\n }\n return Math.max(0.5, Math.trunc(width - width * 0.3));\n }, [currentData, innerWidth, containerRatio, xScale, yScale]);\n\n const subGroupScale = useMemo(\n () =>\n getBandwidth()\n ? scaleBand()\n .domain(subgroupsWithBars)\n .range([0, getBandwidth()])\n .paddingInner(0.55)\n .padding(0.2)\n .paddingOuter(0.01)\n : null,\n [getBandwidth, subgroupsWithBars],\n );\n\n return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqC;AAErC,gBAAmF;AAEnF,qBAAgC;AAChC,yBAA6B;AAC7B,uBAA4B;AAC5B,oBAAkE;AAgB3D,MAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAiB;AACf,QAAM,EAAE,OAAO,OAAO,QAAQ,QAAQ,eAAe,QAAQ,IAAI;AAGjE,QAAM,UAAU,MAAM,UAAU,cAAc,QAAQ;AAEtD,QAAM,oBAAgB;AAAA,IACpB,CAAC,SAAyB,KAAK,QAAQ,CAAC,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;AAAA,IACrF,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,aAAa,CAAC,kBAClB,OAAO,kBAAkB,WAAW,CAAC,eAAe,aAAa,IAAI,iBAAiB,CAAC,GAAG,CAAC;AAE7F,QAAM,sBAAkB;AAAA,IACtB,CAAC,MAAsB,eAAiC;AAGtD,YAAM,QAAQ,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}
|
|
@@ -37,14 +37,17 @@ var import_GridLine = require("./GridLine");
|
|
|
37
37
|
var import_colorPallet = require("../../helpers/colorPallet");
|
|
38
38
|
const AxisBottom = import_react.default.memo(() => {
|
|
39
39
|
const {
|
|
40
|
-
props: { xAxis },
|
|
40
|
+
props: { xAxis, xScroll },
|
|
41
41
|
innerHeight,
|
|
42
42
|
xScale,
|
|
43
|
-
yScale,
|
|
44
43
|
innerWidth,
|
|
45
44
|
containerRatio,
|
|
46
45
|
setAxisBottomRef
|
|
47
46
|
} = (0, import_react.useContext)(import_ChartContext.ChartContext);
|
|
47
|
+
const realInnerWidth = (0, import_react.useMemo)(
|
|
48
|
+
() => innerWidth * (xScroll ? containerRatio : 1),
|
|
49
|
+
[containerRatio, innerWidth, xScroll]
|
|
50
|
+
);
|
|
48
51
|
const { tickRotation } = xAxis.tick || {};
|
|
49
52
|
const { showGrid } = xAxis;
|
|
50
53
|
const textProps = (0, import_react.useMemo)(() => {
|
|
@@ -107,7 +110,7 @@ const AxisBottom = import_react.default.memo(() => {
|
|
|
107
110
|
return null;
|
|
108
111
|
const lineCoords = {
|
|
109
112
|
x1: 0,
|
|
110
|
-
x2:
|
|
113
|
+
x2: realInnerWidth,
|
|
111
114
|
y1: innerHeight,
|
|
112
115
|
y2: innerHeight
|
|
113
116
|
};
|
|
@@ -117,22 +120,12 @@ const AxisBottom = import_react.default.memo(() => {
|
|
|
117
120
|
lineCoords,
|
|
118
121
|
scale: xScale,
|
|
119
122
|
innerRef: setAxisBottomRef,
|
|
120
|
-
dimension:
|
|
123
|
+
dimension: realInnerWidth,
|
|
121
124
|
TickRenderer,
|
|
122
125
|
GridRenderer,
|
|
123
126
|
color: axisColor
|
|
124
127
|
}
|
|
125
128
|
);
|
|
126
|
-
}, [
|
|
127
|
-
GridRenderer,
|
|
128
|
-
TickRenderer,
|
|
129
|
-
containerRatio,
|
|
130
|
-
axisColor,
|
|
131
|
-
innerHeight,
|
|
132
|
-
innerWidth,
|
|
133
|
-
setAxisBottomRef,
|
|
134
|
-
xAxis.hideAxis,
|
|
135
|
-
xScale
|
|
136
|
-
]);
|
|
129
|
+
}, [GridRenderer, TickRenderer, axisColor, innerHeight, realInnerWidth, setAxisBottomRef, xAxis.hideAxis, xScale]);
|
|
137
130
|
});
|
|
138
131
|
//# sourceMappingURL=AxisBottom.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/graphs/Chart/parts/Axis/AxisBottom.tsx", "../../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext, useMemo, useCallback } from 'react';\nimport type { CSSProperties } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type GridRenderPropsT, type TickRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis },\n innerHeight,\n xScale,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext, useMemo, useCallback } from 'react';\nimport type { CSSProperties } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type GridRenderPropsT, type TickRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis, xScroll },\n innerHeight,\n xScale,\n innerWidth,\n containerRatio,\n setAxisBottomRef,\n } = useContext(ChartContext);\n\n const realInnerWidth = useMemo(\n () => innerWidth * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xScroll],\n );\n\n const { tickRotation } = xAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = xAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, y: 17 };\n return {\n ...commomProps,\n dx: 8 * Math.sin(Math.PI * (tickRotation / 180)),\n dy: '.71em',\n y: Math.ceil(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1)),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, xAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(() => {\n if (!tickRotation) return { textAnchor: 'middle' };\n return { textAnchor: tickRotation > 0 ? 'start' : 'end' };\n }, [tickRotation]);\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: position,\n x2: position,\n y1: 0,\n y2: innerHeight,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [innerHeight, showGrid],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n y2: 5,\n stroke: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n tickValue={xScale.getTickFormatted(tickValue)}\n xTranslate={position}\n yTranslate={innerHeight}\n textProps={textProps}\n textStyle={style}\n {...rest}\n />\n );\n },\n [xAxis?.tick?.color, xScale, innerHeight, textProps, style],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[xAxis.color as keyof typeof COLOR_PALLET] || xAxis.color, [xAxis.color]);\n\n return useMemo(() => {\n if (xAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: realInnerWidth,\n y1: innerHeight,\n y2: innerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={xScale}\n innerRef={setAxisBottomRef}\n dimension={realInnerWidth}\n TickRenderer={TickRenderer}\n GridRenderer={GridRenderer}\n color={axisColor}\n />\n );\n }, [GridRenderer, TickRenderer, axisColor, innerHeight, realInnerWidth, setAxisBottomRef, xAxis.hideAxis, xScale]);\n});\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADyDV;AAvDb,mBAAwD;AAExD,0BAA6B;AAE7B,kBAAmE;AACnE,kBAAqB;AACrB,sBAAyB;AACzB,yBAA6B;AAEtB,MAAM,aAAa,aAAAA,QAAM,KAAK,MAAM;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,OAAO,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,gCAAY;AAE3B,QAAM,qBAAiB;AAAA,IACrB,MAAM,cAAc,UAAU,iBAAiB;AAAA,IAC/C,CAAC,gBAAgB,YAAY,OAAO;AAAA,EACtC;AAEA,QAAM,EAAE,aAAa,IAAI,MAAM,QAAS,CAAC;AACzC,QAAM,EAAE,SAAS,IAAI;AAErB,QAAM,gBAAY,sBAAQ,MAAM;AAC9B,UAAM,cAAc,EAAE,MAAM,gCAAa,OAAO,MAAM,UAAuC,OAAO,MAAM,MAAM;AAChH,QAAI,CAAC;AAAc,aAAO,EAAE,GAAG,aAAa,GAAG,GAAG;AAClD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,IAAI,IAAI,KAAK,IAAI,KAAK,MAAM,eAAe,IAAI;AAAA,MAC/C,IAAI;AAAA,MACJ,GAAG,KAAK,KAAK,OAAO,OAAO,eAAe,OAAO,eAAe,IAAI,IAAI,GAAG;AAAA,MAC3E,WAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,c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IACN;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ,GAAG,CAAC,cAAc,cAAc,WAAW,aAAa,gBAAgB,kBAAkB,MAAM,UAAU,MAAM,CAAC;AACnH,CAAC;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -37,15 +37,20 @@ var import_GridLine = require("./GridLine");
|
|
|
37
37
|
var import_colorPallet = require("../../helpers/colorPallet");
|
|
38
38
|
const AxisLeft = import_react.default.memo(() => {
|
|
39
39
|
const {
|
|
40
|
-
props: { yAxis },
|
|
40
|
+
props: { yAxis, yScroll },
|
|
41
41
|
innerHeight,
|
|
42
42
|
height,
|
|
43
43
|
yScale,
|
|
44
44
|
innerWidth,
|
|
45
|
+
containerRatio,
|
|
45
46
|
setAxisLeftRef
|
|
46
47
|
} = (0, import_react.useContext)(import_ChartContext.ChartContext);
|
|
47
48
|
const { tickRotation } = yAxis.tick || {};
|
|
48
49
|
const { showGrid } = yAxis;
|
|
50
|
+
const realInnerHeight = (0, import_react.useMemo)(
|
|
51
|
+
() => innerHeight * (yScroll ? containerRatio : 1),
|
|
52
|
+
[containerRatio, innerHeight, yScroll]
|
|
53
|
+
);
|
|
49
54
|
const textProps = (0, import_react.useMemo)(() => {
|
|
50
55
|
const commomProps = { fill: import_colorPallet.COLOR_PALLET[yAxis?.tick?.color] || yAxis?.tick?.color };
|
|
51
56
|
if (!tickRotation)
|
|
@@ -109,7 +114,7 @@ const AxisLeft = import_react.default.memo(() => {
|
|
|
109
114
|
x1: 0,
|
|
110
115
|
x2: 0,
|
|
111
116
|
y1: 0,
|
|
112
|
-
y2:
|
|
117
|
+
y2: realInnerHeight
|
|
113
118
|
};
|
|
114
119
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
120
|
import_Axis.Axis,
|
|
@@ -123,6 +128,6 @@ const AxisLeft = import_react.default.memo(() => {
|
|
|
123
128
|
color: axisColor
|
|
124
129
|
}
|
|
125
130
|
);
|
|
126
|
-
}, [GridRenderer, TickRenderer, axisColor, height,
|
|
131
|
+
}, [GridRenderer, TickRenderer, axisColor, height, realInnerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);
|
|
127
132
|
});
|
|
128
133
|
//# sourceMappingURL=AxisLeft.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/graphs/Chart/parts/Axis/AxisLeft.tsx", "../../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { type CSSProperties, useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type TickRenderPropsT, type GridRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisLeft = React.memo(() => {\n const {\n props: { yAxis },\n innerHeight,\n height,\n yScale,\n innerWidth,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = yAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = yAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, x: -10, dy: '0.32em' };\n return {\n ...commomProps,\n dy: '.30em',\n dx: '-.10em',\n x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, yAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(\n () => ({\n textAnchor: 'end',\n }),\n [],\n );\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: 0,\n x2: innerWidth,\n y1: position,\n y2: position,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [showGrid, innerWidth],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n x2: -5,\n stroke: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n xTranslate={0}\n yTranslate={position}\n textProps={textProps}\n textStyle={style}\n tickValue={yScale.getTickFormatted(tickValue)}\n {...rest}\n />\n );\n },\n [style, textProps, yAxis?.tick?.color, yScale],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[yAxis.color as keyof typeof COLOR_PALLET] || yAxis.color, [yAxis.color]);\n\n return useMemo(() => {\n if (yAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: 0,\n y1: 0,\n y2:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { type CSSProperties, useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type TickRenderPropsT, type GridRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisLeft = React.memo(() => {\n const {\n props: { yAxis, yScroll },\n innerHeight,\n height,\n yScale,\n innerWidth,\n containerRatio,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = yAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = yAxis;\n\n const realInnerHeight = useMemo(\n () => innerHeight * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yScroll],\n );\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, x: -10, dy: '0.32em' };\n return {\n ...commomProps,\n dy: '.30em',\n dx: '-.10em',\n x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, yAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(\n () => ({\n textAnchor: 'end',\n }),\n [],\n );\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: 0,\n x2: innerWidth,\n y1: position,\n y2: position,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [showGrid, innerWidth],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n x2: -5,\n stroke: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n xTranslate={0}\n yTranslate={position}\n textProps={textProps}\n textStyle={style}\n tickValue={yScale.getTickFormatted(tickValue)}\n {...rest}\n />\n );\n },\n [style, textProps, yAxis?.tick?.color, yScale],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[yAxis.color as keyof typeof COLOR_PALLET] || yAxis.color, [yAxis.color]);\n\n return useMemo(() => {\n if (yAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: 0,\n y1: 0,\n y2: realInnerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={yScale}\n innerRef={setAxisLeftRef}\n dimension={height}\n GridRenderer={GridRenderer}\n TickRenderer={TickRenderer}\n color={axisColor}\n />\n );\n }, [GridRenderer, TickRenderer, axisColor, height, realInnerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);\n});\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;AD0DV;AAxDb,mBAA4E;AAC5E,0BAA6B;AAE7B,kBAAmE;AACnE,kBAAqB;AACrB,sBAAyB;AACzB,yBAA6B;AAEtB,MAAM,WAAW,aAAAA,QAAM,KAAK,MAAM;AACvC,QAAM;AAAA,IACJ,OAAO,EAAE,OAAO,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,gCAAY;AAE3B,QAAM,EAAE,aAAa,IAAI,MAAM,QAAS,CAAC;AACzC,QAAM,EAAE,SAAS,IAAI;AAErB,QAAM,sBAAkB;AAAA,IACtB,MAAM,eAAe,UAAU,iBAAiB;AAAA,IAChD,CAAC,gBAAgB,aAAa,OAAO;AAAA,EACvC;AAEA,QAAM,gBAAY,sBAAQ,MAAM;AAC9B,UAAM,cAAc,EAAE,MAAM,gCAAa,OAAO,MAAM,UAAuC,OAAO,MAAM,MAAM;AAChH,QAAI,CAAC;AAAc,aAAO,EAAE,GAAG,aAAa,GAAG,KAAK,IAAI,SAAS;AACjE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,GAAG,KAAK,MAAM,EAAE,OAAO,OAAO,eAAe,OAAO,eAAe,IAAI,IAAI,IAAI;AAAA,MAC/E,WAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,cAAc,OAAO,MAAM,KAAK,CAAC;AAErC,QAAM,YAAuB;AAAA,IAC3B,OAAO;AAAA,MACL,YAAY;AAAA,IACd;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,mBAAe;AAAA,IACnB,CAAC,UAA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,CAAC;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/graphs/Chart/react-desc-prop-types.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { globalAttributesPropTypes, PropTypes } from '@elliemae/ds-utilities';\nimport type { Series, ScaleLinear, ScaleBand } from 'd3';\nexport declare namespace DSChartT {\n export type SerieTypeT = 'line' | 'bar' | 'area' | 'point';\n export type AxisTypeT = 'log' | 'band' | 'time' | 'linear';\n\n export type LinearScale = ScaleLinear<number, number, never>;\n export type BandScale = ScaleBand<string>;\n\n export type Scales = LinearScale | BandScale;\n export interface SeriesT {\n name: string;\n data: Array<number | null | { x: number; y: number }>;\n type: SerieTypeT;\n scale?: string;\n color?: string;\n // line\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export interface ScrapperT {\n type: 'horizontal' | 'vertical';\n color: string;\n tooltipPreference: string;\n }\n\n export interface SerieComponentT {\n serie: InternalSerie;\n }\n\n export interface LegendT {\n position: 'right' | 'bottom' | 'left' | 'top';\n preventFilterAction: boolean;\n }\n\n export interface AxisTickT {\n tickValues: number[] | Date[];\n tickFormat?: (value: string | number | Date) => string;\n tickCount: number;\n tickRotation: number;\n overwriteTicks: boolean;\n color: string;\n }\n\n export interface AxisT {\n showGrid: boolean;\n color: string;\n label: string;\n type: AxisTypeT;\n cols?: string[];\n domainPadding: number;\n hideAxis: boolean;\n beginAtZero?: boolean;\n advanced: {\n pointSpacing: {\n type: 'string';\n value: number;\n };\n };\n tick: AxisTickT;\n plotRange: number[];\n }\n\n export interface InternalDatum {\n key: string;\n value: number | { x: number; y: number };\n position: number;\n serie: string;\n }\n\n export interface InternalSerie {\n key: string;\n data: InternalDatum[];\n name: string;\n type: DSChartT.SerieTypeT;\n scale?: string | undefined;\n color?: string;\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export type InternalData = InternalSerie[];\n\n export interface OptionalProps {\n groups?: string[][];\n types?: 'scatter';\n scrapper: ScrapperT;\n withTrendHighlight: boolean;\n TooltipRenderer: () => JSX.Element;\n height: number;\n width: number;\n legend: LegendT;\n }\n\n export interface DefaultProps {\n yAxis: AxisT;\n xAxis: AxisT;\n y2Axis: AxisT;\n series: SeriesT[];\n }\n\n export interface RequiredProps {}\n\n export interface Props extends OptionalProps, DefaultProps, RequiredProps {}\n\n export type StackedSeriesByGroupT = Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n}\n\nexport const defaultProps: DSChartT.DefaultProps = {\n series: [\n {\n name: '1',\n data: [0],\n color: 'grey-100',\n type: 'bar',\n },\n ],\n xAxis: {\n cols: ['0'],\n },\n yAxis: {},\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n height: PropTypes.number.isRequired.description('height').defaultValue(''),\n width: PropTypes.number.isRequired.description('height').defaultValue(''),\n margin: PropTypes.shape({\n top: PropTypes.number,\n bottom: PropTypes.number,\n left: PropTypes.number,\n right: PropTypes.number,\n })\n .isRequired.description('margin')\n .defaultValue(''),\n series: PropTypes.arrayOf(PropTypes.object).description('yValue').defaultValue(''),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAAqD;
|
|
4
|
+
"sourcesContent": ["import { globalAttributesPropTypes, PropTypes } from '@elliemae/ds-utilities';\nimport type { Series, ScaleLinear, ScaleBand } from 'd3';\nexport declare namespace DSChartT {\n export type SerieTypeT = 'line' | 'bar' | 'area' | 'point';\n export type AxisTypeT = 'log' | 'band' | 'time' | 'linear';\n\n export type LinearScale = ScaleLinear<number, number, never>;\n export type BandScale = ScaleBand<string>;\n\n export type Scales = LinearScale | BandScale;\n export interface SeriesT {\n name: string;\n data: Array<number | null | { x: number; y: number }>;\n type: SerieTypeT;\n scale?: string;\n color?: string;\n // line\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export interface ScrapperT {\n type: 'horizontal' | 'vertical';\n color: string;\n tooltipPreference: string;\n }\n\n export interface SerieComponentT {\n serie: InternalSerie;\n }\n\n export interface LegendT {\n position: 'right' | 'bottom' | 'left' | 'top';\n preventFilterAction: boolean;\n }\n\n export interface AxisTickT {\n tickValues: number[] | Date[];\n tickFormat?: (value: string | number | Date) => string;\n tickCount: number;\n tickRotation: number;\n overwriteTicks: boolean;\n color: string;\n }\n\n export interface AxisT {\n showGrid: boolean;\n color: string;\n label: string;\n type: AxisTypeT;\n cols?: string[];\n domainPadding: number;\n hideAxis: boolean;\n beginAtZero?: boolean;\n advanced: {\n pointSpacing: {\n type: 'string';\n value: number;\n };\n };\n tick: AxisTickT;\n plotRange: number[];\n }\n\n export interface InternalDatum {\n key: string;\n value: number | { x: number; y: number };\n position: number;\n serie: string;\n }\n\n export interface InternalSerie {\n key: string;\n data: InternalDatum[];\n name: string;\n type: DSChartT.SerieTypeT;\n scale?: string | undefined;\n color?: string;\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export type InternalData = InternalSerie[];\n\n export interface OptionalProps {\n groups?: string[][];\n types?: 'scatter';\n scrapper: ScrapperT;\n withTrendHighlight: boolean;\n TooltipRenderer: () => JSX.Element;\n height: number;\n width: number;\n legend: LegendT;\n xScroll: boolean;\n yScroll: boolean;\n }\n\n export interface DefaultProps {\n yAxis: AxisT;\n xAxis: AxisT;\n y2Axis: AxisT;\n series: SeriesT[];\n }\n\n export interface RequiredProps {}\n\n export interface Props extends OptionalProps, DefaultProps, RequiredProps {}\n\n export type StackedSeriesByGroupT = Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n}\n\nexport const defaultProps: DSChartT.DefaultProps = {\n series: [\n {\n name: '1',\n data: [0],\n color: 'grey-100',\n type: 'bar',\n },\n ],\n xAxis: {\n cols: ['0'],\n },\n yAxis: {},\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n height: PropTypes.number.isRequired.description('height').defaultValue(''),\n width: PropTypes.number.isRequired.description('height').defaultValue(''),\n margin: PropTypes.shape({\n top: PropTypes.number,\n bottom: PropTypes.number,\n left: PropTypes.number,\n right: PropTypes.number,\n })\n .isRequired.description('margin')\n .defaultValue(''),\n series: PropTypes.arrayOf(PropTypes.object).description('yValue').defaultValue(''),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAAqD;AAoH9C,MAAM,eAAsC;AAAA,EACjD,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,MAAM,CAAC,CAAC;AAAA,MACR,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,MAAM,CAAC,GAAG;AAAA,EACZ;AAAA,EACA,OAAO,CAAC;AACV;AAEO,MAAM,YAAY;AAAA,EACvB,GAAG;AAAA,EACH,QAAQ,8BAAU,OAAO,WAAW,YAAY,QAAQ,EAAE,aAAa,EAAE;AAAA,EACzE,OAAO,8BAAU,OAAO,WAAW,YAAY,QAAQ,EAAE,aAAa,EAAE;AAAA,EACxE,QAAQ,8BAAU,MAAM;AAAA,IACtB,KAAK,8BAAU;AAAA,IACf,QAAQ,8BAAU;AAAA,IAClB,MAAM,8BAAU;AAAA,IAChB,OAAO,8BAAU;AAAA,EACnB,CAAC,EACE,WAAW,YAAY,QAAQ,EAC/B,aAAa,EAAE;AAAA,EAClB,QAAQ,8BAAU,QAAQ,8BAAU,MAAM,EAAE,YAAY,QAAQ,EAAE,aAAa,EAAE;AACnF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -35,38 +35,48 @@ var import_ChartContext = require("../ChartContext");
|
|
|
35
35
|
var import_helpers = require("../helpers");
|
|
36
36
|
const HorizontalStackedBars = ({ serie }) => {
|
|
37
37
|
const {
|
|
38
|
-
props: { groups },
|
|
38
|
+
props: { groups, yScroll },
|
|
39
39
|
xScale,
|
|
40
40
|
yScale,
|
|
41
41
|
stackedData,
|
|
42
42
|
subGroupScale,
|
|
43
43
|
colorScale,
|
|
44
|
+
innerHeight,
|
|
45
|
+
containerRatio,
|
|
44
46
|
chartId,
|
|
45
47
|
getYValue
|
|
46
48
|
} = (0, import_react.useContext)(import_ChartContext.ChartContext);
|
|
47
49
|
const serieWithStackedValues = (0, import_helpers.getStackedData)(stackedData, serie);
|
|
48
50
|
const stackIndex = (0, import_helpers.getStackedIndex)(groups, serie.name);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
const realInnerHeight = (0, import_react.useMemo)(
|
|
52
|
+
() => innerHeight * (yScroll ? containerRatio : 1),
|
|
53
|
+
[containerRatio, innerHeight, yScroll]
|
|
54
|
+
);
|
|
55
|
+
return (0, import_react.useMemo)(
|
|
56
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { children: serie.data.map((bar, i) => {
|
|
57
|
+
const sequence = serieWithStackedValues[bar.position];
|
|
58
|
+
const isFloorStack = sequence[0] === 0;
|
|
59
|
+
const xValue = sequence[1] - sequence[0];
|
|
60
|
+
const yValue = getYValue(serie.data[i]);
|
|
61
|
+
const width = xScale.get(sequence[1]) - xScale.get(sequence[0]) - (!isFloorStack ? 2 : 0);
|
|
62
|
+
const height = subGroupScale?.bandwidth();
|
|
63
|
+
const transformX = xScale.get(sequence[0]) + (!isFloorStack ? 2 : 0);
|
|
64
|
+
const transformY = subGroupScale(`stacked-data-${stackIndex}`) + yScale.get(yValue);
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { clipPath: `url(#rect-focus-ring-${chartId})`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { fill: colorScale(serie.name), transform: `translate(0, ${transformY})`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
66
|
+
import_Rect.Rect,
|
|
67
|
+
{
|
|
68
|
+
width,
|
|
69
|
+
height,
|
|
70
|
+
x: transformX,
|
|
71
|
+
xValue,
|
|
72
|
+
yValue,
|
|
73
|
+
id: serie.data[i]?.key,
|
|
74
|
+
name: serie.name,
|
|
75
|
+
datum: serie.data[i]
|
|
76
|
+
}
|
|
77
|
+
) }) }, serie.data[i]?.key);
|
|
78
|
+
}) }),
|
|
79
|
+
[chartId, colorScale, getYValue, serie, serieWithStackedValues, stackIndex, subGroupScale, xScale, yScale]
|
|
80
|
+
);
|
|
71
81
|
};
|
|
72
82
|
//# sourceMappingURL=HorizontalStackedBars.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/series/HorizontalStackedBars.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable complexity */\nimport React, { useContext } from 'react';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\nimport React, { useContext, useMemo } from 'react';\nimport { Rect } from './Rect';\nimport { ChartContext } from '../ChartContext';\nimport { getStackedData, getStackedIndex } from '../helpers';\nimport type { DSChartT } from '../react-desc-prop-types';\n\nexport const HorizontalStackedBars = ({ serie }: DSChartT.SerieComponentT) => {\n const {\n props: { groups, yScroll },\n xScale,\n yScale,\n stackedData,\n subGroupScale,\n colorScale,\n innerHeight,\n containerRatio,\n chartId,\n getYValue,\n } = useContext(ChartContext);\n const serieWithStackedValues = getStackedData(stackedData, serie);\n const stackIndex = getStackedIndex(groups, serie.name);\n\n const realInnerHeight = useMemo(\n () => innerHeight * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yScroll],\n );\n\n return useMemo(\n () => (\n <g>\n {serie.data.map((bar, i) => {\n const sequence = serieWithStackedValues[bar.position];\n const isFloorStack = sequence[0] === 0;\n const xValue = sequence[1] - sequence[0];\n const yValue = getYValue(serie.data[i]);\n\n const width = xScale.get(sequence[1]) - xScale.get(sequence[0]) - (!isFloorStack ? 2 : 0);\n\n const height = subGroupScale?.bandwidth();\n\n const transformX = xScale.get(sequence[0]) + (!isFloorStack ? 2 : 0);\n const transformY = subGroupScale(`stacked-data-${stackIndex}`) + yScale.get(yValue);\n return (\n <g key={serie.data[i]?.key} clipPath={`url(#rect-focus-ring-${chartId})`}>\n <g fill={colorScale(serie.name)} transform={`translate(0, ${transformY})`}>\n <Rect\n width={width}\n height={height}\n x={transformX}\n xValue={xValue}\n yValue={yValue}\n id={serie.data[i]?.key}\n name={serie.name}\n datum={serie.data[i]}\n />\n </g>\n </g>\n );\n })}\n </g>\n ),\n [chartId, colorScale, getYValue, serie, serieWithStackedValues, stackIndex, subGroupScale, xScale, yScale],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;AD8CP;AA7ChB,mBAA2C;AAC3C,kBAAqB;AACrB,0BAA6B;AAC7B,qBAAgD;AAGzC,MAAM,wBAAwB,CAAC,EAAE,MAAM,MAAgC;AAC5E,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ,QAAQ;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,gCAAY;AAC3B,QAAM,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ight + bottomLegendHeight + bottomLabelHeight || 10,
|
|
53
53
|
top: Math.max(topLegendHeight, toolbarHeight) || 10,
|
|
54
|
-
right: rightLabelWidth + axisRightWidth + rightLegendWidth ||
|
|
54
|
+
right: rightLabelWidth + axisRightWidth + rightLegendWidth || 15,
|
|
55
55
|
left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10
|
|
56
56
|
}),
|
|
57
57
|
[
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useInternalMargins.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useEffect, useState } from 'react';\nimport ResizeObserver from 'resize-observer-polyfill';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (\n ref: SVGGElement | null,\n { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 },\n) => {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setWidth(Math.ceil(entry.contentRect.width + offsetWidth));\n setHeight(Math.ceil(entry.contentRect.height + offsetHeight));\n });\n });\n\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [offsetHeight, offsetWidth, ref]);\n return { width, height };\n};\n\nexport const useInternalMargins = ({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n}: UseInternalMarginsT) => {\n // Toolbar\n const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });\n\n // Axis\n const { width: axisRightWidth } = useResizeObserver(axisRightRef, { offsetWidth: 10 });\n const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });\n const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });\n\n // Labels\n const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });\n const { width: rightLabelWidth } = useResizeObserver(rightLabel, { offsetWidth: 10 });\n const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);\n\n // Legends\n const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });\n const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {\n offsetHeight: 10,\n });\n const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);\n const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });\n\n const internalMargin = useMemo(\n () => ({\n bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,\n top: Math.max(topLegendHeight, toolbarHeight) || 10,\n right: rightLabelWidth + axisRightWidth + rightLegendWidth ||
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useEffect, useState } from 'react';\nimport ResizeObserver from 'resize-observer-polyfill';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (\n ref: SVGGElement | null,\n { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 },\n) => {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setWidth(Math.ceil(entry.contentRect.width + offsetWidth));\n setHeight(Math.ceil(entry.contentRect.height + offsetHeight));\n });\n });\n\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [offsetHeight, offsetWidth, ref]);\n return { width, height };\n};\n\nexport const useInternalMargins = ({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n}: UseInternalMarginsT) => {\n // Toolbar\n const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });\n\n // Axis\n const { width: axisRightWidth } = useResizeObserver(axisRightRef, { offsetWidth: 10 });\n const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });\n const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });\n\n // Labels\n const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });\n const { width: rightLabelWidth } = useResizeObserver(rightLabel, { offsetWidth: 10 });\n const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);\n\n // Legends\n const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });\n const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {\n offsetHeight: 10,\n });\n const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);\n const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });\n\n const internalMargin = useMemo(\n () => ({\n bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,\n top: Math.max(topLegendHeight, toolbarHeight) || 10,\n right: rightLabelWidth + axisRightWidth + rightLegendWidth || 15,\n left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10,\n }),\n\n [\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n toolbarHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n leftLegendWidth,\n ],\n );\n\n return useMemo(\n () => ({\n internalMargin,\n leftLegendHeight,\n leftLegendWidth,\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n }),\n [\n axisBottomHeight,\n toolbarHeight,\n leftLegendHeight,\n axisLeftWidth,\n axisRightWidth,\n bottomLabelHeight,\n bottomLegendHeight,\n internalMargin,\n leftLabelWidth,\n leftLegendWidth,\n rightLabelWidth,\n rightLegendWidth,\n topLegendHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n ],\n );\n};\n"],
|
|
5
5
|
"mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,SAAS,WAAW,gBAAgB;AAC7C,OAAO,oBAAoB;AAkB3B,MAAM,oBAAoB,CACxB,KACA,EAAE,eAAe,GAAG,cAAc,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,EAAE,MACvE;AAC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useScales = ({
|
|
|
148
148
|
if (axisProps?.type === "log")
|
|
149
149
|
return new LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));
|
|
150
150
|
if (axisProps?.type === "band" || axis === "x" && axisProps?.type === void 0) {
|
|
151
|
-
|
|
151
|
+
const realRange = axis === "y" ? range.reverse() : range;
|
|
152
|
+
return new BandScale(getScaleBand(getBandDomain(axisProps), realRange), axisProps);
|
|
152
153
|
}
|
|
153
154
|
return null;
|
|
154
155
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useScales.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useCallback } from 'react';\nimport type { Series } from 'd3';\nimport { max, min, scaleLinear, scaleBand, scaleUtc, scaleOrdinal, scaleLog } from 'd3';\nimport type { DSChartT } from '../react-desc-prop-types';\nimport { getStackedIndex } from '../helpers';\nimport { COLOR_PALLET } from '../helpers/colorPallet';\nimport { TIME_OFFSET } from '../../constants';\nimport { BandScale, LinearScale, TimeLinearScale, LogScale } from '../scales';\ninterface UseScales {\n props: DSChartT.Props;\n innerHeight: number;\n innerWidth: number;\n stackedData: Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n currentData: DSChartT.InternalData;\n groups: string[];\n containerRatio: number;\n}\n\nexport const useScales = ({\n props,\n originalSeries: series,\n innerHeight,\n innerWidth,\n stackedData,\n currentData,\n containerRatio,\n}: UseScales) => {\n const { xAxis, yAxis, y2Axis, groups: stackedSeries, xScroll } = props;\n\n // const xScroll = xAxis.advanced?.pointSpacing?.value > 1;\n const yScroll = yAxis.advanced?.pointSpacing?.value > 1;\n\n const getBandDomain = useCallback(\n (axis: DSChartT.AxisT) => axis.cols ?? [...series[0].data.map((_, i) => i.toString())],\n [series],\n );\n\n const getPadding = (domainPadding: number | Array<number>) =>\n typeof domainPadding === 'number' ? [domainPadding, domainPadding] : domainPadding ?? [0, 0];\n\n const getLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const stackedDataFlatten = stackedData.filter((data) => data.scale === axisString).flat();\n const minStackedData = min(stackedDataFlatten, (layer) => min(layer, (sequence) => sequence[0]));\n const maxStackedData = max(stackedDataFlatten, (layer) => max(layer, (sequence) => sequence[1]));\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n if (typeof minStackedData === 'number') aux.push(minStackedData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (typeof end === 'number' || typeof end === 'object') aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n if (typeof maxStackedData === 'number') aux.push(maxStackedData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n if (typeof minRange === 'number' && typeof maxRange === 'number') {\n // @TODO fix this domain padding\n return [\n minRange - (maxRange - minRange) * (leftPadding ?? 0),\n maxRange + (maxRange - minRange) * (rightPadding ?? 0),\n ];\n }\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData, stackedData],\n );\n\n const getTimeLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n aux.push(begin);\n aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData],\n );\n\n // d3 scale functions\n const getScaleTime = (domain: Date[], range: number[]) => scaleUtc().domain(domain).range(range);\n\n const getScaleBand = (domain: string[], range: number[], padding = 0.2) =>\n scaleBand().domain(domain).range(range).padding(padding).paddingOuter(0.05);\n const getScaleLinear = (domain: number[], range: number[]) => scaleLinear().domain(domain).range(range);\n const getScaleLog = (domain: number[], range: number[]) => scaleLog().domain(domain).range(range);\n\n // dataviz scales\n\n const scaleFactory = useCallback(\n (axis: 'x' | 'y' | 'y2', axisProps: DSChartT.AxisT, range: number[]) => {\n if (!axisProps) return null;\n if (['time', 'datetime'].includes(axisProps?.type)) {\n return new TimeLinearScale(getScaleTime(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'linear' || (['y', 'y2'].includes(axis) && axisProps?.type === undefined)) {\n return new LinearScale(getScaleLinear(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'log') return new LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));\n\n if (axisProps?.type === 'band' || (axis === 'x' && axisProps?.type === undefined)) {\n return new BandScale(getScaleBand(getBandDomain(axisProps), range), axisProps);\n }\n return null;\n },\n [getBandDomain, getLinearDomain],\n );\n\n const xRangeFrom = useMemo(() => containerRatio * (xAxis?.plotRange?.[0] || 0), [containerRatio, xAxis?.plotRange]);\n const xRangeTo = useMemo(\n () => (innerWidth - (xAxis?.plotRange?.[1] || 0)) * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xAxis?.plotRange, xScroll],\n );\n\n const yRangeTo = useMemo(() => yAxis?.plotRange?.[0] || 0, [yAxis?.plotRange]);\n const yRangeFrom = useMemo(\n () => (innerHeight - (yAxis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yAxis?.plotRange, yScroll],\n );\n\n const y2RangeTo = useMemo(() => y2Axis?.plotRange?.[0] || 0, [y2Axis?.plotRange]);\n const y2RangeFrom = useMemo(\n () => (innerHeight - (y2Axis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, y2Axis?.plotRange, yScroll],\n );\n\n const xScale = useMemo(\n () => scaleFactory('x', xAxis, [xRangeFrom, xRangeTo]),\n [scaleFactory, xAxis, xRangeFrom, xRangeTo],\n );\n\n const yScale = useMemo(\n () => scaleFactory('y', yAxis, [yRangeFrom, yRangeTo]),\n [scaleFactory, yAxis, yRangeFrom, yRangeTo],\n );\n\n const y2Scale = useMemo(\n () => scaleFactory('y2', y2Axis, [y2RangeFrom, y2RangeTo]),\n [scaleFactory, y2Axis, y2RangeFrom, y2RangeTo],\n );\n\n const colorScale = useMemo(\n () =>\n scaleOrdinal()\n .domain(series.map((d) => d.name))\n .range(series.map((d) => COLOR_PALLET[d.color as keyof typeof COLOR_PALLET] ?? d.color))\n .unknown('red'),\n [series],\n );\n // get only groups bars to calculate the subgroup scale\n\n const subgroupsWithBars = useMemo(() => {\n const data = currentData\n .filter(\n (serie) => serie.type === 'bar' && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1),\n )\n .map((serie) => serie.name);\n\n if (stackedSeries?.length) {\n stackedSeries.forEach((stackedGroup, i) => {\n if (stackedGroup.length > 0) data.push(`stacked-data-${i}`);\n });\n }\n return data;\n }, [currentData, stackedSeries]);\n\n const getBandwidth = useCallback(() => {\n if (xScale?.type === 'BAND') {\n return xScale.getBandwidth();\n }\n if (yScale?.type === 'BAND') {\n return yScale?.getBandwidth();\n }\n // @todo explore this. is to create bars with a linear axis\n const bar = currentData.filter((serie) => serie.type === 'bar');\n const barsLength = bar.length;\n if (!barsLength) return;\n // we get the size of the bars using the length of the data or the ticks amounts\n // the biggest is the one we use to get the real width we need.\n // we are doing calculations only for x axis because we are not expecting\n // y axis linear cases.\n const divisor = Math.max(bar[0].data.length, xScale?.scale.ticks().length, xScale?.getTicks(innerWidth).length, 1);\n const leftMargin = xScale?.get(bar[0].data[0].value.x);\n const rightMargin = innerWidth * containerRatio - xScale?.get(bar[0].data[bar[0].data.length - 1].value.x);\n\n const width = (innerWidth - (leftMargin + rightMargin)) / divisor;\n if (containerRatio > 1) {\n return Math.max(0.5, width * containerRatio);\n }\n return Math.max(0.5, Math.trunc(width - width * 0.3));\n }, [currentData, innerWidth, containerRatio, xScale, yScale]);\n\n const subGroupScale = useMemo(\n () =>\n getBandwidth()\n ? scaleBand()\n .domain(subgroupsWithBars)\n .range([0, getBandwidth()])\n .paddingInner(0.55)\n .padding(0.2)\n .paddingOuter(0.01)\n : null,\n [getBandwidth, subgroupsWithBars],\n );\n\n return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,mBAAmB;AAErC,SAAS,KAAK,KAAK,aAAa,WAAW,UAAU,cAAc,gBAAgB;AAEnF,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,WAAW,aAAa,iBAAiB,gBAAgB;AAgB3D,MAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAiB;AACf,QAAM,EAAE,OAAO,OAAO,QAAQ,QAAQ,eAAe,QAAQ,IAAI;AAGjE,QAAM,UAAU,MAAM,UAAU,cAAc,QAAQ;AAEtD,QAAM,gBAAgB;AAAA,IACpB,CAAC,SAAyB,KAAK,QAAQ,CAAC,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;AAAA,IACrF,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,aAAa,CAAC,kBAClB,OAAO,kBAAkB,WAAW,CAAC,eAAe,aAAa,IAAI,iBAAiB,CAAC,GAAG,CAAC;AAE7F,QAAM,kBAAkB;AAAA,IACtB,CAAC,MAAsB,eAAiC;AAGtD,YAAM,QAAQ,MAAM,cAAc,IAAI,KAAK,OAAO;AAClD,YAAM,MAAM,KAAK,OAAO;AACxB,YAAM,OAAO,YAEV,OAAO,C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AC;AAAW,eAAO;AACvB,UAAI,CAAC,QAAQ,UAAU,EAAE,SAAS,WAAW,IAAI,GAAG;AAClD,eAAO,IAAI,gBAAgB,aAAa,gBAAgB,WAAW,IAAI,GAAG,KAAK,GAAG,SAAS;AAAA,MAC7F;AAEA,UAAI,WAAW,SAAS,YAAa,CAAC,KAAK,IAAI,EAAE,SAAS,IAAI,KAAK,WAAW,SAAS,QAAY;AACjG,eAAO,IAAI,YAAY,eAAe,gBAAgB,WAAW,IAAI,GAAG,KAAK,GAAG,SAAS;AAAA,MAC3F;AAEA,UAAI,WAAW,SAAS;AAAO,eAAO,IAAI,SAAS,YAAY,gBAAgB,WAAW,IAAI,GAAG,KAAK,CAAC;AAEvG,UAAI,WAAW,SAAS,UAAW,SAAS,OAAO,WAAW,SAAS,QAAY;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useCallback } from 'react';\nimport type { Series } from 'd3';\nimport { max, min, scaleLinear, scaleBand, scaleUtc, scaleOrdinal, scaleLog } from 'd3';\nimport type { DSChartT } from '../react-desc-prop-types';\nimport { getStackedIndex } from '../helpers';\nimport { COLOR_PALLET } from '../helpers/colorPallet';\nimport { TIME_OFFSET } from '../../constants';\nimport { BandScale, LinearScale, TimeLinearScale, LogScale } from '../scales';\ninterface UseScales {\n props: DSChartT.Props;\n innerHeight: number;\n innerWidth: number;\n stackedData: Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n currentData: DSChartT.InternalData;\n groups: string[];\n containerRatio: number;\n}\n\nexport const useScales = ({\n props,\n originalSeries: series,\n innerHeight,\n innerWidth,\n stackedData,\n currentData,\n containerRatio,\n}: UseScales) => {\n const { xAxis, yAxis, y2Axis, groups: stackedSeries, xScroll } = props;\n\n // const xScroll = xAxis.advanced?.pointSpacing?.value > 1;\n const yScroll = yAxis.advanced?.pointSpacing?.value > 1;\n\n const getBandDomain = useCallback(\n (axis: DSChartT.AxisT) => axis.cols ?? [...series[0].data.map((_, i) => i.toString())],\n [series],\n );\n\n const getPadding = (domainPadding: number | Array<number>) =>\n typeof domainPadding === 'number' ? [domainPadding, domainPadding] : domainPadding ?? [0, 0];\n\n const getLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const stackedDataFlatten = stackedData.filter((data) => data.scale === axisString).flat();\n const minStackedData = min(stackedDataFlatten, (layer) => min(layer, (sequence) => sequence[0]));\n const maxStackedData = max(stackedDataFlatten, (layer) => max(layer, (sequence) => sequence[1]));\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n if (typeof minStackedData === 'number') aux.push(minStackedData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n if (typeof begin === 'number' || typeof begin === 'object') aux.push(begin);\n if (typeof end === 'number' || typeof end === 'object') aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n if (typeof maxStackedData === 'number') aux.push(maxStackedData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n if (typeof minRange === 'number' && typeof maxRange === 'number') {\n // @TODO fix this domain padding\n return [\n minRange - (maxRange - minRange) * (leftPadding ?? 0),\n maxRange + (maxRange - minRange) * (rightPadding ?? 0),\n ];\n }\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData, stackedData],\n );\n\n const getTimeLinearDomain = useCallback(\n (axis: DSChartT.AxisT, axisString: 'x' | 'y' | 'y2') => {\n // we are calculating the min and max between all the data\n // including the stacked groups if exists\n\n const begin = axis?.beginAtZero ? 0 : axis.min ?? undefined;\n const end = axis.max ?? undefined;\n const data = currentData\n // we filter the data based on scale.. if is x axis we dont because theres no x2 axis\n .filter((serie) => serie.scale === axisString || axisString === 'x')\n .map((serie) =>\n serie.data\n .filter((datum) => datum.value !== null)\n .map((datum) => {\n if (typeof datum.value === 'number') {\n return datum.value;\n }\n\n return datum.value[axisString === 'y2' ? 'y' : axisString];\n }),\n );\n\n const dataFlattened = data.flat();\n const minData = min(dataFlattened);\n const maxData = max(dataFlattened);\n const types = ['number', 'object'];\n\n const getMin = () => {\n const aux = [];\n aux.push(begin);\n if (types.includes(typeof minData)) aux.push(minData);\n return min(aux);\n };\n const getMax = () => {\n const aux = [];\n aux.push(begin);\n aux.push(end);\n if (types.includes(typeof maxData)) aux.push(maxData);\n return max(aux);\n };\n const minRange = getMin();\n const maxRange = getMax();\n\n const [leftPadding, rightPadding] = getPadding(axis.domainPadding);\n\n // timelinear case\n if (typeof minRange === 'object' && typeof maxRange === 'object') {\n if (axis.domainPaddingType && TIME_OFFSET[axis.domainPaddingType]) {\n return [\n TIME_OFFSET[axis.domainPaddingType].offset(minRange, -leftPadding),\n TIME_OFFSET[axis.domainPaddingType].offset(maxRange, rightPadding),\n ];\n }\n return [minRange, maxRange];\n }\n\n return [];\n },\n [currentData],\n );\n\n // d3 scale functions\n const getScaleTime = (domain: Date[], range: number[]) => scaleUtc().domain(domain).range(range);\n\n const getScaleBand = (domain: string[], range: number[], padding = 0.2) =>\n scaleBand().domain(domain).range(range).padding(padding).paddingOuter(0.05);\n const getScaleLinear = (domain: number[], range: number[]) => scaleLinear().domain(domain).range(range);\n const getScaleLog = (domain: number[], range: number[]) => scaleLog().domain(domain).range(range);\n\n // dataviz scales\n\n const scaleFactory = useCallback(\n (axis: 'x' | 'y' | 'y2', axisProps: DSChartT.AxisT, range: number[]) => {\n if (!axisProps) return null;\n if (['time', 'datetime'].includes(axisProps?.type)) {\n return new TimeLinearScale(getScaleTime(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'linear' || (['y', 'y2'].includes(axis) && axisProps?.type === undefined)) {\n return new LinearScale(getScaleLinear(getLinearDomain(axisProps, axis), range), axisProps);\n }\n\n if (axisProps?.type === 'log') return new LogScale(getScaleLog(getLinearDomain(axisProps, axis), range));\n\n if (axisProps?.type === 'band' || (axis === 'x' && axisProps?.type === undefined)) {\n // we need to reverse the range in case is a horizontal bar char\n const realRange = axis === 'y' ? range.reverse() : range;\n return new BandScale(getScaleBand(getBandDomain(axisProps), realRange), axisProps);\n }\n return null;\n },\n [getBandDomain, getLinearDomain],\n );\n\n const xRangeFrom = useMemo(() => containerRatio * (xAxis?.plotRange?.[0] || 0), [containerRatio, xAxis?.plotRange]);\n const xRangeTo = useMemo(\n () => (innerWidth - (xAxis?.plotRange?.[1] || 0)) * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xAxis?.plotRange, xScroll],\n );\n\n const yRangeTo = useMemo(() => yAxis?.plotRange?.[0] || 0, [yAxis?.plotRange]);\n const yRangeFrom = useMemo(\n () => (innerHeight - (yAxis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yAxis?.plotRange, yScroll],\n );\n\n const y2RangeTo = useMemo(() => y2Axis?.plotRange?.[0] || 0, [y2Axis?.plotRange]);\n const y2RangeFrom = useMemo(\n () => (innerHeight - (y2Axis?.plotRange?.[1] || 0)) * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, y2Axis?.plotRange, yScroll],\n );\n\n const xScale = useMemo(\n () => scaleFactory('x', xAxis, [xRangeFrom, xRangeTo]),\n [scaleFactory, xAxis, xRangeFrom, xRangeTo],\n );\n\n const yScale = useMemo(\n () => scaleFactory('y', yAxis, [yRangeFrom, yRangeTo]),\n [scaleFactory, yAxis, yRangeFrom, yRangeTo],\n );\n\n const y2Scale = useMemo(\n () => scaleFactory('y2', y2Axis, [y2RangeFrom, y2RangeTo]),\n [scaleFactory, y2Axis, y2RangeFrom, y2RangeTo],\n );\n\n const colorScale = useMemo(\n () =>\n scaleOrdinal()\n .domain(series.map((d) => d.name))\n .range(series.map((d) => COLOR_PALLET[d.color as keyof typeof COLOR_PALLET] ?? d.color))\n .unknown('red'),\n [series],\n );\n // get only groups bars to calculate the subgroup scale\n\n const subgroupsWithBars = useMemo(() => {\n const data = currentData\n .filter(\n (serie) => serie.type === 'bar' && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1),\n )\n .map((serie) => serie.name);\n\n if (stackedSeries?.length) {\n stackedSeries.forEach((stackedGroup, i) => {\n if (stackedGroup.length > 0) data.push(`stacked-data-${i}`);\n });\n }\n return data;\n }, [currentData, stackedSeries]);\n\n const getBandwidth = useCallback(() => {\n if (xScale?.type === 'BAND') {\n return xScale.getBandwidth();\n }\n if (yScale?.type === 'BAND') {\n return yScale?.getBandwidth();\n }\n // @todo explore this. is to create bars with a linear axis\n const bar = currentData.filter((serie) => serie.type === 'bar');\n const barsLength = bar.length;\n if (!barsLength) return;\n // we get the size of the bars using the length of the data or the ticks amounts\n // the biggest is the one we use to get the real width we need.\n // we are doing calculations only for x axis because we are not expecting\n // y axis linear cases.\n const divisor = Math.max(bar[0].data.length, xScale?.scale.ticks().length, xScale?.getTicks(innerWidth).length, 1);\n const leftMargin = xScale?.get(bar[0].data[0].value.x);\n const rightMargin = innerWidth * containerRatio - xScale?.get(bar[0].data[bar[0].data.length - 1].value.x);\n\n const width = (innerWidth - (leftMargin + rightMargin)) / divisor;\n if (containerRatio > 1) {\n return Math.max(0.5, width * containerRatio);\n }\n return Math.max(0.5, Math.trunc(width - width * 0.3));\n }, [currentData, innerWidth, containerRatio, xScale, yScale]);\n\n const subGroupScale = useMemo(\n () =>\n getBandwidth()\n ? scaleBand()\n .domain(subgroupsWithBars)\n .range([0, getBandwidth()])\n .paddingInner(0.55)\n .padding(0.2)\n .paddingOuter(0.01)\n : null,\n [getBandwidth, subgroupsWithBars],\n );\n\n return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,mBAAmB;AAErC,SAAS,KAAK,KAAK,aAAa,WAAW,UAAU,cAAc,gBAAgB;AAEnF,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,WAAW,aAAa,iBAAiB,gBAAgB;AAgB3D,MAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAiB;AACf,QAAM,EAAE,OAAO,OAAO,QAAQ,QAAQ,eAAe,QAAQ,IAAI;AAGjE,QAAM,UAAU,MAAM,UAAU,cAAc,QAAQ;AAEtD,QAAM,gBAAgB;AAAA,IACpB,CAAC,SAAyB,KAAK,QAAQ,CAAC,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;AAAA,IACrF,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,aAAa,CAAC,kBAClB,OAAO,kBAAkB,WAAW,CAAC,eAAe,aAAa,IAAI,iBAAiB,CAAC,GAAG,CAAC;AAE7F,QAAM,kBAAkB;AAAA,IACtB,CAAC,MAAsB,e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8,14 +8,17 @@ import { GridLine } from "./GridLine";
|
|
|
8
8
|
import { COLOR_PALLET } from "../../helpers/colorPallet";
|
|
9
9
|
const AxisBottom = React2.memo(() => {
|
|
10
10
|
const {
|
|
11
|
-
props: { xAxis },
|
|
11
|
+
props: { xAxis, xScroll },
|
|
12
12
|
innerHeight,
|
|
13
13
|
xScale,
|
|
14
|
-
yScale,
|
|
15
14
|
innerWidth,
|
|
16
15
|
containerRatio,
|
|
17
16
|
setAxisBottomRef
|
|
18
17
|
} = useContext(ChartContext);
|
|
18
|
+
const realInnerWidth = useMemo(
|
|
19
|
+
() => innerWidth * (xScroll ? containerRatio : 1),
|
|
20
|
+
[containerRatio, innerWidth, xScroll]
|
|
21
|
+
);
|
|
19
22
|
const { tickRotation } = xAxis.tick || {};
|
|
20
23
|
const { showGrid } = xAxis;
|
|
21
24
|
const textProps = useMemo(() => {
|
|
@@ -78,7 +81,7 @@ const AxisBottom = React2.memo(() => {
|
|
|
78
81
|
return null;
|
|
79
82
|
const lineCoords = {
|
|
80
83
|
x1: 0,
|
|
81
|
-
x2:
|
|
84
|
+
x2: realInnerWidth,
|
|
82
85
|
y1: innerHeight,
|
|
83
86
|
y2: innerHeight
|
|
84
87
|
};
|
|
@@ -88,23 +91,13 @@ const AxisBottom = React2.memo(() => {
|
|
|
88
91
|
lineCoords,
|
|
89
92
|
scale: xScale,
|
|
90
93
|
innerRef: setAxisBottomRef,
|
|
91
|
-
dimension:
|
|
94
|
+
dimension: realInnerWidth,
|
|
92
95
|
TickRenderer,
|
|
93
96
|
GridRenderer,
|
|
94
97
|
color: axisColor
|
|
95
98
|
}
|
|
96
99
|
);
|
|
97
|
-
}, [
|
|
98
|
-
GridRenderer,
|
|
99
|
-
TickRenderer,
|
|
100
|
-
containerRatio,
|
|
101
|
-
axisColor,
|
|
102
|
-
innerHeight,
|
|
103
|
-
innerWidth,
|
|
104
|
-
setAxisBottomRef,
|
|
105
|
-
xAxis.hideAxis,
|
|
106
|
-
xScale
|
|
107
|
-
]);
|
|
100
|
+
}, [GridRenderer, TickRenderer, axisColor, innerHeight, realInnerWidth, setAxisBottomRef, xAxis.hideAxis, xScale]);
|
|
108
101
|
});
|
|
109
102
|
export {
|
|
110
103
|
AxisBottom
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Axis/AxisBottom.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext, useMemo, useCallback } from 'react';\nimport type { CSSProperties } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type GridRenderPropsT, type TickRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis },\n innerHeight,\n xScale,\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext, useMemo, useCallback } from 'react';\nimport type { CSSProperties } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type GridRenderPropsT, type TickRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis, xScroll },\n innerHeight,\n xScale,\n innerWidth,\n containerRatio,\n setAxisBottomRef,\n } = useContext(ChartContext);\n\n const realInnerWidth = useMemo(\n () => innerWidth * (xScroll ? containerRatio : 1),\n [containerRatio, innerWidth, xScroll],\n );\n\n const { tickRotation } = xAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = xAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, y: 17 };\n return {\n ...commomProps,\n dx: 8 * Math.sin(Math.PI * (tickRotation / 180)),\n dy: '.71em',\n y: Math.ceil(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1)),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, xAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(() => {\n if (!tickRotation) return { textAnchor: 'middle' };\n return { textAnchor: tickRotation > 0 ? 'start' : 'end' };\n }, [tickRotation]);\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: position,\n x2: position,\n y1: 0,\n y2: innerHeight,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [innerHeight, showGrid],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n y2: 5,\n stroke: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n tickValue={xScale.getTickFormatted(tickValue)}\n xTranslate={position}\n yTranslate={innerHeight}\n textProps={textProps}\n textStyle={style}\n {...rest}\n />\n );\n },\n [xAxis?.tick?.color, xScale, innerHeight, textProps, style],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[xAxis.color as keyof typeof COLOR_PALLET] || xAxis.color, [xAxis.color]);\n\n return useMemo(() => {\n if (xAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: realInnerWidth,\n y1: innerHeight,\n y2: innerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={xScale}\n innerRef={setAxisBottomRef}\n dimension={realInnerWidth}\n TickRenderer={TickRenderer}\n GridRenderer={GridRenderer}\n color={axisColor}\n />\n );\n }, [GridRenderer, TickRenderer, axisColor, innerHeight, realInnerWidth, setAxisBottomRef, xAxis.hideAxis, xScale]);\n});\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACyDV;AAvDb,OAAOA,UAAS,YAAY,SAAS,mBAAmB;AAExD,SAAS,oBAAoB;AAE7B,SAAS,YAA0D;AACnE,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAEtB,MAAM,aAAaA,OAAM,KAAK,MAAM;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,OAAO,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,iBAAiB;AAAA,IACrB,MAAM,cAAc,UAAU,iBAAiB;AAAA,IAC/C,CAAC,gBAAgB,YAAY,OAAO;AAAA,EACtC;AAEA,QAAM,EAAE,aAAa,IAAI,MAAM,QAAS,CAAC;AACzC,QAAM,EAAE,SAAS,IAAI;AAErB,QAAM,YAAY,QAAQ,MAAM;AAC9B,UAAM,cAAc,EAAE,MAAM,aAAa,OAAO,MAAM,UAAuC,OAAO,MAAM,MAAM;AAChH,QAAI,CAAC;AAAc,aAAO,EAAE,GAAG,aAAa,GAAG,GAAG;AAClD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,IAAI,IAAI,KAAK,IAAI,KAAK,MAAM,eAAe,IAAI;AAAA,MAC/C,IAAI;AAAA,MACJ,GAAG,KAAK,KAAK,OAAO,OAAO,eAAe,OAAO,eAAe,IAAI,IAAI,GAAG;AAAA,MAC3E,WAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,cAAc,OAAO,MAAM,KAAK,CAAC;AAErC,QAAM,QAAuB,QAAQ,MAAM;AACzC,QAAI,CAAC;AAAc,aAAO,EAAE,YAAY,SA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AAAA,QACA,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ,GAAG,CAAC,cAAc,cAAc,WAAW,aAAa,gBAAgB,kBAAkB,MAAM,UAAU,MAAM,CAAC;AACnH,CAAC;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -8,15 +8,20 @@ import { GridLine } from "./GridLine";
|
|
|
8
8
|
import { COLOR_PALLET } from "../../helpers/colorPallet";
|
|
9
9
|
const AxisLeft = React2.memo(() => {
|
|
10
10
|
const {
|
|
11
|
-
props: { yAxis },
|
|
11
|
+
props: { yAxis, yScroll },
|
|
12
12
|
innerHeight,
|
|
13
13
|
height,
|
|
14
14
|
yScale,
|
|
15
15
|
innerWidth,
|
|
16
|
+
containerRatio,
|
|
16
17
|
setAxisLeftRef
|
|
17
18
|
} = useContext(ChartContext);
|
|
18
19
|
const { tickRotation } = yAxis.tick || {};
|
|
19
20
|
const { showGrid } = yAxis;
|
|
21
|
+
const realInnerHeight = useMemo(
|
|
22
|
+
() => innerHeight * (yScroll ? containerRatio : 1),
|
|
23
|
+
[containerRatio, innerHeight, yScroll]
|
|
24
|
+
);
|
|
20
25
|
const textProps = useMemo(() => {
|
|
21
26
|
const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color] || yAxis?.tick?.color };
|
|
22
27
|
if (!tickRotation)
|
|
@@ -80,7 +85,7 @@ const AxisLeft = React2.memo(() => {
|
|
|
80
85
|
x1: 0,
|
|
81
86
|
x2: 0,
|
|
82
87
|
y1: 0,
|
|
83
|
-
y2:
|
|
88
|
+
y2: realInnerHeight
|
|
84
89
|
};
|
|
85
90
|
return /* @__PURE__ */ jsx(
|
|
86
91
|
Axis,
|
|
@@ -94,7 +99,7 @@ const AxisLeft = React2.memo(() => {
|
|
|
94
99
|
color: axisColor
|
|
95
100
|
}
|
|
96
101
|
);
|
|
97
|
-
}, [GridRenderer, TickRenderer, axisColor, height,
|
|
102
|
+
}, [GridRenderer, TickRenderer, axisColor, height, realInnerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);
|
|
98
103
|
});
|
|
99
104
|
export {
|
|
100
105
|
AxisLeft
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Axis/AxisLeft.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { type CSSProperties, useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type TickRenderPropsT, type GridRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisLeft = React.memo(() => {\n const {\n props: { yAxis },\n innerHeight,\n height,\n yScale,\n innerWidth,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = yAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = yAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, x: -10, dy: '0.32em' };\n return {\n ...commomProps,\n dy: '.30em',\n dx: '-.10em',\n x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, yAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(\n () => ({\n textAnchor: 'end',\n }),\n [],\n );\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: 0,\n x2: innerWidth,\n y1: position,\n y2: position,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [showGrid, innerWidth],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n x2: -5,\n stroke: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n xTranslate={0}\n yTranslate={position}\n textProps={textProps}\n textStyle={style}\n tickValue={yScale.getTickFormatted(tickValue)}\n {...rest}\n />\n );\n },\n [style, textProps, yAxis?.tick?.color, yScale],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[yAxis.color as keyof typeof COLOR_PALLET] || yAxis.color, [yAxis.color]);\n\n return useMemo(() => {\n if (yAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: 0,\n y1: 0,\n y2:
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { type CSSProperties, useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type TickRenderPropsT, type GridRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisLeft = React.memo(() => {\n const {\n props: { yAxis, yScroll },\n innerHeight,\n height,\n yScale,\n innerWidth,\n containerRatio,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = yAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = yAxis;\n\n const realInnerHeight = useMemo(\n () => innerHeight * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yScroll],\n );\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, x: -10, dy: '0.32em' };\n return {\n ...commomProps,\n dy: '.30em',\n dx: '-.10em',\n x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, yAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(\n () => ({\n textAnchor: 'end',\n }),\n [],\n );\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: 0,\n x2: innerWidth,\n y1: position,\n y2: position,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [showGrid, innerWidth],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n x2: -5,\n stroke: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n xTranslate={0}\n yTranslate={position}\n textProps={textProps}\n textStyle={style}\n tickValue={yScale.getTickFormatted(tickValue)}\n {...rest}\n />\n );\n },\n [style, textProps, yAxis?.tick?.color, yScale],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[yAxis.color as keyof typeof COLOR_PALLET] || yAxis.color, [yAxis.color]);\n\n return useMemo(() => {\n if (yAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: 0,\n y1: 0,\n y2: realInnerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={yScale}\n innerRef={setAxisLeftRef}\n dimension={height}\n GridRenderer={GridRenderer}\n TickRenderer={TickRenderer}\n color={axisColor}\n />\n );\n }, [GridRenderer, TickRenderer, axisColor, height, realInnerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);\n});\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC0DV;AAxDb,OAAOA,UAA6B,aAAa,YAAY,eAAe;AAC5E,SAAS,oBAAoB;AAE7B,SAAS,YA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A,CAAC,UAAU,UAAU;AAAA,EACvB;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,UAA4B;AAC3B,YAAM,EAAE,UAAU,cAAc,KAAK,IAAI;AACzC,YAAM,iBAAiB;AAAA,QACrB,IAAI;AAAA,QACJ,QAAQ,aAAa,OAAO,MAAM,UAAuC,OAAO,MAAM;AAAA,MACxF;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ;AAAA,UACA,WAAW;AAAA,UACX,WAAW,OAAO,iBAAiB,SAAS;AAAA,UAC3C,GAAG;AAAA;AAAA,MACN;AAAA,IAEJ;AAAA,IACA,CAAC,OAAO,WAAW,OAAO,MAAM,OAAO,MAAM;AAAA,EAC/C;AAEA,QAAM,YAAY,QAAQ,MAAM,aAAa,MAAM,UAAuC,MAAM,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpH,SAAO,QAAQ,MAAM;AACnB,QAAI,MAAM;AAAU,aAAO;AAC3B,UAAM,aAAa;AAAA,MACjB,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ,GAAG,CAAC,cAAc,cAAc,WAAW,QAAQ,iBAAiB,gBAAgB,MAAM,UAAU,MAAM,CAAC;AAC7G,CAAC;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/graphs/Chart/react-desc-prop-types.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { globalAttributesPropTypes, PropTypes } from '@elliemae/ds-utilities';\nimport type { Series, ScaleLinear, ScaleBand } from 'd3';\nexport declare namespace DSChartT {\n export type SerieTypeT = 'line' | 'bar' | 'area' | 'point';\n export type AxisTypeT = 'log' | 'band' | 'time' | 'linear';\n\n export type LinearScale = ScaleLinear<number, number, never>;\n export type BandScale = ScaleBand<string>;\n\n export type Scales = LinearScale | BandScale;\n export interface SeriesT {\n name: string;\n data: Array<number | null | { x: number; y: number }>;\n type: SerieTypeT;\n scale?: string;\n color?: string;\n // line\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export interface ScrapperT {\n type: 'horizontal' | 'vertical';\n color: string;\n tooltipPreference: string;\n }\n\n export interface SerieComponentT {\n serie: InternalSerie;\n }\n\n export interface LegendT {\n position: 'right' | 'bottom' | 'left' | 'top';\n preventFilterAction: boolean;\n }\n\n export interface AxisTickT {\n tickValues: number[] | Date[];\n tickFormat?: (value: string | number | Date) => string;\n tickCount: number;\n tickRotation: number;\n overwriteTicks: boolean;\n color: string;\n }\n\n export interface AxisT {\n showGrid: boolean;\n color: string;\n label: string;\n type: AxisTypeT;\n cols?: string[];\n domainPadding: number;\n hideAxis: boolean;\n beginAtZero?: boolean;\n advanced: {\n pointSpacing: {\n type: 'string';\n value: number;\n };\n };\n tick: AxisTickT;\n plotRange: number[];\n }\n\n export interface InternalDatum {\n key: string;\n value: number | { x: number; y: number };\n position: number;\n serie: string;\n }\n\n export interface InternalSerie {\n key: string;\n data: InternalDatum[];\n name: string;\n type: DSChartT.SerieTypeT;\n scale?: string | undefined;\n color?: string;\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export type InternalData = InternalSerie[];\n\n export interface OptionalProps {\n groups?: string[][];\n types?: 'scatter';\n scrapper: ScrapperT;\n withTrendHighlight: boolean;\n TooltipRenderer: () => JSX.Element;\n height: number;\n width: number;\n legend: LegendT;\n }\n\n export interface DefaultProps {\n yAxis: AxisT;\n xAxis: AxisT;\n y2Axis: AxisT;\n series: SeriesT[];\n }\n\n export interface RequiredProps {}\n\n export interface Props extends OptionalProps, DefaultProps, RequiredProps {}\n\n export type StackedSeriesByGroupT = Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n}\n\nexport const defaultProps: DSChartT.DefaultProps = {\n series: [\n {\n name: '1',\n data: [0],\n color: 'grey-100',\n type: 'bar',\n },\n ],\n xAxis: {\n cols: ['0'],\n },\n yAxis: {},\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n height: PropTypes.number.isRequired.description('height').defaultValue(''),\n width: PropTypes.number.isRequired.description('height').defaultValue(''),\n margin: PropTypes.shape({\n top: PropTypes.number,\n bottom: PropTypes.number,\n left: PropTypes.number,\n right: PropTypes.number,\n })\n .isRequired.description('margin')\n .defaultValue(''),\n series: PropTypes.arrayOf(PropTypes.object).description('yValue').defaultValue(''),\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,2BAA2B,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { globalAttributesPropTypes, PropTypes } from '@elliemae/ds-utilities';\nimport type { Series, ScaleLinear, ScaleBand } from 'd3';\nexport declare namespace DSChartT {\n export type SerieTypeT = 'line' | 'bar' | 'area' | 'point';\n export type AxisTypeT = 'log' | 'band' | 'time' | 'linear';\n\n export type LinearScale = ScaleLinear<number, number, never>;\n export type BandScale = ScaleBand<string>;\n\n export type Scales = LinearScale | BandScale;\n export interface SeriesT {\n name: string;\n data: Array<number | null | { x: number; y: number }>;\n type: SerieTypeT;\n scale?: string;\n color?: string;\n // line\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export interface ScrapperT {\n type: 'horizontal' | 'vertical';\n color: string;\n tooltipPreference: string;\n }\n\n export interface SerieComponentT {\n serie: InternalSerie;\n }\n\n export interface LegendT {\n position: 'right' | 'bottom' | 'left' | 'top';\n preventFilterAction: boolean;\n }\n\n export interface AxisTickT {\n tickValues: number[] | Date[];\n tickFormat?: (value: string | number | Date) => string;\n tickCount: number;\n tickRotation: number;\n overwriteTicks: boolean;\n color: string;\n }\n\n export interface AxisT {\n showGrid: boolean;\n color: string;\n label: string;\n type: AxisTypeT;\n cols?: string[];\n domainPadding: number;\n hideAxis: boolean;\n beginAtZero?: boolean;\n advanced: {\n pointSpacing: {\n type: 'string';\n value: number;\n };\n };\n tick: AxisTickT;\n plotRange: number[];\n }\n\n export interface InternalDatum {\n key: string;\n value: number | { x: number; y: number };\n position: number;\n serie: string;\n }\n\n export interface InternalSerie {\n key: string;\n data: InternalDatum[];\n name: string;\n type: DSChartT.SerieTypeT;\n scale?: string | undefined;\n color?: string;\n dashStyle?: string;\n pointRadius?: number;\n }\n\n export type InternalData = InternalSerie[];\n\n export interface OptionalProps {\n groups?: string[][];\n types?: 'scatter';\n scrapper: ScrapperT;\n withTrendHighlight: boolean;\n TooltipRenderer: () => JSX.Element;\n height: number;\n width: number;\n legend: LegendT;\n xScroll: boolean;\n yScroll: boolean;\n }\n\n export interface DefaultProps {\n yAxis: AxisT;\n xAxis: AxisT;\n y2Axis: AxisT;\n series: SeriesT[];\n }\n\n export interface RequiredProps {}\n\n export interface Props extends OptionalProps, DefaultProps, RequiredProps {}\n\n export type StackedSeriesByGroupT = Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n}\n\nexport const defaultProps: DSChartT.DefaultProps = {\n series: [\n {\n name: '1',\n data: [0],\n color: 'grey-100',\n type: 'bar',\n },\n ],\n xAxis: {\n cols: ['0'],\n },\n yAxis: {},\n};\n\nexport const propTypes = {\n ...globalAttributesPropTypes,\n height: PropTypes.number.isRequired.description('height').defaultValue(''),\n width: PropTypes.number.isRequired.description('height').defaultValue(''),\n margin: PropTypes.shape({\n top: PropTypes.number,\n bottom: PropTypes.number,\n left: PropTypes.number,\n right: PropTypes.number,\n })\n .isRequired.description('margin')\n .defaultValue(''),\n series: PropTypes.arrayOf(PropTypes.object).description('yValue').defaultValue(''),\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,2BAA2B,iBAAiB;AAoH9C,MAAM,eAAsC;AAAA,EACjD,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,MAAM,CAAC,CAAC;AAAA,MACR,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,MAAM,CAAC,GAAG;AAAA,EACZ;AAAA,EACA,OAAO,CAAC;AACV;AAEO,MAAM,YAAY;AAAA,EACvB,GAAG;AAAA,EACH,QAAQ,UAAU,OAAO,WAAW,YAAY,QAAQ,EAAE,aAAa,EAAE;AAAA,EACzE,OAAO,UAAU,OAAO,WAAW,YAAY,QAAQ,EAAE,aAAa,EAAE;AAAA,EACxE,QAAQ,UAAU,MAAM;AAAA,IACtB,KAAK,UAAU;AAAA,IACf,QAAQ,UAAU;AAAA,IAClB,MAAM,UAAU;AAAA,IAChB,OAAO,UAAU;AAAA,EACnB,CAAC,EACE,WAAW,YAAY,QAAQ,EAC/B,aAAa,EAAE;AAAA,EAClB,QAAQ,UAAU,QAAQ,UAAU,MAAM,EAAE,YAAY,QAAQ,EAAE,aAAa,EAAE;AACnF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useContext } from "react";
|
|
3
|
+
import { useContext, useMemo } from "react";
|
|
4
4
|
import { Rect } from "./Rect";
|
|
5
5
|
import { ChartContext } from "../ChartContext";
|
|
6
6
|
import { getStackedData, getStackedIndex } from "../helpers";
|
|
7
7
|
const HorizontalStackedBars = ({ serie }) => {
|
|
8
8
|
const {
|
|
9
|
-
props: { groups },
|
|
9
|
+
props: { groups, yScroll },
|
|
10
10
|
xScale,
|
|
11
11
|
yScale,
|
|
12
12
|
stackedData,
|
|
13
13
|
subGroupScale,
|
|
14
14
|
colorScale,
|
|
15
|
+
innerHeight,
|
|
16
|
+
containerRatio,
|
|
15
17
|
chartId,
|
|
16
18
|
getYValue
|
|
17
19
|
} = useContext(ChartContext);
|
|
18
20
|
const serieWithStackedValues = getStackedData(stackedData, serie);
|
|
19
21
|
const stackIndex = getStackedIndex(groups, serie.name);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
22
|
+
const realInnerHeight = useMemo(
|
|
23
|
+
() => innerHeight * (yScroll ? containerRatio : 1),
|
|
24
|
+
[containerRatio, innerHeight, yScroll]
|
|
25
|
+
);
|
|
26
|
+
return useMemo(
|
|
27
|
+
() => /* @__PURE__ */ jsx("g", { children: serie.data.map((bar, i) => {
|
|
28
|
+
const sequence = serieWithStackedValues[bar.position];
|
|
29
|
+
const isFloorStack = sequence[0] === 0;
|
|
30
|
+
const xValue = sequence[1] - sequence[0];
|
|
31
|
+
const yValue = getYValue(serie.data[i]);
|
|
32
|
+
const width = xScale.get(sequence[1]) - xScale.get(sequence[0]) - (!isFloorStack ? 2 : 0);
|
|
33
|
+
const height = subGroupScale?.bandwidth();
|
|
34
|
+
const transformX = xScale.get(sequence[0]) + (!isFloorStack ? 2 : 0);
|
|
35
|
+
const transformY = subGroupScale(`stacked-data-${stackIndex}`) + yScale.get(yValue);
|
|
36
|
+
return /* @__PURE__ */ jsx("g", { clipPath: `url(#rect-focus-ring-${chartId})`, children: /* @__PURE__ */ jsx("g", { fill: colorScale(serie.name), transform: `translate(0, ${transformY})`, children: /* @__PURE__ */ jsx(
|
|
37
|
+
Rect,
|
|
38
|
+
{
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
x: transformX,
|
|
42
|
+
xValue,
|
|
43
|
+
yValue,
|
|
44
|
+
id: serie.data[i]?.key,
|
|
45
|
+
name: serie.name,
|
|
46
|
+
datum: serie.data[i]
|
|
47
|
+
}
|
|
48
|
+
) }) }, serie.data[i]?.key);
|
|
49
|
+
}) }),
|
|
50
|
+
[chartId, colorScale, getYValue, serie, serieWithStackedValues, stackIndex, subGroupScale, xScale, yScale]
|
|
51
|
+
);
|
|
42
52
|
};
|
|
43
53
|
export {
|
|
44
54
|
HorizontalStackedBars
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/series/HorizontalStackedBars.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport React, { useContext } from 'react';\
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport React, { useContext, useMemo } from 'react';\nimport { Rect } from './Rect';\nimport { ChartContext } from '../ChartContext';\nimport { getStackedData, getStackedIndex } from '../helpers';\nimport type { DSChartT } from '../react-desc-prop-types';\n\nexport const HorizontalStackedBars = ({ serie }: DSChartT.SerieComponentT) => {\n const {\n props: { groups, yScroll },\n xScale,\n yScale,\n stackedData,\n subGroupScale,\n colorScale,\n innerHeight,\n containerRatio,\n chartId,\n getYValue,\n } = useContext(ChartContext);\n const serieWithStackedValues = getStackedData(stackedData, serie);\n const stackIndex = getStackedIndex(groups, serie.name);\n\n const realInnerHeight = useMemo(\n () => innerHeight * (yScroll ? containerRatio : 1),\n [containerRatio, innerHeight, yScroll],\n );\n\n return useMemo(\n () => (\n <g>\n {serie.data.map((bar, i) => {\n const sequence = serieWithStackedValues[bar.position];\n const isFloorStack = sequence[0] === 0;\n const xValue = sequence[1] - sequence[0];\n const yValue = getYValue(serie.data[i]);\n\n const width = xScale.get(sequence[1]) - xScale.get(sequence[0]) - (!isFloorStack ? 2 : 0);\n\n const height = subGroupScale?.bandwidth();\n\n const transformX = xScale.get(sequence[0]) + (!isFloorStack ? 2 : 0);\n const transformY = subGroupScale(`stacked-data-${stackIndex}`) + yScale.get(yValue);\n return (\n <g key={serie.data[i]?.key} clipPath={`url(#rect-focus-ring-${chartId})`}>\n <g fill={colorScale(serie.name)} transform={`translate(0, ${transformY})`}>\n <Rect\n width={width}\n height={height}\n x={transformX}\n xValue={xValue}\n yValue={yValue}\n id={serie.data[i]?.key}\n name={serie.name}\n datum={serie.data[i]}\n />\n </g>\n </g>\n );\n })}\n </g>\n ),\n [chartId, colorScale, getYValue, serie, serieWithStackedValues, stackIndex, subGroupScale, xScale, yScale],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC8CP;AA7ChB,SAAgB,YAAY,eAAe;AAC3C,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,uBAAuB;AAGzC,MAAM,wBAAwB,CAAC,EAAE,MAAM,MAAgC;AAC5E,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ,QAAQ;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAC3B,QAAM,yBAAyB,eAAe,aAAa,KAAK;AAChE,QAAM,aAAa,gBAAgB,QAAQ,MAAM,IAAI;AAErD,QAAM,kBAAkB;AAAA,IACtB,MAAM,eAAe,UAAU,iBAAiB;AAAA,IAChD,CAAC,gBAAgB,aAAa,OAAO;AAAA,EACvC;AAEA,SAAO;AAAA,IACL,MACE,oBAAC,OACE,gBAAM,KAAK,IAAI,CAAC,KAAK,MAAM;AAC1B,YAAM,WAAW,uBAAuB,IAAI;AAC5C,YAAM,eAAe,SAAS,OAAO;AACrC,YAAM,SAAS,SAAS,KAAK,SAAS;AACtC,YAAM,SAAS,UAAU,MAAM,KAAK,EAAE;AAEtC,YAAM,QAAQ,OAAO,IAAI,SAAS,EAAE,IAAI,OAAO,IAAI,SAAS,EAAE,KAAK,CAAC,eAAe,IAAI;AAEvF,YAAM,SAAS,eAAe,UAAU;AAExC,YAAM,aAAa,OAAO,IAAI,SAAS,EAAE,KAAK,CAAC,eAAe,IAAI;AAClE,YAAM,aAAa,cAAc,gBAAgB,YAAY,IAAI,OAAO,IAAI,MAAM;AAClF,aACE,oBAAC,OAA2B,UAAU,wBAAwB,YAC5D,8BAAC,OAAE,MAAM,WAAW,MAAM,IAAI,GAAG,WAAW,gBAAgB,eAC1D;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,GAAG;AAAA,UACH;AAAA,UACA;AAAA,UACA,IAAI,MAAM,KAAK,IAAI;AAAA,UACnB,MAAM,MAAM;AAAA,UACZ,OAAO,MAAM,KAAK;AAAA;AAAA,MACpB,GACF,KAZM,MAAM,KAAK,IAAI,GAavB;AAAA,IAEJ,CAAC,GACH;AAAA,IAEF,CAAC,SAAS,YAAY,WAAW,OAAO,wBAAwB,YAAY,eAAe,QAAQ,MAAM;AAAA,EAC3G;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-dataviz",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - DataViz",
|
|
6
6
|
"files": [
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"d3-shape": "~3.1.0",
|
|
41
41
|
"resize-observer-polyfill": "~1.5.1",
|
|
42
42
|
"uid": "~2.0.0",
|
|
43
|
-
"@elliemae/ds-popperjs": "3.14.
|
|
44
|
-
"@elliemae/ds-system": "3.14.
|
|
45
|
-
"@elliemae/ds-utilities": "3.14.
|
|
43
|
+
"@elliemae/ds-popperjs": "3.14.10",
|
|
44
|
+
"@elliemae/ds-system": "3.14.10",
|
|
45
|
+
"@elliemae/ds-utilities": "3.14.10"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@elliemae/pui-theme": "~2.6.0",
|