@hitachivantara/uikit-react-viz 4.0.1-next.2 → 4.0.1-next.5
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/Chart/Chart.d.ts +19 -0
- package/dist/Chart/Chart.js +9 -2
- package/dist/Chart/Chart.js.map +1 -1
- package/dist/Chart/Tooltip/Tooltip.js +21 -8
- package/dist/Chart/Tooltip/Tooltip.js.map +1 -1
- package/dist/legacy/Chart/Chart.d.ts +19 -0
- package/dist/legacy/Chart/Chart.js +9 -2
- package/dist/legacy/Chart/Chart.js.map +1 -1
- package/dist/legacy/Chart/Tooltip/Tooltip.js +22 -9
- package/dist/legacy/Chart/Tooltip/Tooltip.js.map +1 -1
- package/dist/modern/Chart/Chart.d.ts +19 -0
- package/dist/modern/Chart/Chart.js +9 -2
- package/dist/modern/Chart/Chart.js.map +1 -1
- package/dist/modern/Chart/Tooltip/Tooltip.js +22 -9
- package/dist/modern/Chart/Tooltip/Tooltip.js.map +1 -1
- package/package.json +3 -3
package/dist/Chart/Chart.d.ts
CHANGED
|
@@ -3,11 +3,30 @@ import { HvPlotProps } from "./Plot";
|
|
|
3
3
|
|
|
4
4
|
export type HvChartClassKey = "root";
|
|
5
5
|
|
|
6
|
+
export type TooltipElementObject = {
|
|
7
|
+
color: string;
|
|
8
|
+
name: string;
|
|
9
|
+
value: number | string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type TooltipDataObject = {
|
|
13
|
+
title: string;
|
|
14
|
+
elements: TooltipElementObject[];
|
|
15
|
+
};
|
|
16
|
+
|
|
6
17
|
export interface HvChartProps extends StandardProps<HvPlotProps, HvChartClassKey> {
|
|
18
|
+
/**
|
|
19
|
+
* An Id passed on to the component
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
7
22
|
/**
|
|
8
23
|
* Defines if should use a single or multiline tooltip.
|
|
9
24
|
*/
|
|
10
25
|
tooltipType?: "single" | "multiple";
|
|
26
|
+
/**
|
|
27
|
+
* Custom tooltip element to be displayed
|
|
28
|
+
*/
|
|
29
|
+
tooltip?: (data: TooltipDataObject) => Element;
|
|
11
30
|
/**
|
|
12
31
|
* Defines the X axis title.
|
|
13
32
|
*/
|
package/dist/Chart/Chart.js
CHANGED
|
@@ -57,7 +57,7 @@ var _styles2 = _interopRequireDefault(require("./styles"));
|
|
|
57
57
|
|
|
58
58
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
59
59
|
|
|
60
|
-
var _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
60
|
+
var _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "tooltip", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
61
61
|
|
|
62
62
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
63
63
|
|
|
@@ -75,6 +75,7 @@ var Chart = function Chart(_ref) {
|
|
|
75
75
|
config = _ref.config,
|
|
76
76
|
_ref$tooltipType = _ref.tooltipType,
|
|
77
77
|
tooltipType = _ref$tooltipType === void 0 ? "multiple" : _ref$tooltipType,
|
|
78
|
+
tooltip = _ref.tooltip,
|
|
78
79
|
afterPlot = _ref.afterPlot,
|
|
79
80
|
xAxisTitle = _ref.xAxisTitle,
|
|
80
81
|
yAxisTitle = _ref.yAxisTitle,
|
|
@@ -152,7 +153,8 @@ var Chart = function Chart(_ref) {
|
|
|
152
153
|
children: [isHover && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
153
154
|
coordinates: coordinates,
|
|
154
155
|
data: dataTooltip,
|
|
155
|
-
useSingle: useSingle
|
|
156
|
+
useSingle: useSingle,
|
|
157
|
+
tooltip: tooltip
|
|
156
158
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
157
159
|
id: id,
|
|
158
160
|
className: classes.root,
|
|
@@ -204,6 +206,11 @@ process.env.NODE_ENV !== "production" ? Chart.propTypes = {
|
|
|
204
206
|
*/
|
|
205
207
|
tooltipType: _propTypes.default.oneOf(["single", "multiple"]),
|
|
206
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Custom tooltip element to be displayed
|
|
211
|
+
*/
|
|
212
|
+
tooltip: _propTypes.default.func,
|
|
213
|
+
|
|
207
214
|
/**
|
|
208
215
|
* Function to be called after plot render.
|
|
209
216
|
*/
|
package/dist/Chart/Chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","names":["Chart","id","classes","data","layout","config","tooltipType","afterPlot","xAxisTitle","yAxisTitle","others","theme","useTheme","isHorizontal","useMemo","isNil","orientation","toUpperCase","chartLayout","applyLayoutDefaults","chartConfig","applyConfigDefaults","useSingle","useState","isHover","setIsHover","x","y","coordinates","setCoordinates","dataTooltip","setDataTooltip","onHover","useCallback","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","PropTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle","withStyles","styles"],"sources":["../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && <Tooltip
|
|
1
|
+
{"version":3,"file":"Chart.js","names":["Chart","id","classes","data","layout","config","tooltipType","tooltip","afterPlot","xAxisTitle","yAxisTitle","others","theme","useTheme","isHorizontal","useMemo","isNil","orientation","toUpperCase","chartLayout","applyLayoutDefaults","chartConfig","applyConfigDefaults","useSingle","useState","isHover","setIsHover","x","y","coordinates","setCoordinates","dataTooltip","setDataTooltip","onHover","useCallback","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","PropTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle","withStyles","styles"],"sources":["../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n tooltip,\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && (\n <Tooltip\n coordinates={coordinates}\n data={dataTooltip}\n useSingle={useSingle}\n tooltip={tooltip}\n />\n )}\n <div id={id} className={classes.root}>\n <div onMouseMove={onMouseMove}>\n <Plot\n data={data}\n layout={chartLayout}\n config={chartConfig}\n onHover={onHover}\n onUnHover={onUnHover}\n afterPlot={afterPlot}\n {...others}\n />\n </div>\n </div>\n </>\n );\n};\n\nChart.propTypes = {\n /**\n * An Id passed on to the component\n */\n id: PropTypes.string,\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n root: PropTypes.string,\n }),\n\n /**\n * Plotly data object (see https://plot.ly/javascript/reference/).\n */\n data: PropTypes.arrayOf(PropTypes.instanceOf(Object)).isRequired,\n /**\n * Plotly layout object (see https://plot.ly/javascript/reference/#layout).\n */\n layout: PropTypes.instanceOf(Object).isRequired,\n /**\n * Plotly config object (see https://plot.ly/javascript/configuration-options/).\n */\n config: PropTypes.instanceOf(Object),\n /**\n * Defines if should use a single or multiline tooltip.\n */\n tooltipType: PropTypes.oneOf([\"single\", \"multiple\"]),\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n /**\n * Function to be called after plot render.\n */\n afterPlot: PropTypes.func,\n /**\n * Defines the X axis title.\n */\n xAxisTitle: PropTypes.string,\n /**\n * Defines the Y axis title.\n */\n yAxisTitle: PropTypes.string,\n /**\n * Defines the chart subtitle.\n */\n subtitle: PropTypes.string,\n};\n\nexport default withStyles(styles, { name: \"HvChart\" })(Chart);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;;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EAAgDC,UAftC;;EAgBhB;AACF;AACA;EACE9D,MAAM,EAAEwD,kBAAA,CAAUI,UAAV,CAAqBC,MAArB,EAA6BC,UAnBrB;;EAoBhB;AACF;AACA;EACE7D,MAAM,EAAEuD,kBAAA,CAAUI,UAAV,CAAqBC,MAArB,CAvBQ;;EAwBhB;AACF;AACA;EACE3D,WAAW,EAAEsD,kBAAA,CAAUO,KAAV,CAAgB,CAAC,QAAD,EAAW,UAAX,CAAhB,CA3BG;;EA4BhB;AACF;AACA;EACE5D,OAAO,EAAEqD,kBAAA,CAAUQ,IA/BH;;EAgChB;AACF;AACA;EACE5D,SAAS,EAAEoD,kBAAA,CAAUQ,IAnCL;;EAoChB;AACF;AACA;EACE3D,UAAU,EAAEmD,kBAAA,CAAUC,MAvCN;;EAwChB;AACF;AACA;EACEnD,UAAU,EAAEkD,kBAAA,CAAUC,MA3CN;;EA4ChB;AACF;AACA;EACEQ,QAAQ,EAAET,kBAAA,CAAUC;AA/CJ,CAAlB;;eAkDe,IAAAS,kBAAA,EAAWC,gBAAX,EAAmB;EAAExB,IAAI,EAAE;AAAR,CAAnB,EAAwC/C,KAAxC,C"}
|
|
@@ -48,10 +48,13 @@ var offset = 20;
|
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
var MainToolTip = function MainToolTip(_ref) {
|
|
51
|
+
var _MultipleTooltip;
|
|
52
|
+
|
|
51
53
|
var classes = _ref.classes,
|
|
52
54
|
coordinates = _ref.coordinates,
|
|
53
55
|
data = _ref.data,
|
|
54
|
-
useSingle = _ref.useSingle
|
|
56
|
+
useSingle = _ref.useSingle,
|
|
57
|
+
tooltip = _ref.tooltip;
|
|
55
58
|
var x = coordinates.x,
|
|
56
59
|
y = coordinates.y;
|
|
57
60
|
|
|
@@ -82,16 +85,21 @@ var MainToolTip = function MainToolTip(_ref) {
|
|
|
82
85
|
top: y - height - offset
|
|
83
86
|
});
|
|
84
87
|
}, [x, y]);
|
|
88
|
+
var renderTooltip = (0, _react.useCallback)(function (CustomTooltip) {
|
|
89
|
+
if (CustomTooltip) return CustomTooltip(data);
|
|
90
|
+
if (useSingle) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SingleTooltip.default, {
|
|
91
|
+
title: data.title,
|
|
92
|
+
value: data.elements[0].value
|
|
93
|
+
});
|
|
94
|
+
return _MultipleTooltip || (_MultipleTooltip = /*#__PURE__*/(0, _jsxRuntime.jsx)(_MultiTooltip.default, {
|
|
95
|
+
data: data
|
|
96
|
+
}));
|
|
97
|
+
}, [data, useSingle]);
|
|
85
98
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
86
99
|
ref: ref,
|
|
87
100
|
className: classes.root,
|
|
88
101
|
style: style,
|
|
89
|
-
children:
|
|
90
|
-
title: data.title,
|
|
91
|
-
value: data.elements[0].value
|
|
92
|
-
}) || /*#__PURE__*/(0, _jsxRuntime.jsx)(_MultiTooltip.default, {
|
|
93
|
-
data: data
|
|
94
|
-
})
|
|
102
|
+
children: renderTooltip(tooltip)
|
|
95
103
|
});
|
|
96
104
|
};
|
|
97
105
|
|
|
@@ -154,7 +162,12 @@ process.env.NODE_ENV !== "production" ? MainToolTip.propTypes = {
|
|
|
154
162
|
/**
|
|
155
163
|
* Defines if should use a single or multiline tooltip.
|
|
156
164
|
*/
|
|
157
|
-
useSingle: _propTypes.default.bool
|
|
165
|
+
useSingle: _propTypes.default.bool,
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Custom tooltip element to be displayed
|
|
169
|
+
*/
|
|
170
|
+
tooltip: _propTypes.default.func
|
|
158
171
|
} : void 0;
|
|
159
172
|
MainToolTip.defaultProps = {
|
|
160
173
|
useSingle: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["offset","MainToolTip","classes","coordinates","data","useSingle","x","y","useState","left","top","visibility","style","setStyle","ref","useRef","useEffect","current","getBoundingClientRect","width","height","
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["offset","MainToolTip","classes","coordinates","data","useSingle","tooltip","x","y","useState","left","top","visibility","style","setStyle","ref","useRef","useEffect","current","getBoundingClientRect","width","height","renderTooltip","useCallback","CustomTooltip","title","elements","value","root","propTypes","PropTypes","shape","string","isRequired","arrayOf","color","name","number","bool","func","defaultProps","withStyles","styles"],"sources":["../../../src/Chart/Tooltip/Tooltip.js"],"sourcesContent":["import React, { useEffect, useRef, useState, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { withStyles } from \"@mui/styles\";\nimport SingleTooltip from \"./SingleTooltip\";\nimport MultipleTooltip from \"./MultiTooltip\";\nimport styles from \"./styles\";\n\nconst offset = 20;\n\n/**\n * Component responsible for deciding which tooltip should be use and to calculate\n * the exact position where it should be render.\n */\nconst MainToolTip = ({ classes, coordinates, data, useSingle, tooltip }) => {\n const { x, y } = coordinates;\n const [style, setStyle] = useState({ left: x, top: y, visibility: \"hidden\" });\n const ref = useRef(null);\n\n /**\n * Calculate the position where the tooltip has to render, having in account\n * the dimensions.\n */\n useEffect(() => {\n if (!ref.current || !ref.current.getBoundingClientRect().width) return;\n\n const { width, height } = ref.current.getBoundingClientRect();\n\n setStyle({ left: x - width / 2, top: y - height - offset });\n }, [x, y]);\n\n const renderTooltip = useCallback(\n (CustomTooltip) => {\n if (CustomTooltip) return CustomTooltip(data);\n if (useSingle) return <SingleTooltip title={data.title} value={data.elements[0].value} />;\n return <MultipleTooltip data={data} />;\n },\n [data, useSingle]\n );\n\n return (\n <div ref={ref} className={classes.root} style={style}>\n {renderTooltip(tooltip)}\n </div>\n );\n};\n\nMainToolTip.propTypes = {\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n /**\n * Styles applied to the barchart root class.\n */\n root: PropTypes.string,\n }).isRequired,\n /**\n * Data of the tooltip.\n */\n data: PropTypes.shape({\n /**\n * Title.\n */\n title: PropTypes.string,\n /**\n * Values of the tooltip.\n */\n elements: PropTypes.arrayOf(\n PropTypes.shape({\n /**\n * Color of the bar.\n */\n color: PropTypes.string,\n /**\n * Name.\n */\n name: PropTypes.string,\n /**\n * Value.\n */\n value: PropTypes.number,\n })\n ),\n }).isRequired,\n /**\n * Coordinates.\n */\n coordinates: PropTypes.shape({\n /**\n * xx's coordinate.\n */\n x: PropTypes.number.isRequired,\n /**\n * yy's coordinate.\n */\n y: PropTypes.number.isRequired,\n }).isRequired,\n /**\n * Defines if should use a single or multiline tooltip.\n */\n useSingle: PropTypes.bool,\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n};\n\nMainToolTip.defaultProps = {\n useSingle: false,\n};\n\nexport default withStyles(styles, { name: \"HvChartTooltip\" })(MainToolTip);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,MAAM,GAAG,EAAf;AAEA;AACA;AACA;AACA;;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAc,OAAwD;EAAA;;EAAA,IAArDC,OAAqD,QAArDA,OAAqD;EAAA,IAA5CC,WAA4C,QAA5CA,WAA4C;EAAA,IAA/BC,IAA+B,QAA/BA,IAA+B;EAAA,IAAzBC,SAAyB,QAAzBA,SAAyB;EAAA,IAAdC,OAAc,QAAdA,OAAc;EAC1E,IAAQC,CAAR,GAAiBJ,WAAjB,CAAQI,CAAR;EAAA,IAAWC,CAAX,GAAiBL,WAAjB,CAAWK,CAAX;;EACA,gBAA0B,IAAAC,eAAA,EAAS;IAAEC,IAAI,EAAEH,CAAR;IAAWI,GAAG,EAAEH,CAAhB;IAAmBI,UAAU,EAAE;EAA/B,CAAT,CAA1B;EAAA;EAAA,IAAOC,KAAP;EAAA,IAAcC,QAAd;;EACA,IAAMC,GAAG,GAAG,IAAAC,aAAA,EAAO,IAAP,CAAZ;EAEA;AACF;AACA;AACA;;EACE,IAAAC,gBAAA,EAAU,YAAM;IACd,IAAI,CAACF,GAAG,CAACG,OAAL,IAAgB,CAACH,GAAG,CAACG,O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AJG;;IAKpB;AACJ;AACA;IACIN,QAAQ,EAAEI,kBAAA,CAAUI,OAAV,CACRJ,kBAAA,CAAUC,KAAV,CAAgB;MACd;AACR;AACA;MACQI,KAAK,EAAEL,kBAAA,CAAUE,MAJH;;MAKd;AACR;AACA;MACQI,IAAI,EAAEN,kBAAA,CAAUE,MARF;;MASd;AACR;AACA;MACQL,KAAK,EAAEG,kBAAA,CAAUO;IAZH,CAAhB,CADQ;EARU,CAAhB,EAwBHJ,UArCmB;;EAsCtB;AACF;AACA;EACE9B,WAAW,EAAE2B,kBAAA,CAAUC,KAAV,CAAgB;IAC3B;AACJ;AACA;IACIxB,CAAC,EAAEuB,kBAAA,CAAUO,MAAV,CAAiBJ,UAJO;;IAK3B;AACJ;AACA;IACIzB,CAAC,EAAEsB,kBAAA,CAAUO,MAAV,CAAiBJ;EARO,CAAhB,EASVA,UAlDmB;;EAmDtB;AACF;AACA;EACE5B,SAAS,EAAEyB,kBAAA,CAAUQ,IAtDC;;EAuDtB;AACF;AACA;EACEhC,OAAO,EAAEwB,kBAAA,CAAUS;AA1DG,CAAxB;AA6DAtC,WAAW,CAACuC,YAAZ,GAA2B;EACzBnC,SAAS,EAAE;AADc,CAA3B;;eAIe,IAAAoC,kBAAA,EAAWC,gBAAX,EAAmB;EAAEN,IAAI,EAAE;AAAR,CAAnB,EAA+CnC,WAA/C,C"}
|
|
@@ -3,11 +3,30 @@ import { HvPlotProps } from "./Plot";
|
|
|
3
3
|
|
|
4
4
|
export type HvChartClassKey = "root";
|
|
5
5
|
|
|
6
|
+
export type TooltipElementObject = {
|
|
7
|
+
color: string;
|
|
8
|
+
name: string;
|
|
9
|
+
value: number | string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type TooltipDataObject = {
|
|
13
|
+
title: string;
|
|
14
|
+
elements: TooltipElementObject[];
|
|
15
|
+
};
|
|
16
|
+
|
|
6
17
|
export interface HvChartProps extends StandardProps<HvPlotProps, HvChartClassKey> {
|
|
18
|
+
/**
|
|
19
|
+
* An Id passed on to the component
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
7
22
|
/**
|
|
8
23
|
* Defines if should use a single or multiline tooltip.
|
|
9
24
|
*/
|
|
10
25
|
tooltipType?: "single" | "multiple";
|
|
26
|
+
/**
|
|
27
|
+
* Custom tooltip element to be displayed
|
|
28
|
+
*/
|
|
29
|
+
tooltip?: (data: TooltipDataObject) => Element;
|
|
11
30
|
/**
|
|
12
31
|
* Defines the X axis title.
|
|
13
32
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
4
|
+
var _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "tooltip", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
5
5
|
|
|
6
6
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
7
|
|
|
@@ -35,6 +35,7 @@ var Chart = function Chart(_ref) {
|
|
|
35
35
|
config = _ref.config,
|
|
36
36
|
_ref$tooltipType = _ref.tooltipType,
|
|
37
37
|
tooltipType = _ref$tooltipType === void 0 ? "multiple" : _ref$tooltipType,
|
|
38
|
+
tooltip = _ref.tooltip,
|
|
38
39
|
afterPlot = _ref.afterPlot,
|
|
39
40
|
xAxisTitle = _ref.xAxisTitle,
|
|
40
41
|
yAxisTitle = _ref.yAxisTitle,
|
|
@@ -113,7 +114,8 @@ var Chart = function Chart(_ref) {
|
|
|
113
114
|
children: [isHover && /*#__PURE__*/_jsx(Tooltip, {
|
|
114
115
|
coordinates: coordinates,
|
|
115
116
|
data: dataTooltip,
|
|
116
|
-
useSingle: useSingle
|
|
117
|
+
useSingle: useSingle,
|
|
118
|
+
tooltip: tooltip
|
|
117
119
|
}), /*#__PURE__*/_jsx("div", {
|
|
118
120
|
id: id,
|
|
119
121
|
className: classes.root,
|
|
@@ -165,6 +167,11 @@ process.env.NODE_ENV !== "production" ? Chart.propTypes = {
|
|
|
165
167
|
*/
|
|
166
168
|
tooltipType: PropTypes.oneOf(["single", "multiple"]),
|
|
167
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Custom tooltip element to be displayed
|
|
172
|
+
*/
|
|
173
|
+
tooltip: PropTypes.func,
|
|
174
|
+
|
|
168
175
|
/**
|
|
169
176
|
* Function to be called after plot render.
|
|
170
177
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","names":["React","useState","useMemo","useCallback","PropTypes","isNil","withStyles","useTheme","Tooltip","applyLayoutDefaults","applyConfigDefaults","Plot","styles","Chart","id","classes","data","layout","config","tooltipType","afterPlot","xAxisTitle","yAxisTitle","others","theme","isHorizontal","orientation","toUpperCase","chartLayout","chartConfig","useSingle","isHover","setIsHover","x","y","coordinates","setCoordinates","dataTooltip","setDataTooltip","onHover","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle"],"sources":["../../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && <Tooltip
|
|
1
|
+
{"version":3,"file":"Chart.js","names":["React","useState","useMemo","useCallback","PropTypes","isNil","withStyles","useTheme","Tooltip","applyLayoutDefaults","applyConfigDefaults","Plot","styles","Chart","id","classes","data","layout","config","tooltipType","tooltip","afterPlot","xAxisTitle","yAxisTitle","others","theme","isHorizontal","orientation","toUpperCase","chartLayout","chartConfig","useSingle","isHover","setIsHover","x","y","coordinates","setCoordinates","dataTooltip","setDataTooltip","onHover","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle"],"sources":["../../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n tooltip,\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && (\n <Tooltip\n coordinates={coordinates}\n data={dataTooltip}\n useSingle={useSingle}\n tooltip={tooltip}\n />\n )}\n <div id={id} className={classes.root}>\n <div onMouseMove={onMouseMove}>\n <Plot\n data={data}\n layout={chartLayout}\n config={chartConfig}\n onHover={onHover}\n onUnHover={onUnHover}\n afterPlot={afterPlot}\n {...others}\n />\n </div>\n </div>\n </>\n );\n};\n\nChart.propTypes = {\n /**\n * An Id passed on to the component\n */\n id: PropTypes.string,\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n root: PropTypes.string,\n }),\n\n /**\n * Plotly data object (see https://plot.ly/javascript/reference/).\n */\n data: PropTypes.arrayOf(PropTypes.instanceOf(Object)).isRequired,\n /**\n * Plotly layout object (see https://plot.ly/javascript/reference/#layout).\n */\n layout: PropTypes.instanceOf(Object).isRequired,\n /**\n * Plotly config object (see https://plot.ly/javascript/configuration-options/).\n */\n config: PropTypes.instanceOf(Object),\n /**\n * Defines if should use a single or multiline tooltip.\n */\n tooltipType: PropTypes.oneOf([\"single\", \"multiple\"]),\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n /**\n * Function to be called after plot render.\n */\n afterPlot: PropTypes.func,\n /**\n * Defines the X axis title.\n */\n xAxisTitle: PropTypes.string,\n /**\n * Defines the Y axis title.\n */\n yAxisTitle: PropTypes.string,\n /**\n * Defines the chart subtitle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ADF;IADF,EATF;EAAA,EADF;AAyBD,CAzGD;;AA2GA,wCAAAX,KAAK,CAACoD,SAAN,GAAkB;EAChB;AACF;AACA;EACEnD,EAAE,EAAEV,SAAS,CAAC8D,MAJE;;EAKhB;AACF;AACA;EACEnD,OAAO,EAAEX,SAAS,CAAC+D,KAAV,CAAgB;IACvBH,IAAI,EAAE5D,SAAS,CAAC8D;EADO,CAAhB,CARO;;EAYhB;AACF;AACA;EACElD,IAAI,EAAEZ,SAAS,CAACgE,OAAV,CAAkBhE,SAAS,CAACiE,UAAV,CAAqBC,MAArB,CAAlB,EAAgDC,UAftC;;EAgBhB;AACF;AACA;EACEtD,MAAM,EAAEb,SAAS,CAACiE,UAAV,CAAqBC,MAArB,EAA6BC,UAnBrB;;EAoBhB;AACF;AACA;EACErD,MAAM,EAAEd,SAAS,CAACiE,UAAV,CAAqBC,MAArB,CAvBQ;;EAwBhB;AACF;AACA;EACEnD,WAAW,EAAEf,SAAS,CAACoE,KAAV,CAAgB,CAAC,QAAD,EAAW,UAAX,CAAhB,CA3BG;;EA4BhB;AACF;AACA;EACEpD,OAAO,EAAEhB,SAAS,CAACqE,IA/BH;;EAgChB;AACF;AACA;EACEpD,SAAS,EAAEjB,SAAS,CAACqE,IAnCL;;EAoChB;AACF;AACA;EACEnD,UAAU,EAAElB,SAAS,CAAC8D,MAvCN;;EAwChB;AACF;AACA;EACE3C,UAAU,EAAEnB,SAAS,CAAC8D,MA3CN;;EA4ChB;AACF;AACA;EACEQ,QAAQ,EAAEtE,SAAS,CAAC8D;AA/CJ,CAAlB;AAkDA,eAAe5D,UAAU,CAACM,MAAD,EAAS;EAAEyC,IAAI,EAAE;AAAR,CAAT,CAAV,CAAwCxC,KAAxC,CAAf"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import React, { useEffect, useRef, useState, useCallback } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { withStyles } from "@mui/styles";
|
|
5
5
|
import SingleTooltip from "./SingleTooltip";
|
|
@@ -13,10 +13,13 @@ var offset = 20;
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
var MainToolTip = function MainToolTip(_ref) {
|
|
16
|
+
var _MultipleTooltip;
|
|
17
|
+
|
|
16
18
|
var classes = _ref.classes,
|
|
17
19
|
coordinates = _ref.coordinates,
|
|
18
20
|
data = _ref.data,
|
|
19
|
-
useSingle = _ref.useSingle
|
|
21
|
+
useSingle = _ref.useSingle,
|
|
22
|
+
tooltip = _ref.tooltip;
|
|
20
23
|
var x = coordinates.x,
|
|
21
24
|
y = coordinates.y;
|
|
22
25
|
|
|
@@ -47,16 +50,21 @@ var MainToolTip = function MainToolTip(_ref) {
|
|
|
47
50
|
top: y - height - offset
|
|
48
51
|
});
|
|
49
52
|
}, [x, y]);
|
|
53
|
+
var renderTooltip = useCallback(function (CustomTooltip) {
|
|
54
|
+
if (CustomTooltip) return CustomTooltip(data);
|
|
55
|
+
if (useSingle) return /*#__PURE__*/_jsx(SingleTooltip, {
|
|
56
|
+
title: data.title,
|
|
57
|
+
value: data.elements[0].value
|
|
58
|
+
});
|
|
59
|
+
return _MultipleTooltip || (_MultipleTooltip = /*#__PURE__*/_jsx(MultipleTooltip, {
|
|
60
|
+
data: data
|
|
61
|
+
}));
|
|
62
|
+
}, [data, useSingle]);
|
|
50
63
|
return /*#__PURE__*/_jsx("div", {
|
|
51
64
|
ref: ref,
|
|
52
65
|
className: classes.root,
|
|
53
66
|
style: style,
|
|
54
|
-
children:
|
|
55
|
-
title: data.title,
|
|
56
|
-
value: data.elements[0].value
|
|
57
|
-
}) || /*#__PURE__*/_jsx(MultipleTooltip, {
|
|
58
|
-
data: data
|
|
59
|
-
})
|
|
67
|
+
children: renderTooltip(tooltip)
|
|
60
68
|
});
|
|
61
69
|
};
|
|
62
70
|
|
|
@@ -119,7 +127,12 @@ process.env.NODE_ENV !== "production" ? MainToolTip.propTypes = {
|
|
|
119
127
|
/**
|
|
120
128
|
* Defines if should use a single or multiline tooltip.
|
|
121
129
|
*/
|
|
122
|
-
useSingle: PropTypes.bool
|
|
130
|
+
useSingle: PropTypes.bool,
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Custom tooltip element to be displayed
|
|
134
|
+
*/
|
|
135
|
+
tooltip: PropTypes.func
|
|
123
136
|
} : void 0;
|
|
124
137
|
MainToolTip.defaultProps = {
|
|
125
138
|
useSingle: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["React","useEffect","useRef","useState","PropTypes","withStyles","SingleTooltip","MultipleTooltip","styles","offset","MainToolTip","classes","coordinates","data","useSingle","x","y","left","top","visibility","style","setStyle","ref","current","getBoundingClientRect","width","height","
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["React","useEffect","useRef","useState","useCallback","PropTypes","withStyles","SingleTooltip","MultipleTooltip","styles","offset","MainToolTip","classes","coordinates","data","useSingle","tooltip","x","y","left","top","visibility","style","setStyle","ref","current","getBoundingClientRect","width","height","renderTooltip","CustomTooltip","title","elements","value","root","propTypes","shape","string","isRequired","arrayOf","color","name","number","bool","func","defaultProps"],"sources":["../../../../src/Chart/Tooltip/Tooltip.js"],"sourcesContent":["import React, { useEffect, useRef, useState, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { withStyles } from \"@mui/styles\";\nimport SingleTooltip from \"./SingleTooltip\";\nimport MultipleTooltip from \"./MultiTooltip\";\nimport styles from \"./styles\";\n\nconst offset = 20;\n\n/**\n * Component responsible for deciding which tooltip should be use and to calculate\n * the exact position where it should be render.\n */\nconst MainToolTip = ({ classes, coordinates, data, useSingle, tooltip }) => {\n const { x, y } = coordinates;\n const [style, setStyle] = useState({ left: x, top: y, visibility: \"hidden\" });\n const ref = useRef(null);\n\n /**\n * Calculate the position where the tooltip has to render, having in account\n * the dimensions.\n */\n useEffect(() => {\n if (!ref.current || !ref.current.getBoundingClientRect().width) return;\n\n const { width, height } = ref.current.getBoundingClientRect();\n\n setStyle({ left: x - width / 2, top: y - height - offset });\n }, [x, y]);\n\n const renderTooltip = useCallback(\n (CustomTooltip) => {\n if (CustomTooltip) return CustomTooltip(data);\n if (useSingle) return <SingleTooltip title={data.title} value={data.elements[0].value} />;\n return <MultipleTooltip data={data} />;\n },\n [data, useSingle]\n );\n\n return (\n <div ref={ref} className={classes.root} style={style}>\n {renderTooltip(tooltip)}\n </div>\n );\n};\n\nMainToolTip.propTypes = {\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n /**\n * Styles applied to the barchart root class.\n */\n root: PropTypes.string,\n }).isRequired,\n /**\n * Data of the tooltip.\n */\n data: PropTypes.shape({\n /**\n * Title.\n */\n title: PropTypes.string,\n /**\n * Values of the tooltip.\n */\n elements: PropTypes.arrayOf(\n PropTypes.shape({\n /**\n * Color of the bar.\n */\n color: PropTypes.string,\n /**\n * Name.\n */\n name: PropTypes.string,\n /**\n * Value.\n */\n value: PropTypes.number,\n })\n ),\n }).isRequired,\n /**\n * Coordinates.\n */\n coordinates: PropTypes.shape({\n /**\n * xx's coordinate.\n */\n x: PropTypes.number.isRequired,\n /**\n * yy's coordinate.\n */\n y: PropTypes.number.isRequired,\n }).isRequired,\n /**\n * Defines if should use a single or multiline tooltip.\n */\n useSingle: PropTypes.bool,\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n};\n\nMainToolTip.defaultProps = {\n useSingle: false,\n};\n\nexport default withStyles(styles, { name: \"HvChartTooltip\" })(MainToolTip);\n"],"mappings":";AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,EAAmCC,QAAnC,EAA6CC,WAA7C,QAAgE,OAAhE;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,UAAT,QAA2B,aAA3B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC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;IACIpB,CAAC,EAAEb,SAAS,CAACqC,MAAV,CAAiBJ;EARO,CAAhB,EASVA,UAlDmB;;EAmDtB;AACF;AACA;EACEvB,SAAS,EAAEV,SAAS,CAACsC,IAtDC;;EAuDtB;AACF;AACA;EACE3B,OAAO,EAAEX,SAAS,CAACuC;AA1DG,CAAxB;AA6DAjC,WAAW,CAACkC,YAAZ,GAA2B;EACzB9B,SAAS,EAAE;AADc,CAA3B;AAIA,eAAeT,UAAU,CAACG,MAAD,EAAS;EAAEgC,IAAI,EAAE;AAAR,CAAT,CAAV,CAA+C9B,WAA/C,CAAf"}
|
|
@@ -3,11 +3,30 @@ import { HvPlotProps } from "./Plot";
|
|
|
3
3
|
|
|
4
4
|
export type HvChartClassKey = "root";
|
|
5
5
|
|
|
6
|
+
export type TooltipElementObject = {
|
|
7
|
+
color: string;
|
|
8
|
+
name: string;
|
|
9
|
+
value: number | string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type TooltipDataObject = {
|
|
13
|
+
title: string;
|
|
14
|
+
elements: TooltipElementObject[];
|
|
15
|
+
};
|
|
16
|
+
|
|
6
17
|
export interface HvChartProps extends StandardProps<HvPlotProps, HvChartClassKey> {
|
|
18
|
+
/**
|
|
19
|
+
* An Id passed on to the component
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
7
22
|
/**
|
|
8
23
|
* Defines if should use a single or multiline tooltip.
|
|
9
24
|
*/
|
|
10
25
|
tooltipType?: "single" | "multiple";
|
|
26
|
+
/**
|
|
27
|
+
* Custom tooltip element to be displayed
|
|
28
|
+
*/
|
|
29
|
+
tooltip?: (data: TooltipDataObject) => Element;
|
|
11
30
|
/**
|
|
12
31
|
* Defines the X axis title.
|
|
13
32
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
const _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
3
|
+
const _excluded = ["id", "classes", "data", "layout", "config", "tooltipType", "tooltip", "afterPlot", "xAxisTitle", "yAxisTitle"];
|
|
4
4
|
|
|
5
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
6
|
|
|
@@ -27,6 +27,7 @@ const Chart = _ref => {
|
|
|
27
27
|
layout,
|
|
28
28
|
config,
|
|
29
29
|
tooltipType = "multiple",
|
|
30
|
+
tooltip,
|
|
30
31
|
afterPlot,
|
|
31
32
|
xAxisTitle,
|
|
32
33
|
yAxisTitle
|
|
@@ -92,7 +93,8 @@ const Chart = _ref => {
|
|
|
92
93
|
children: [isHover && /*#__PURE__*/_jsx(Tooltip, {
|
|
93
94
|
coordinates: coordinates,
|
|
94
95
|
data: dataTooltip,
|
|
95
|
-
useSingle: useSingle
|
|
96
|
+
useSingle: useSingle,
|
|
97
|
+
tooltip: tooltip
|
|
96
98
|
}), /*#__PURE__*/_jsx("div", {
|
|
97
99
|
id: id,
|
|
98
100
|
className: classes.root,
|
|
@@ -144,6 +146,11 @@ process.env.NODE_ENV !== "production" ? Chart.propTypes = {
|
|
|
144
146
|
*/
|
|
145
147
|
tooltipType: PropTypes.oneOf(["single", "multiple"]),
|
|
146
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Custom tooltip element to be displayed
|
|
151
|
+
*/
|
|
152
|
+
tooltip: PropTypes.func,
|
|
153
|
+
|
|
147
154
|
/**
|
|
148
155
|
* Function to be called after plot render.
|
|
149
156
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","names":["React","useState","useMemo","useCallback","PropTypes","isNil","withStyles","useTheme","Tooltip","applyLayoutDefaults","applyConfigDefaults","Plot","styles","Chart","id","classes","data","layout","config","tooltipType","afterPlot","xAxisTitle","yAxisTitle","others","theme","isHorizontal","orientation","toUpperCase","chartLayout","chartConfig","useSingle","isHover","setIsHover","coordinates","setCoordinates","x","y","dataTooltip","setDataTooltip","onHover","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle"],"sources":["../../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && <Tooltip
|
|
1
|
+
{"version":3,"file":"Chart.js","names":["React","useState","useMemo","useCallback","PropTypes","isNil","withStyles","useTheme","Tooltip","applyLayoutDefaults","applyConfigDefaults","Plot","styles","Chart","id","classes","data","layout","config","tooltipType","tooltip","afterPlot","xAxisTitle","yAxisTitle","others","theme","isHorizontal","orientation","toUpperCase","chartLayout","chartConfig","useSingle","isHover","setIsHover","coordinates","setCoordinates","x","y","dataTooltip","setDataTooltip","onHover","event","points","dataFromPoints","title","elements","forEach","p","i","fData","fullData","pNumber","pointNumber","name","push","color","marker","line","labels","value","onUnHover","onMouseMove","clientX","clientY","root","propTypes","string","shape","arrayOf","instanceOf","Object","isRequired","oneOf","func","subtitle"],"sources":["../../../src/Chart/Chart.js"],"sourcesContent":["import React, { useState, useMemo, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport isNil from \"lodash/isNil\";\nimport { withStyles, useTheme } from \"@mui/styles\";\n\nimport Tooltip from \"./Tooltip\";\nimport { applyLayoutDefaults, applyConfigDefaults } from \"./chartPlotlyOverrides\";\n\nimport Plot from \"./Plot\";\nimport styles from \"./styles\";\n\nconst Chart = ({\n id,\n classes,\n data,\n layout,\n config,\n tooltipType = \"multiple\",\n tooltip,\n afterPlot,\n xAxisTitle,\n yAxisTitle,\n ...others\n}) => {\n const theme = useTheme();\n\n /* Values derived from props */\n\n // Check if the barchart is horizontal or vertical.\n const isHorizontal = useMemo(\n () => (!isNil(data[0]?.orientation) ? data[0].orientation.toUpperCase() === \"H\" : false),\n [data]\n );\n\n const chartLayout = useMemo(\n () => applyLayoutDefaults(layout, theme, isHorizontal, xAxisTitle, yAxisTitle),\n [isHorizontal, layout, theme, xAxisTitle, yAxisTitle]\n );\n\n const chartConfig = useMemo(() => applyConfigDefaults(config), [config]);\n\n const useSingle = tooltipType === \"single\";\n\n /* State */\n\n const [isHover, setIsHover] = useState(false);\n const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });\n const [dataTooltip, setDataTooltip] = useState();\n\n /* Callbacks */\n\n // Extract data from the plotly onHover event to be used to create the tooltip.\n const onHover = useCallback(\n (event) => {\n const { points } = event;\n\n const dataFromPoints = {\n title: \"\",\n elements: [],\n };\n\n points.forEach((p, i) => {\n const fData = p.fullData;\n const pNumber = p.pointNumber;\n\n if (i === 0) dataFromPoints.title = isHorizontal ? p.y : p.x || fData.name;\n\n dataFromPoints.elements.push({\n color: fData.marker?.color || fData.line?.color || p.color,\n name: fData.labels?.[pNumber] || fData.name,\n value: isHorizontal ? p.x : p.y || p.value,\n });\n });\n\n setDataTooltip(dataFromPoints);\n setIsHover(true);\n },\n [isHorizontal]\n );\n\n const onUnHover = useCallback(() => {\n setIsHover(false);\n }, []);\n\n const onMouseMove = useCallback((event) => {\n setCoordinates({\n x: event.clientX,\n y: event.clientY,\n });\n }, []);\n\n return (\n <>\n {isHover && (\n <Tooltip\n coordinates={coordinates}\n data={dataTooltip}\n useSingle={useSingle}\n tooltip={tooltip}\n />\n )}\n <div id={id} className={classes.root}>\n <div onMouseMove={onMouseMove}>\n <Plot\n data={data}\n layout={chartLayout}\n config={chartConfig}\n onHover={onHover}\n onUnHover={onUnHover}\n afterPlot={afterPlot}\n {...others}\n />\n </div>\n </div>\n </>\n );\n};\n\nChart.propTypes = {\n /**\n * An Id passed on to the component\n */\n id: PropTypes.string,\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n root: PropTypes.string,\n }),\n\n /**\n * Plotly data object (see https://plot.ly/javascript/reference/).\n */\n data: PropTypes.arrayOf(PropTypes.instanceOf(Object)).isRequired,\n /**\n * Plotly layout object (see https://plot.ly/javascript/reference/#layout).\n */\n layout: PropTypes.instanceOf(Object).isRequired,\n /**\n * Plotly config object (see https://plot.ly/javascript/configuration-options/).\n */\n config: PropTypes.instanceOf(Object),\n /**\n * Defines if should use a single or multiline tooltip.\n */\n tooltipType: PropTypes.oneOf([\"single\", \"multiple\"]),\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n /**\n * Function to be called after plot render.\n */\n afterPlot: PropTypes.func,\n /**\n * Defines the X axis title.\n */\n xAxisTitle: PropTypes.string,\n /**\n * Defines the Y axis title.\n */\n yAxisTitle: PropTypes.string,\n /**\n * Defines the chart subtitle.\n */\n subtitle: PropTypes.string,\n};\n\nexport default withStyles(styles, { name: \"HvChart\" })(Chart);\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,OAA1B,EAAmCC,WAAnC,QAAsD,OAAtD;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,KAAP,MAAkB,cAAlB;AACA,SAASC,UAAT,EAAqBC,QAArB,QAAqC,aAArC;AAEA,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,mBAAT,EAA8BC,mBAA9B,QAAyD,wBAAzD;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,MAAP,MAAmB,UAAnB;;;;;AAEA,MAAMC,KAAK,GAAG,QAYR;EAAA,IAZS;IACbC,EADa;IAEbC,OAFa;IAGbC,IAHa;IAIbC,MAJa;IAKbC,MALa;IAMbC,WAAW,GAAG,UAND;IAObC,OAPa;IAQbC,SARa;IASbC,UATa;IAUbC;EAVa,CAYT;EAAA,IADDC,MACC;;EACJ,MAAMC,KAAK,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AAlB;AAkDA,eAAe5D,UAAU,CAACM,MAAD,EAAS;EAAEyC,IAAI,EAAE;AAAR,CAAT,CAAV,CAAwCxC,KAAxC,CAAf"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import React, { useEffect, useRef, useState, useCallback } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { withStyles } from "@mui/styles";
|
|
5
5
|
import SingleTooltip from "./SingleTooltip";
|
|
@@ -16,8 +16,11 @@ const MainToolTip = ({
|
|
|
16
16
|
classes,
|
|
17
17
|
coordinates,
|
|
18
18
|
data,
|
|
19
|
-
useSingle
|
|
19
|
+
useSingle,
|
|
20
|
+
tooltip
|
|
20
21
|
}) => {
|
|
22
|
+
var _MultipleTooltip;
|
|
23
|
+
|
|
21
24
|
const {
|
|
22
25
|
x,
|
|
23
26
|
y
|
|
@@ -44,16 +47,21 @@ const MainToolTip = ({
|
|
|
44
47
|
top: y - height - offset
|
|
45
48
|
});
|
|
46
49
|
}, [x, y]);
|
|
50
|
+
const renderTooltip = useCallback(CustomTooltip => {
|
|
51
|
+
if (CustomTooltip) return CustomTooltip(data);
|
|
52
|
+
if (useSingle) return /*#__PURE__*/_jsx(SingleTooltip, {
|
|
53
|
+
title: data.title,
|
|
54
|
+
value: data.elements[0].value
|
|
55
|
+
});
|
|
56
|
+
return _MultipleTooltip || (_MultipleTooltip = /*#__PURE__*/_jsx(MultipleTooltip, {
|
|
57
|
+
data: data
|
|
58
|
+
}));
|
|
59
|
+
}, [data, useSingle]);
|
|
47
60
|
return /*#__PURE__*/_jsx("div", {
|
|
48
61
|
ref: ref,
|
|
49
62
|
className: classes.root,
|
|
50
63
|
style: style,
|
|
51
|
-
children:
|
|
52
|
-
title: data.title,
|
|
53
|
-
value: data.elements[0].value
|
|
54
|
-
}) || /*#__PURE__*/_jsx(MultipleTooltip, {
|
|
55
|
-
data: data
|
|
56
|
-
})
|
|
64
|
+
children: renderTooltip(tooltip)
|
|
57
65
|
});
|
|
58
66
|
};
|
|
59
67
|
|
|
@@ -116,7 +124,12 @@ process.env.NODE_ENV !== "production" ? MainToolTip.propTypes = {
|
|
|
116
124
|
/**
|
|
117
125
|
* Defines if should use a single or multiline tooltip.
|
|
118
126
|
*/
|
|
119
|
-
useSingle: PropTypes.bool
|
|
127
|
+
useSingle: PropTypes.bool,
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Custom tooltip element to be displayed
|
|
131
|
+
*/
|
|
132
|
+
tooltip: PropTypes.func
|
|
120
133
|
} : void 0;
|
|
121
134
|
MainToolTip.defaultProps = {
|
|
122
135
|
useSingle: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["React","useEffect","useRef","useState","PropTypes","withStyles","SingleTooltip","MultipleTooltip","styles","offset","MainToolTip","classes","coordinates","data","useSingle","x","y","style","setStyle","left","top","visibility","ref","current","getBoundingClientRect","width","height","
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["React","useEffect","useRef","useState","useCallback","PropTypes","withStyles","SingleTooltip","MultipleTooltip","styles","offset","MainToolTip","classes","coordinates","data","useSingle","tooltip","x","y","style","setStyle","left","top","visibility","ref","current","getBoundingClientRect","width","height","renderTooltip","CustomTooltip","title","elements","value","root","propTypes","shape","string","isRequired","arrayOf","color","name","number","bool","func","defaultProps"],"sources":["../../../../src/Chart/Tooltip/Tooltip.js"],"sourcesContent":["import React, { useEffect, useRef, useState, useCallback } from \"react\";\nimport PropTypes from \"prop-types\";\nimport { withStyles } from \"@mui/styles\";\nimport SingleTooltip from \"./SingleTooltip\";\nimport MultipleTooltip from \"./MultiTooltip\";\nimport styles from \"./styles\";\n\nconst offset = 20;\n\n/**\n * Component responsible for deciding which tooltip should be use and to calculate\n * the exact position where it should be render.\n */\nconst MainToolTip = ({ classes, coordinates, data, useSingle, tooltip }) => {\n const { x, y } = coordinates;\n const [style, setStyle] = useState({ left: x, top: y, visibility: \"hidden\" });\n const ref = useRef(null);\n\n /**\n * Calculate the position where the tooltip has to render, having in account\n * the dimensions.\n */\n useEffect(() => {\n if (!ref.current || !ref.current.getBoundingClientRect().width) return;\n\n const { width, height } = ref.current.getBoundingClientRect();\n\n setStyle({ left: x - width / 2, top: y - height - offset });\n }, [x, y]);\n\n const renderTooltip = useCallback(\n (CustomTooltip) => {\n if (CustomTooltip) return CustomTooltip(data);\n if (useSingle) return <SingleTooltip title={data.title} value={data.elements[0].value} />;\n return <MultipleTooltip data={data} />;\n },\n [data, useSingle]\n );\n\n return (\n <div ref={ref} className={classes.root} style={style}>\n {renderTooltip(tooltip)}\n </div>\n );\n};\n\nMainToolTip.propTypes = {\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes: PropTypes.shape({\n /**\n * Styles applied to the barchart root class.\n */\n root: PropTypes.string,\n }).isRequired,\n /**\n * Data of the tooltip.\n */\n data: PropTypes.shape({\n /**\n * Title.\n */\n title: PropTypes.string,\n /**\n * Values of the tooltip.\n */\n elements: PropTypes.arrayOf(\n PropTypes.shape({\n /**\n * Color of the bar.\n */\n color: PropTypes.string,\n /**\n * Name.\n */\n name: PropTypes.string,\n /**\n * Value.\n */\n value: PropTypes.number,\n })\n ),\n }).isRequired,\n /**\n * Coordinates.\n */\n coordinates: PropTypes.shape({\n /**\n * xx's coordinate.\n */\n x: PropTypes.number.isRequired,\n /**\n * yy's coordinate.\n */\n y: PropTypes.number.isRequired,\n }).isRequired,\n /**\n * Defines if should use a single or multiline tooltip.\n */\n useSingle: PropTypes.bool,\n /**\n * Custom tooltip element to be displayed\n */\n tooltip: PropTypes.func,\n};\n\nMainToolTip.defaultProps = {\n useSingle: false,\n};\n\nexport default withStyles(styles, { name: \"HvChartTooltip\" })(MainToolTip);\n"],"mappings":";AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,EAAmCC,QAAnC,EAA6CC,WAA7C,QAA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AACA;EACEvB,SAAS,EAAEV,SAAS,CAACsC,IAtDC;;EAuDtB;AACF;AACA;EACE3B,OAAO,EAAEX,SAAS,CAACuC;AA1DG,CAAxB;AA6DAjC,WAAW,CAACkC,YAAZ,GAA2B;EACzB9B,SAAS,EAAE;AADc,CAA3B;AAIA,eAAeT,UAAU,CAACG,MAAD,EAAS;EAAEgC,IAAI,EAAE;AAAR,CAAT,CAAV,CAA+C9B,WAA/C,CAAf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/uikit-react-viz",
|
|
3
|
-
"version": "4.0.1-next.
|
|
3
|
+
"version": "4.0.1-next.5",
|
|
4
4
|
"description": "A collection of React visualizations for the Hitachi Vantara's Design System.",
|
|
5
5
|
"homepage": "https://github.com/lumada-design/hv-uikit-react",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"react-dom": "^16.13.1 || ^17.0.2"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@hitachivantara/uikit-react-core": "^4.0.1-next.
|
|
48
|
+
"@hitachivantara/uikit-react-core": "^4.0.1-next.5",
|
|
49
49
|
"clsx": "^1.2.1",
|
|
50
50
|
"lodash": "^4.17.21",
|
|
51
51
|
"prop-types": "^15.8.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "fe888b15f863a60ee54f0ba4084568a3a44feed2"
|
|
67
67
|
}
|