@elliemae/ds-dataviz 3.13.0-next.3 → 3.13.0
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/ChartContext.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useChart.js +55 -10
- package/dist/cjs/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js +48 -19
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js.map +3 -3
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js +89 -7
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useScales.js +25 -12
- package/dist/cjs/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useValidateProps.js +37 -0
- package/dist/cjs/graphs/Chart/config/useValidateProps.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js +28 -10
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js +5 -5
- package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/BottomLegend.js +43 -43
- package/dist/cjs/graphs/Chart/parts/Legend/BottomLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/LeftLegend.js +12 -8
- package/dist/cjs/graphs/Chart/parts/Legend/LeftLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/LegendItem.js +4 -10
- package/dist/cjs/graphs/Chart/parts/Legend/LegendItem.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/RightLegend.js +5 -9
- package/dist/cjs/graphs/Chart/parts/Legend/RightLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/TopLegend.js +21 -18
- package/dist/cjs/graphs/Chart/parts/Legend/TopLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js +42 -19
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js +28 -18
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js +14 -1
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Bars.js +2 -2
- package/dist/cjs/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Point.js +1 -2
- package/dist/cjs/graphs/Chart/series/Point.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Rect.js +2 -2
- package/dist/cjs/graphs/Chart/series/Rect.js.map +1 -1
- package/dist/cjs/graphs/Chart/series/StackedBar.js +1 -1
- package/dist/cjs/graphs/Chart/series/StackedBar.js.map +1 -1
- package/dist/cjs/graphs/constants.js +7 -0
- package/dist/cjs/graphs/constants.js.map +2 -2
- package/dist/esm/graphs/Chart/ChartContext.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useChart.js +55 -10
- package/dist/esm/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useInternalMargins.js +49 -20
- package/dist/esm/graphs/Chart/config/useInternalMargins.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js +90 -8
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useScales.js +25 -12
- package/dist/esm/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useValidateProps.js +11 -0
- package/dist/esm/graphs/Chart/config/useValidateProps.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/ChartContainer.js +28 -10
- package/dist/esm/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js +5 -5
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/BottomLegend.js +44 -44
- package/dist/esm/graphs/Chart/parts/Legend/BottomLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/LeftLegend.js +13 -9
- package/dist/esm/graphs/Chart/parts/Legend/LeftLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/LegendItem.js +4 -10
- package/dist/esm/graphs/Chart/parts/Legend/LegendItem.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/RightLegend.js +6 -10
- package/dist/esm/graphs/Chart/parts/Legend/RightLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/TopLegend.js +23 -20
- package/dist/esm/graphs/Chart/parts/Legend/TopLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js +44 -21
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js +29 -19
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/esm/graphs/Chart/react-desc-prop-types.js +14 -1
- package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Bars.js +2 -2
- package/dist/esm/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Point.js +1 -2
- package/dist/esm/graphs/Chart/series/Point.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Rect.js +2 -2
- package/dist/esm/graphs/Chart/series/Rect.js.map +1 -1
- package/dist/esm/graphs/Chart/series/StackedBar.js +1 -1
- package/dist/esm/graphs/Chart/series/StackedBar.js.map +1 -1
- package/dist/esm/graphs/constants.js +7 -0
- package/dist/esm/graphs/constants.js.map +2 -2
- package/package.json +4 -4
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useContext, useMemo,
|
|
3
|
+
import { useContext, useMemo, useEffect, useState } from "react";
|
|
4
4
|
import { select } from "d3";
|
|
5
5
|
import { ChartContext } from "../../ChartContext";
|
|
6
6
|
import { LegendItem } from "./LegendItem";
|
|
7
7
|
const BottomLegend = () => {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
const {
|
|
9
|
+
colorScale,
|
|
10
|
+
bottomLegendWidth,
|
|
11
|
+
bottomLegend,
|
|
12
|
+
axisBottomHeight,
|
|
13
|
+
axisLeftWidth,
|
|
14
|
+
innerWidth,
|
|
15
|
+
innerHeight,
|
|
16
|
+
bottomLabelHeight,
|
|
17
|
+
internalMargin,
|
|
18
|
+
currentData,
|
|
19
|
+
width: graphWidth,
|
|
20
|
+
setBottomLegend
|
|
21
|
+
} = useContext(ChartContext);
|
|
22
|
+
const [xTransform, setXTransform] = useState(0);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!bottomLegend)
|
|
25
|
+
return;
|
|
26
|
+
const cells = select(bottomLegend).selectAll(".cell");
|
|
27
|
+
const padding = 25;
|
|
28
|
+
let offset = 0;
|
|
29
|
+
let verticalOffset = 0;
|
|
30
|
+
currentData.forEach((_, i) => {
|
|
31
|
+
if (cells._groups[0][i - 1]) {
|
|
32
|
+
const lastCell = select(cells._groups[0][i - 1]);
|
|
33
|
+
const d3sel = select(cells._groups[0][i]);
|
|
34
|
+
const { width: currentCellWidth } = d3sel.node().getBBox();
|
|
35
|
+
const { width: lastCellWidth } = lastCell.node().getBBox();
|
|
36
|
+
if (offset + lastCellWidth + padding + currentCellWidth + 10 > graphWidth) {
|
|
37
|
+
offset = 0;
|
|
38
|
+
verticalOffset += 20;
|
|
39
|
+
} else {
|
|
40
|
+
offset += lastCellWidth + padding;
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [innerWidth]);
|
|
37
|
-
const margin = useMemo(() => {
|
|
38
|
-
let counter = 0;
|
|
39
|
-
if (bottomLabelHeight > 0) {
|
|
40
|
-
counter += bottomLabelHeight;
|
|
41
|
-
}
|
|
42
|
-
if (axisBottomHeight > 0) {
|
|
43
|
-
counter += axisBottomHeight;
|
|
44
|
-
}
|
|
45
|
-
return counter;
|
|
46
|
-
}, [axisBottomHeight, bottomLabelHeight]);
|
|
42
|
+
d3sel.attr("transform", `translate(${offset}, ${verticalOffset})`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
setXTransform(innerWidth / 2 + internalMargin.left - bottomLegendWidth / 2);
|
|
46
|
+
}, [bottomLegend, currentData, bottomLegendWidth, axisLeftWidth, innerWidth, internalMargin.left, graphWidth]);
|
|
47
47
|
return useMemo(
|
|
48
|
-
() => /* @__PURE__ */ jsx(
|
|
48
|
+
() => /* @__PURE__ */ jsx(
|
|
49
49
|
"g",
|
|
50
50
|
{
|
|
51
|
-
ref,
|
|
52
|
-
transform: `translate(${xTransform
|
|
51
|
+
ref: setBottomLegend,
|
|
52
|
+
transform: `translate(${xTransform}, ${innerHeight + bottomLabelHeight + axisBottomHeight + internalMargin.top})`,
|
|
53
53
|
className: "bottom-legend",
|
|
54
54
|
children: colorScale.domain().map((domainValue, i) => /* @__PURE__ */ jsx(LegendItem, { domainValue }, domainValue))
|
|
55
55
|
}
|
|
56
|
-
)
|
|
57
|
-
[colorScale, innerHeight, internalMargin.
|
|
56
|
+
),
|
|
57
|
+
[axisBottomHeight, bottomLabelHeight, colorScale, innerHeight, internalMargin.top, setBottomLegend, xTransform]
|
|
58
58
|
);
|
|
59
59
|
};
|
|
60
60
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Legend/BottomLegend.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo, useEffect, useState } from 'react';\nimport { select } from 'd3';\nimport { ChartContext } from '../../ChartContext';\nimport { LegendItem } from './LegendItem';\n\nexport const BottomLegend = () => {\n const {\n colorScale,\n bottomLegendWidth,\n bottomLegend,\n axisBottomHeight,\n axisLeftWidth,\n innerWidth,\n innerHeight,\n bottomLabelHeight,\n internalMargin,\n currentData,\n width: graphWidth,\n setBottomLegend,\n } = useContext(ChartContext);\n\n const [xTransform, setXTransform] = useState(0);\n\n useEffect(() => {\n if (!bottomLegend) return;\n const cells = select(bottomLegend).selectAll('.cell');\n const padding = 25;\n let offset = 0;\n let verticalOffset = 0;\n\n currentData.forEach((_, i) => {\n if (cells._groups[0][i - 1]) {\n const lastCell = select(cells._groups[0][i - 1]);\n const d3sel = select(cells._groups[0][i]);\n const { width: currentCellWidth } = d3sel.node().getBBox();\n\n const { width: lastCellWidth } = lastCell.node().getBBox();\n\n if (offset + lastCellWidth + padding + currentCellWidth + 10 > graphWidth) {\n offset = 0;\n verticalOffset += 20;\n } else {\n offset += lastCellWidth + padding;\n }\n\n d3sel.attr('transform', `translate(${offset}, ${verticalOffset})`);\n }\n });\n\n setXTransform(innerWidth / 2 + internalMargin.left - bottomLegendWidth / 2);\n }, [bottomLegend, currentData, bottomLegendWidth, axisLeftWidth, innerWidth, internalMargin.left, graphWidth]);\n\n return useMemo(\n () => (\n <g\n ref={setBottomLegend}\n transform={`translate(${xTransform}, ${\n innerHeight + bottomLabelHeight + axisBottomHeight + internalMargin.top\n })`}\n className=\"bottom-legend\"\n >\n {colorScale.domain().map((domainValue, i) => (\n <LegendItem domainValue={domainValue} key={domainValue} />\n ))}\n </g>\n ),\n\n [axisBottomHeight, bottomLabelHeight, colorScale, innerHeight, internalMargin.top, setBottomLegend, xTransform],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC8Db;AA9DV,SAAgB,YAAY,SAAS,WAAW,gBAAgB;AAChE,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,MAAM,eAAe,MAAM;AAChC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC;AAE9C,YAAU,MAAM;AACd,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,OAAO,YAAY,EAAE,UAAU,OAAO;AACpD,UAAM,UAAU;AAChB,QAAI,SAAS;AACb,QAAI,iBAAiB;AAErB,gBAAY,QAAQ,CAAC,GAAG,MAAM;AAC5B,UAAI,MAAM,QAAQ,GAAG,IAAI,IAAI;AAC3B,cAAM,WAAW,OAAO,MAAM,QAAQ,GAAG,IAAI,EAAE;AAC/C,cAAM,QAAQ,OAAO,MAAM,QAAQ,GAAG,EAAE;AACxC,cAAM,EAAE,OAAO,iBAAiB,IAAI,MAAM,KAAK,EAAE,QAAQ;AAEzD,cAAM,EAAE,OAAO,cAAc,IAAI,SAAS,KAAK,EAAE,QAAQ;AAEzD,YAAI,SAAS,gBAAgB,UAAU,mBAAmB,KAAK,YAAY;AACzE,mBAAS;AACT,4BAAkB;AAAA,QACpB,OAAO;AACL,oBAAU,gBAAgB;AAAA,QAC5B;AAEA,cAAM,KAAK,aAAa,aAAa,WAAW,iBAAiB;AAAA,MACnE;AAAA,IACF,CAAC;AAED,kBAAc,aAAa,IAAI,eAAe,OAAO,oBAAoB,CAAC;AAAA,EAC5E,GAAG,CAAC,cAAc,aAAa,mBAAmB,eAAe,YAAY,eAAe,MAAM,UAAU,CAAC;AAE7G,SAAO;AAAA,IACL,MACE;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,WAAW,aAAa,eACtB,cAAc,oBAAoB,mBAAmB,eAAe;AAAA,QAEtE,WAAU;AAAA,QAET,qBAAW,OAAO,EAAE,IAAI,CAAC,aAAa,MACrC,oBAAC,cAAW,eAA+B,WAAa,CACzD;AAAA;AAAA,IACH;AAAA,IAGF,CAAC,kBAAkB,mBAAmB,YAAY,aAAa,eAAe,KAAK,iBAAiB,UAAU;AAAA,EAChH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useContext, useState,
|
|
3
|
+
import { useContext, useState, useEffect } from "react";
|
|
4
4
|
import { ChartContext } from "../../ChartContext";
|
|
5
5
|
import { LegendItem } from "./LegendItem";
|
|
6
6
|
const LeftLegend = () => {
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
originalSeries: series,
|
|
9
|
+
leftLegendHeight,
|
|
10
|
+
innerHeight,
|
|
11
|
+
internalMargin,
|
|
12
|
+
leftLegend,
|
|
13
|
+
setLeftLegend
|
|
14
|
+
} = useContext(ChartContext);
|
|
8
15
|
const [yTransform, setYTransform] = useState(innerHeight / 2 + internalMargin.top);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}, [leftLegend]);
|
|
15
|
-
return /* @__PURE__ */ jsx("g", { transform: `translate(8,${yTransform})`, ref: setLeftLegend, children: colorScale.domain().map((domainValue, i) => /* @__PURE__ */ jsx("g", { className: "tick", transform: `translate(0,${i * 30})`, children: /* @__PURE__ */ jsx(LegendItem, { domainValue }) }, domainValue)) });
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setYTransform(innerHeight / 2 + internalMargin.top - leftLegendHeight / 2);
|
|
18
|
+
}, [innerHeight, internalMargin.top, leftLegend, leftLegendHeight]);
|
|
19
|
+
return /* @__PURE__ */ jsx("g", { transform: `translate(8,${yTransform})`, ref: setLeftLegend, children: series.map((serie, i) => /* @__PURE__ */ jsx("g", { className: "tick", transform: `translate(0,${i * 30})`, children: /* @__PURE__ */ jsx(LegendItem, { domainValue: serie.name }, serie.name) }, serie.name)) });
|
|
16
20
|
};
|
|
17
21
|
export {
|
|
18
22
|
LeftLegend
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Legend/LeftLegend.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useState,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useState, useEffect } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport { LegendItem } from './LegendItem';\n\nexport const LeftLegend = () => {\n const {\n originalSeries: series,\n leftLegendHeight,\n innerHeight,\n internalMargin,\n leftLegend,\n setLeftLegend,\n } = useContext(ChartContext);\n\n const [yTransform, setYTransform] = useState(innerHeight / 2 + internalMargin.top);\n useEffect(() => {\n setYTransform(innerHeight / 2 + internalMargin.top - leftLegendHeight / 2);\n }, [innerHeight, internalMargin.top, leftLegend, leftLegendHeight]);\n\n return (\n <g transform={`translate(8,${yTransform})`} ref={setLeftLegend}>\n {series.map((serie, i) => (\n <g className=\"tick\" transform={`translate(0,${i * 30})`} key={serie.name}>\n <LegendItem key={serie.name} domainValue={serie.name} />\n </g>\n ))}\n </g>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACuBb;AAvBV,SAAgB,YAAY,UAAU,iBAAiB;AACvD,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,MAAM,aAAa,MAAM;AAC9B,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,cAAc,IAAI,eAAe,GAAG;AACjF,YAAU,MAAM;AACd,kBAAc,cAAc,IAAI,eAAe,MAAM,mBAAmB,CAAC;AAAA,EAC3E,GAAG,CAAC,aAAa,eAAe,KAAK,YAAY,gBAAgB,CAAC;AAElE,SACE,oBAAC,OAAE,WAAW,eAAe,eAAe,KAAK,eAC9C,iBAAO,IAAI,CAAC,OAAO,MAClB,oBAAC,OAAE,WAAU,QAAO,WAAW,eAAe,IAAI,OAChD,8BAAC,cAA4B,aAAa,MAAM,QAA/B,MAAM,IAA+B,KADM,MAAM,IAEpE,CACD,GACH;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,10 +17,11 @@ const LegendItem = ({ domainValue }) => {
|
|
|
17
17
|
colorScale,
|
|
18
18
|
setHiddenSeries,
|
|
19
19
|
hiddenSeries,
|
|
20
|
-
|
|
20
|
+
originalSeries: series,
|
|
21
|
+
props: { types }
|
|
21
22
|
} = useContext(ChartContext);
|
|
22
23
|
const serieData = series.find((serie) => serie.name === domainValue);
|
|
23
|
-
const LegendIcon = LegendItemsMap[serieData
|
|
24
|
+
const LegendIcon = LegendItemsMap[serieData?.pointStyle] ?? (serieData?.type === "line" || types === "scatter" ? LegendItemCircle : LegendItemSquare);
|
|
24
25
|
const handleOnClick = useCallback(() => {
|
|
25
26
|
setHiddenSeries((prev) => {
|
|
26
27
|
if (prev.includes(domainValue))
|
|
@@ -39,19 +40,12 @@ const LegendItem = ({ domainValue }) => {
|
|
|
39
40
|
style: hiddenSeries.includes(domainValue) ? { opacity: 0.2, cursor: "pointer" } : { cursor: "pointer" },
|
|
40
41
|
children: [
|
|
41
42
|
/* @__PURE__ */ jsx(LegendIcon, { fill: colorScale(domainValue) }),
|
|
42
|
-
serieData.type === "line" ? /* @__PURE__ */ jsx(
|
|
43
|
-
LegendItemLine,
|
|
44
|
-
{
|
|
45
|
-
stroke: colorScale(domainValue),
|
|
46
|
-
strokeDasharray: LINE.DASH_STYLE_VALUES[serieData.dashStyle]
|
|
47
|
-
}
|
|
48
|
-
) : null,
|
|
49
43
|
/* @__PURE__ */ jsx("text", { x: 24, dy: ".32em", fontWeight: "600", children: domainValue })
|
|
50
44
|
]
|
|
51
45
|
},
|
|
52
46
|
domainValue
|
|
53
47
|
),
|
|
54
|
-
[LegendIcon, colorScale, domainValue, handleOnClick, hiddenSeries
|
|
48
|
+
[LegendIcon, colorScale, domainValue, handleOnClick, hiddenSeries]
|
|
55
49
|
);
|
|
56
50
|
};
|
|
57
51
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Legend/LegendItem.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo, useCallback } from 'react';\nimport { LINE } from '../../../constants';\nimport { ChartContext } from '../../ChartContext';\n\nconst LegendItemLine = (props) => <line x1={-18} x2={18} y1={0} y2={0} {...props} strokeWidth={2} />;\nconst LegendItemCircle = (props) => <circle r={6} {...props} />;\nconst LegendItemSquare = (props) => <rect x={-6} y={-6} width={12} height={12} {...props} />;\nconst LegendItemDiamond = (props) => (\n <g transform=\"rotate(45)\">\n <rect x={-6} y={-6} width={12} height={12} {...props} />\n </g>\n);\n\nconst LegendItemsMap = {\n [LINE.POINT_STYLE.CIRCLE]: LegendItemCircle,\n [LINE.POINT_STYLE.SQUARE]: LegendItemSquare,\n [LINE.POINT_STYLE.DIAMOND]: LegendItemDiamond,\n};\n\nexport const LegendItem = ({ domainValue }) => {\n const {\n colorScale,\n setHiddenSeries,\n hiddenSeries,\n props: {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIW,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo, useCallback } from 'react';\nimport { LINE } from '../../../constants';\nimport { ChartContext } from '../../ChartContext';\n\nconst LegendItemLine = (props) => <line x1={-18} x2={18} y1={0} y2={0} {...props} strokeWidth={2} />;\nconst LegendItemCircle = (props) => <circle r={6} {...props} />;\nconst LegendItemSquare = (props) => <rect x={-6} y={-6} width={12} height={12} {...props} />;\nconst LegendItemDiamond = (props) => (\n <g transform=\"rotate(45)\">\n <rect x={-6} y={-6} width={12} height={12} {...props} />\n </g>\n);\n\nconst LegendItemsMap = {\n [LINE.POINT_STYLE.CIRCLE]: LegendItemCircle,\n [LINE.POINT_STYLE.SQUARE]: LegendItemSquare,\n [LINE.POINT_STYLE.DIAMOND]: LegendItemDiamond,\n};\n\nexport const LegendItem = ({ domainValue }) => {\n const {\n colorScale,\n setHiddenSeries,\n hiddenSeries,\n originalSeries: series,\n props: { types },\n } = useContext(ChartContext);\n\n const serieData = series.find((serie) => serie.name === domainValue);\n const LegendIcon =\n LegendItemsMap[serieData?.pointStyle] ??\n (serieData?.type === 'line' || types === 'scatter' ? LegendItemCircle : LegendItemSquare);\n\n const handleOnClick = useCallback(() => {\n setHiddenSeries((prev) => {\n if (prev.includes(domainValue)) return prev.filter((serie) => serie !== domainValue);\n if (prev.length + 1 !== series.length) return [...prev, domainValue];\n return prev;\n });\n }, [domainValue, series.length, setHiddenSeries]);\n\n return useMemo(\n () => (\n <g\n onClick={handleOnClick}\n key={domainValue}\n className=\"cell\"\n style={hiddenSeries.includes(domainValue) ? { opacity: 0.2, cursor: 'pointer' } : { cursor: 'pointer' }}\n >\n <LegendIcon fill={colorScale(domainValue)} />\n <text x={24} dy=\".32em\" fontWeight=\"600\">\n {domainValue}\n </text>\n </g>\n ),\n\n [LegendIcon, colorScale, domainValue, handleOnClick, hiddenSeries],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIW,cAuC5B,YAvC4B;AAJlC,SAAgB,YAAY,SAAS,mBAAmB;AACxD,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAE7B,MAAM,iBAAiB,CAAC,UAAU,oBAAC,UAAK,IAAI,KAAK,IAAI,IAAI,IAAI,GAAG,IAAI,GAAI,GAAG,OAAO,aAAa,GAAG;AAClG,MAAM,mBAAmB,CAAC,UAAU,oBAAC,YAAO,GAAG,GAAI,GAAG,OAAO;AAC7D,MAAM,mBAAmB,CAAC,UAAU,oBAAC,UAAK,GAAG,IAAI,GAAG,IAAI,OAAO,IAAI,QAAQ,IAAK,GAAG,OAAO;AAC1F,MAAM,oBAAoB,CAAC,UACzB,oBAAC,OAAE,WAAU,cACX,8BAAC,UAAK,GAAG,IAAI,GAAG,IAAI,OAAO,IAAI,QAAQ,IAAK,GAAG,OAAO,GACxD;AAGF,MAAM,iBAAiB;AAAA,EACrB,CAAC,KAAK,YAAY,SAAS;AAAA,EAC3B,CAAC,KAAK,YAAY,SAAS;AAAA,EAC3B,CAAC,KAAK,YAAY,UAAU;AAC9B;AAEO,MAAM,aAAa,CAAC,EAAE,YAAY,MAAM;AAC7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO,EAAE,MAAM;AAAA,EACjB,IAAI,WAAW,YAAY;AAE3B,QAAM,YAAY,OAAO,KAAK,CAAC,UAAU,MAAM,SAAS,WAAW;AACnE,QAAM,aACJ,eAAe,WAAW,gBACzB,WAAW,SAAS,UAAU,UAAU,YAAY,mBAAmB;AAE1E,QAAM,gBAAgB,YAAY,MAAM;AACtC,oBAAgB,CAAC,SAAS;AACxB,UAAI,KAAK,SAAS,WAAW;AAAG,eAAO,KAAK,OAAO,CAAC,UAAU,UAAU,WAAW;AACnF,UAAI,KAAK,SAAS,MAAM,OAAO;AAAQ,eAAO,CAAC,GAAG,MAAM,WAAW;AACnE,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,aAAa,OAAO,QAAQ,eAAe,CAAC;AAEhD,SAAO;AAAA,IACL,MACE;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QAET,WAAU;AAAA,QACV,OAAO,aAAa,SAAS,WAAW,IAAI,EAAE,SAAS,KAAK,QAAQ,UAAU,IAAI,EAAE,QAAQ,UAAU;AAAA,QAEtG;AAAA,8BAAC,cAAW,MAAM,WAAW,WAAW,GAAG;AAAA,UAC3C,oBAAC,UAAK,GAAG,IAAI,IAAG,SAAQ,YAAW,OAChC,uBACH;AAAA;AAAA;AAAA,MAPK;AAAA,IAQP;AAAA,IAGF,CAAC,YAAY,YAAY,aAAa,eAAe,YAAY;AAAA,EACnE;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useContext, useState,
|
|
3
|
+
import { useContext, useState, useEffect } from "react";
|
|
4
4
|
import { ChartContext } from "../../ChartContext";
|
|
5
5
|
import { LegendItem } from "./LegendItem";
|
|
6
6
|
const RightLegend = () => {
|
|
7
7
|
const {
|
|
8
|
-
colorScale,
|
|
9
8
|
innerWidth,
|
|
10
9
|
innerHeight,
|
|
11
10
|
rightLabelWidth,
|
|
12
|
-
rightLegend,
|
|
13
11
|
axisRightWidth,
|
|
14
12
|
internalMargin,
|
|
13
|
+
rightLegendHeight,
|
|
15
14
|
setRightLegend,
|
|
16
|
-
|
|
15
|
+
originalSeries: series
|
|
17
16
|
} = useContext(ChartContext);
|
|
18
17
|
const [yTransform, setYTransform] = useState(innerHeight / 2 + internalMargin.top);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setYTransform((prev) => prev - bounds.height / 2);
|
|
23
|
-
}
|
|
24
|
-
}, [rightLegend]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setYTransform(innerHeight / 2 + internalMargin.top - rightLegendHeight / 2);
|
|
20
|
+
}, [innerHeight, internalMargin.top, rightLegendHeight]);
|
|
25
21
|
return /* @__PURE__ */ jsxs(
|
|
26
22
|
"g",
|
|
27
23
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Legend/RightLegend.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useState,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useState, useEffect } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport { LegendItem } from './LegendItem';\n\nexport const RightLegend = () => {\n const {\n innerWidth,\n innerHeight,\n rightLabelWidth,\n axisRightWidth,\n internalMargin,\n rightLegendHeight,\n setRightLegend,\n originalSeries: series,\n } = useContext(ChartContext);\n\n const [yTransform, setYTransform] = useState(innerHeight / 2 + internalMargin.top);\n\n useEffect(() => {\n setYTransform(innerHeight / 2 + internalMargin.top - rightLegendHeight / 2);\n }, [innerHeight, internalMargin.top, rightLegendHeight]);\n\n return (\n <g\n ref={setRightLegend}\n transform={`translate(${innerWidth + internalMargin.left + axisRightWidth + rightLabelWidth},${yTransform})`}\n >\n <rect width=\"20\" height={1} fill=\"transparent\" />\n <g transform={`translate(0,0)`}>\n {series.map((serie, i) => (\n <g className=\"tick\" transform={`translate(30,${i * 30})`} key={serie.name}>\n <LegendItem domainValue={serie.name} />\n </g>\n ))}\n </g>\n </g>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACuBnB,SAIE,KAJF;AAvBJ,SAAgB,YAAY,UAAU,iBAAiB;AACvD,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,MAAM,cAAc,MAAM;AAC/B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,EAClB,IAAI,WAAW,YAAY;AAE3B,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,cAAc,IAAI,eAAe,GAAG;AAEjF,YAAU,MAAM;AACd,kBAAc,cAAc,IAAI,eAAe,MAAM,oBAAoB,CAAC;AAAA,EAC5E,GAAG,CAAC,aAAa,eAAe,KAAK,iBAAiB,CAAC;AAEvD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,aAAa,aAAa,eAAe,OAAO,iBAAiB,mBAAmB;AAAA,MAE/F;AAAA,4BAAC,UAAK,OAAM,MAAK,QAAQ,GAAG,MAAK,eAAc;AAAA,QAC/C,oBAAC,OAAE,WAAW,kBACX,iBAAO,IAAI,CAAC,OAAO,MAClB,oBAAC,OAAE,WAAU,QAAO,WAAW,gBAAgB,IAAI,OACjD,8BAAC,cAAW,aAAa,MAAM,MAAM,KADwB,MAAM,IAErE,CACD,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { jsx
|
|
3
|
-
import { useContext, useMemo,
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useMemo, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { select } from "d3";
|
|
5
5
|
import { ChartContext } from "../../ChartContext";
|
|
6
6
|
import { LegendItem } from "./LegendItem";
|
|
7
7
|
const TopLegend = () => {
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
colorScale,
|
|
10
|
+
currentData,
|
|
11
|
+
topLegendHeight,
|
|
12
|
+
internalMargin,
|
|
13
|
+
innerWidth,
|
|
14
|
+
setTopLegend,
|
|
15
|
+
width: graphWidth
|
|
16
|
+
} = useContext(ChartContext);
|
|
9
17
|
const ref = useRef(null);
|
|
10
|
-
const firstRender = useRef(true);
|
|
11
18
|
const [xTransform, setXTransform] = useState(innerWidth / 2 + internalMargin.left);
|
|
12
|
-
|
|
13
|
-
if (ref.current
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (ref.current) {
|
|
14
21
|
const cells = select(ref.current).selectAll(".cell");
|
|
15
22
|
const padding = 30;
|
|
16
23
|
let offset = 0;
|
|
17
24
|
let verticalOffset = 0;
|
|
18
|
-
|
|
25
|
+
currentData.forEach((_, i) => {
|
|
19
26
|
if (cells._groups[0][i - 1]) {
|
|
20
27
|
const lastCell = select(cells._groups[0][i - 1]);
|
|
21
28
|
const d3sel = select(cells._groups[0][i]);
|
|
22
|
-
const { width } =
|
|
23
|
-
|
|
29
|
+
const { width: currentCellWidth } = d3sel.node().getBBox();
|
|
30
|
+
const { width: lastCellWidth } = lastCell.node().getBBox();
|
|
31
|
+
if (offset + lastCellWidth + padding + currentCellWidth + 10 > graphWidth) {
|
|
24
32
|
offset = 0;
|
|
25
33
|
verticalOffset += 20;
|
|
26
34
|
} else {
|
|
27
|
-
offset +=
|
|
35
|
+
offset += lastCellWidth + padding;
|
|
28
36
|
}
|
|
29
37
|
d3sel.attr("transform", `translate(${offset}, ${verticalOffset})`);
|
|
30
38
|
}
|
|
31
39
|
});
|
|
32
40
|
const bounds = ref.current.getBoundingClientRect();
|
|
33
|
-
setXTransform(
|
|
34
|
-
firstRender.current = false;
|
|
41
|
+
setXTransform(innerWidth / 2 + internalMargin.left - bounds.width / 2);
|
|
35
42
|
}
|
|
36
|
-
}, [innerWidth]);
|
|
37
|
-
|
|
38
|
-
() => /* @__PURE__ */ jsx("g", { ref, transform: `translate(${xTransform}
|
|
39
|
-
|
|
40
|
-
colorScale.domain().map((domainValue, i) => /* @__PURE__ */ jsx(LegendItem, { domainValue }, domainValue))
|
|
41
|
-
] }) }),
|
|
42
|
-
[colorScale, setTopLegend, xTransform, toolbarHeight]
|
|
43
|
+
}, [currentData, graphWidth, innerWidth, internalMargin.left]);
|
|
44
|
+
return useMemo(
|
|
45
|
+
() => /* @__PURE__ */ jsx("g", { ref, transform: `translate(${xTransform},10)`, children: /* @__PURE__ */ jsx("g", { ref: setTopLegend, children: colorScale.domain().map((domainValue) => /* @__PURE__ */ jsx(LegendItem, { domainValue }, domainValue)) }) }),
|
|
46
|
+
[xTransform, setTopLegend, colorScale]
|
|
43
47
|
);
|
|
44
|
-
return render;
|
|
45
48
|
};
|
|
46
49
|
export {
|
|
47
50
|
TopLegend
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Legend/TopLegend.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo, useEffect, useRef, useState } from 'react';\n\nimport { select } from 'd3';\nimport { ChartContext } from '../../ChartContext';\nimport { LegendItem } from './LegendItem';\n\nexport const TopLegend = () => {\n const {\n colorScale,\n currentData,\n topLegendHeight,\n internalMargin,\n innerWidth,\n setTopLegend,\n width: graphWidth,\n } = useContext(ChartContext);\n\n const ref = useRef<SVGGElement>(null);\n\n const [xTransform, setXTransform] = useState(innerWidth / 2 + internalMargin.left);\n\n useEffect(() => {\n if (ref.current) {\n const cells = select(ref.current).selectAll('.cell');\n const padding = 30;\n let offset = 0;\n let verticalOffset = 0;\n\n currentData.forEach((_, i) => {\n if (cells._groups[0][i - 1]) {\n const lastCell = select(cells._groups[0][i - 1]);\n const d3sel = select(cells._groups[0][i]);\n const { width: currentCellWidth } = d3sel.node().getBBox();\n\n const { width: lastCellWidth } = lastCell.node().getBBox();\n\n if (offset + lastCellWidth + padding + currentCellWidth + 10 > graphWidth) {\n offset = 0;\n verticalOffset += 20;\n } else {\n offset += lastCellWidth + padding;\n }\n\n d3sel.attr('transform', `translate(${offset}, ${verticalOffset})`);\n }\n });\n const bounds = ref.current.getBoundingClientRect();\n setXTransform(innerWidth / 2 + internalMargin.left - bounds.width / 2);\n }\n }, [currentData, graphWidth, innerWidth, internalMargin.left]);\n return useMemo(\n () => (\n <g ref={ref} transform={`translate(${xTransform},10)`}>\n <g ref={setTopLegend}>\n {colorScale.domain().map((domainValue) => (\n <LegendItem key={domainValue} domainValue={domainValue} />\n ))}\n </g>\n </g>\n ),\n\n [xTransform, setTopLegend, colorScale],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACuDX;AAvDZ,SAAgB,YAAY,SAAS,WAAW,QAAQ,gBAAgB;AAExE,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,MAAM,YAAY,MAAM;AAC7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,IAAI,WAAW,YAAY;AAE3B,QAAM,MAAM,OAAoB,IAAI;AAEpC,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,aAAa,IAAI,eAAe,IAAI;AAEjF,YAAU,MAAM;AACd,QAAI,IAAI,SAAS;AACf,YAAM,QAAQ,OAAO,IAAI,OAAO,EAAE,UAAU,OAAO;AACnD,YAAM,UAAU;AAChB,UAAI,SAAS;AACb,UAAI,iBAAiB;AAErB,kBAAY,QAAQ,CAAC,GAAG,MAAM;AAC5B,YAAI,MAAM,QAAQ,GAAG,IAAI,IAAI;AAC3B,gBAAM,WAAW,OAAO,MAAM,QAAQ,GAAG,IAAI,EAAE;AAC/C,gBAAM,QAAQ,OAAO,MAAM,QAAQ,GAAG,EAAE;AACxC,gBAAM,EAAE,OAAO,iBAAiB,IAAI,MAAM,KAAK,EAAE,QAAQ;AAEzD,gBAAM,EAAE,OAAO,cAAc,IAAI,SAAS,KAAK,EAAE,QAAQ;AAEzD,cAAI,SAAS,gBAAgB,UAAU,mBAAmB,KAAK,YAAY;AACzE,qBAAS;AACT,8BAAkB;AAAA,UACpB,OAAO;AACL,sBAAU,gBAAgB;AAAA,UAC5B;AAEA,gBAAM,KAAK,aAAa,aAAa,WAAW,iBAAiB;AAAA,QACnE;AAAA,MACF,CAAC;AACD,YAAM,SAAS,IAAI,QAAQ,sBAAsB;AACjD,oBAAc,aAAa,IAAI,eAAe,OAAO,OAAO,QAAQ,CAAC;AAAA,IACvE;AAAA,EACF,GAAG,CAAC,aAAa,YAAY,YAAY,eAAe,IAAI,CAAC;AAC7D,SAAO;AAAA,IACL,MACE,oBAAC,OAAE,KAAU,WAAW,aAAa,kBACnC,8BAAC,OAAE,KAAK,cACL,qBAAW,OAAO,EAAE,IAAI,CAAC,gBACxB,oBAAC,cAA6B,eAAb,WAAuC,CACzD,GACH,GACF;AAAA,IAGF,CAAC,YAAY,cAAc,UAAU;AAAA,EACvC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,51 +1,74 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { jsx
|
|
3
|
-
import { useContext, useCallback } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useCallback, useMemo } from "react";
|
|
4
|
+
import { styled } from "@elliemae/ds-system";
|
|
4
5
|
import { ChartContext } from "../../ChartContext";
|
|
6
|
+
import { TOOLBAR } from "../../../constants";
|
|
7
|
+
const StyledResetter = styled("g")`
|
|
8
|
+
cursor: ${({ isDisabled }) => isDisabled ? "not-allowed" : "pointer"};
|
|
9
|
+
opacity: ${({ isDisabled }) => isDisabled ? "0.4" : "1"};
|
|
10
|
+
&focus {
|
|
11
|
+
outline: 2px solid blue;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
5
14
|
const Controllers = () => {
|
|
6
15
|
const {
|
|
7
16
|
props: { xScroll },
|
|
8
17
|
width,
|
|
18
|
+
internalMargin,
|
|
9
19
|
xScale,
|
|
10
20
|
yScale,
|
|
21
|
+
containerRef,
|
|
11
22
|
containerRatio,
|
|
12
23
|
setContainerRatio,
|
|
13
24
|
lastPosition,
|
|
14
25
|
setToolbarRef,
|
|
15
26
|
setXScrollbarPosition
|
|
16
27
|
} = useContext(ChartContext);
|
|
28
|
+
const isDisabled = useMemo(() => containerRatio === 1, [containerRatio]);
|
|
17
29
|
const handleOnClick = useCallback(() => {
|
|
18
30
|
setContainerRatio(1);
|
|
19
31
|
setXScrollbarPosition(0);
|
|
20
32
|
lastPosition.current = 0;
|
|
21
33
|
}, [lastPosition, setContainerRatio, setXScrollbarPosition]);
|
|
34
|
+
const handleOnKeyDown = useCallback(
|
|
35
|
+
(e) => {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
if (e.code === "Space") {
|
|
38
|
+
setContainerRatio(1);
|
|
39
|
+
setXScrollbarPosition(0);
|
|
40
|
+
lastPosition.current = 0;
|
|
41
|
+
containerRef.focus();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[containerRef, lastPosition, setContainerRatio, setXScrollbarPosition]
|
|
45
|
+
);
|
|
22
46
|
if (xScale.bandwidth || yScale.bandwidth)
|
|
23
47
|
return null;
|
|
24
48
|
if (!xScroll)
|
|
25
49
|
return null;
|
|
26
|
-
return /* @__PURE__ */
|
|
27
|
-
|
|
50
|
+
return /* @__PURE__ */ jsx(
|
|
51
|
+
StyledResetter,
|
|
28
52
|
{
|
|
29
53
|
onClick: handleOnClick,
|
|
30
|
-
|
|
54
|
+
onKeyDown: handleOnKeyDown,
|
|
55
|
+
onBlur: (e) => e.stopPropagation(),
|
|
56
|
+
transform: `translate(${width - TOOLBAR.RESET.WIDTH * 2},${internalMargin.top / 2 - TOOLBAR.RESET.HEIGHT / 2})`,
|
|
31
57
|
strokeLinecap: "round",
|
|
32
|
-
|
|
33
|
-
strokeOpacity: "1",
|
|
34
|
-
style: { cursor: "pointer", opacity: containerRatio > 1 ? 1 : 0.5 },
|
|
58
|
+
isDisabled,
|
|
35
59
|
ref: setToolbarRef,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
]
|
|
60
|
+
role: "button",
|
|
61
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
62
|
+
children: /* @__PURE__ */ jsx(
|
|
63
|
+
"path",
|
|
64
|
+
{
|
|
65
|
+
d: "M 2.875 7.75 A 5.625 5.625 0 1 1 4.5225 11.7275 L 8.2725 10.7275 L 6.5225 14.9775 L 4.5225 11.7275\n M 0 0 H 17 V 17 H 0 V 0 ",
|
|
66
|
+
fill: "#ffffff",
|
|
67
|
+
stroke: "#000000",
|
|
68
|
+
strokeLinecap: "round",
|
|
69
|
+
strokeWidth: "1"
|
|
70
|
+
}
|
|
71
|
+
)
|
|
49
72
|
}
|
|
50
73
|
);
|
|
51
74
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Scroller/Controllers.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable arrow-body-style */\n/* eslint-disable indent */\nimport React, { useContext, useCallback } from 'react';\nimport { ChartContext } from '../../ChartContext';\n\nexport const Controllers = () => {\n const {\n props: { xScroll },\n width,\n xScale,\n yScale,\n containerRatio,\n setContainerRatio,\n lastPosition,\n setToolbarRef,\n setXScrollbarPosition,\n } = useContext(ChartContext);\n\n const handleOnClick = useCallback(() => {\n setContainerRatio(1);\n setXScrollbarPosition(0);\n lastPosition.current = 0;\n }, [lastPosition, setContainerRatio, setXScrollbarPosition]);\n\n // if is a bar chart we dont give controls\n if (xScale.bandwidth || yScale.bandwidth) return null;\n\n if (!xScroll) return null;\n return (\n <
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable arrow-body-style */\n/* eslint-disable indent */\nimport React, { useContext, useCallback, useMemo } from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport { ChartContext } from '../../ChartContext';\nimport { TOOLBAR } from '../../../constants';\n\nconst StyledResetter = styled('g')<{ isDisabled: 'boolean' }>`\n cursor: ${({ isDisabled }) => (isDisabled ? 'not-allowed' : 'pointer')};\n opacity: ${({ isDisabled }) => (isDisabled ? '0.4' : '1')};\n &focus {\n outline: 2px solid blue;\n }\n`;\nexport const Controllers = () => {\n const {\n props: { xScroll },\n width,\n internalMargin,\n xScale,\n yScale,\n containerRef,\n containerRatio,\n setContainerRatio,\n lastPosition,\n setToolbarRef,\n setXScrollbarPosition,\n } = useContext(ChartContext);\n\n const isDisabled = useMemo(() => containerRatio === 1, [containerRatio]);\n const handleOnClick = useCallback(() => {\n setContainerRatio(1);\n setXScrollbarPosition(0);\n lastPosition.current = 0;\n }, [lastPosition, setContainerRatio, setXScrollbarPosition]);\n\n const handleOnKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n e.stopPropagation();\n if (e.code === 'Space') {\n setContainerRatio(1);\n setXScrollbarPosition(0);\n lastPosition.current = 0;\n containerRef.focus();\n }\n },\n [containerRef, lastPosition, setContainerRatio, setXScrollbarPosition],\n );\n // if is a bar chart we dont give controls\n if (xScale.bandwidth || yScale.bandwidth) return null;\n\n if (!xScroll) return null;\n return (\n <StyledResetter\n onClick={handleOnClick}\n onKeyDown={handleOnKeyDown}\n onBlur={(e) => e.stopPropagation()}\n transform={`translate(${width - TOOLBAR.RESET.WIDTH * 2},${internalMargin.top / 2 - TOOLBAR.RESET.HEIGHT / 2})`}\n strokeLinecap=\"round\"\n isDisabled={isDisabled}\n ref={setToolbarRef}\n role=\"button\"\n tabIndex={isDisabled ? -1 : 0}\n >\n <path\n d=\"M 2.875 7.75 A 5.625 5.625 0 1 1 4.5225 11.7275 L 8.2725 10.7275 L 6.5225 14.9775 L 4.5225 11.7275\n M 0 0 H 17 V 17 H 0 V 0 \"\n fill=\"#ffffff\"\n stroke=\"#000000\"\n strokeLinecap=\"round\"\n strokeWidth=\"1\"\n ></path>\n </StyledResetter>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACgEjB;AA9DN,SAAgB,YAAY,aAAa,eAAe;AACxD,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AAExB,MAAM,iBAAiB,OAAO,GAAG;AAAA,YACrB,CAAC,EAAE,WAAW,MAAO,aAAa,gBAAgB;AAAA,aACjD,CAAC,EAAE,WAAW,MAAO,aAAa,QAAQ;AAAA;AAAA;AAAA;AAAA;AAKhD,MAAM,cAAc,MAAM;AAC/B,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,aAAa,QAAQ,MAAM,mBAAmB,GAAG,CAAC,cAAc,CAAC;AACvE,QAAM,gBAAgB,YAAY,MAAM;AACtC,sBAAkB,CAAC;AACnB,0BAAsB,CAAC;AACvB,iBAAa,UAAU;AAAA,EACzB,GAAG,CAAC,cAAc,mBAAmB,qBAAqB,CAAC;AAE3D,QAAM,kBAA8C;AAAA,IAClD,CAAC,MAAM;AACL,QAAE,gBAAgB;AAClB,UAAI,EAAE,SAAS,SAAS;AACtB,0BAAkB,CAAC;AACnB,8BAAsB,CAAC;AACvB,qBAAa,UAAU;AACvB,qBAAa,MAAM;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,cAAc,cAAc,mBAAmB,qBAAqB;AAAA,EACvE;AAEA,MAAI,OAAO,aAAa,OAAO;AAAW,WAAO;AAEjD,MAAI,CAAC;AAAS,WAAO;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,WAAW;AAAA,MACX,QAAQ,CAAC,MAAM,EAAE,gBAAgB;AAAA,MACjC,WAAW,aAAa,QAAQ,QAAQ,MAAM,QAAQ,KAAK,eAAe,MAAM,IAAI,QAAQ,MAAM,SAAS;AAAA,MAC3G,eAAc;AAAA,MACd;AAAA,MACA,KAAK;AAAA,MACL,MAAK;AAAA,MACL,UAAU,aAAa,KAAK;AAAA,MAE5B;AAAA,QAAC;AAAA;AAAA,UACC,GAAE;AAAA,UAEF,MAAK;AAAA,UACL,QAAO;AAAA,UACP,eAAc;AAAA,UACd,aAAY;AAAA;AAAA,MACb;AAAA;AAAA,EACH;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|