@pie-lib/plot 3.1.0-next.2 → 3.1.0-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/CHANGELOG.md +8 -0
- package/lib/draggable.js +44 -0
- package/lib/draggable.js.map +1 -0
- package/lib/graph-props.js +46 -0
- package/lib/graph-props.js.map +1 -0
- package/lib/grid-draggable.js +307 -0
- package/lib/grid-draggable.js.map +1 -0
- package/lib/index.js +44 -0
- package/lib/index.js.map +1 -0
- package/lib/label.js +150 -0
- package/lib/label.js.map +1 -0
- package/lib/root.js +455 -0
- package/lib/root.js.map +1 -0
- package/lib/trig.js +149 -0
- package/lib/trig.js.map +1 -0
- package/lib/types.js +40 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.js +168 -0
- package/lib/utils.js.map +1 -0
- package/package.json +4 -4
package/lib/label.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
13
|
+
var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
var _utils = require("./utils");
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
var styles = {
|
|
20
|
+
axisLabel: {
|
|
21
|
+
fontSize: 12,
|
|
22
|
+
textAlign: 'center',
|
|
23
|
+
margin: 4,
|
|
24
|
+
padding: '4px 0'
|
|
25
|
+
},
|
|
26
|
+
chartLabel: {
|
|
27
|
+
fontSize: 16,
|
|
28
|
+
textAlign: 'center',
|
|
29
|
+
margin: 4,
|
|
30
|
+
padding: '4px 0'
|
|
31
|
+
},
|
|
32
|
+
disabledLabel: {
|
|
33
|
+
pointerEvents: 'none',
|
|
34
|
+
width: '100%'
|
|
35
|
+
},
|
|
36
|
+
editLabel: {
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
backgroundColor: 'white',
|
|
39
|
+
borderRadius: 4,
|
|
40
|
+
boxShadow: '0px 5px 8px rgba(0,0,0,0.15)',
|
|
41
|
+
zIndex: 10
|
|
42
|
+
},
|
|
43
|
+
rotateLeftLabel: {
|
|
44
|
+
transform: 'rotate(-90deg)',
|
|
45
|
+
transformOrigin: '0 0',
|
|
46
|
+
position: 'absolute'
|
|
47
|
+
},
|
|
48
|
+
rotateRightLabel: {
|
|
49
|
+
transform: 'rotate(90deg)',
|
|
50
|
+
transformOrigin: '0 0',
|
|
51
|
+
position: 'absolute'
|
|
52
|
+
},
|
|
53
|
+
customBottom: {
|
|
54
|
+
position: 'absolute'
|
|
55
|
+
},
|
|
56
|
+
displayNone: {
|
|
57
|
+
display: 'none'
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var LabelComponent = function LabelComponent(props) {
|
|
61
|
+
var disabledLabel = props.disabledLabel,
|
|
62
|
+
graphHeight = props.graphHeight,
|
|
63
|
+
graphWidth = props.graphWidth,
|
|
64
|
+
isChartBottomLabel = props.isChartBottomLabel,
|
|
65
|
+
isDefineChartBottomLabel = props.isDefineChartBottomLabel,
|
|
66
|
+
isChartLeftLabel = props.isChartLeftLabel,
|
|
67
|
+
isDefineChartLeftLabel = props.isDefineChartLeftLabel,
|
|
68
|
+
placeholder = props.placeholder,
|
|
69
|
+
text = props.text,
|
|
70
|
+
side = props.side,
|
|
71
|
+
onChange = props.onChange,
|
|
72
|
+
_props$mathMlOptions = props.mathMlOptions,
|
|
73
|
+
mathMlOptions = _props$mathMlOptions === void 0 ? {} : _props$mathMlOptions,
|
|
74
|
+
charactersLimit = props.charactersLimit,
|
|
75
|
+
titleHeight = props.titleHeight;
|
|
76
|
+
var _useState = (0, _react.useState)(false),
|
|
77
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
78
|
+
rotatedToHorizontal = _useState2[0],
|
|
79
|
+
setRotatedToHorizontal = _useState2[1];
|
|
80
|
+
var activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math'];
|
|
81
|
+
var isChart = isChartBottomLabel || isChartLeftLabel || isDefineChartBottomLabel || isDefineChartLeftLabel;
|
|
82
|
+
var chartValue = side === 'left' && isDefineChartLeftLabel && graphHeight - 220;
|
|
83
|
+
var defaultStyle = {
|
|
84
|
+
width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),
|
|
85
|
+
top: chartValue || isChartLeftLabel && "".concat(graphHeight - 70, "px") || side === 'left' && "".concat(graphHeight - 8, "px") || isChartBottomLabel && "".concat(graphHeight - 60 + titleHeight, "px") || side === 'bottom' && "".concat(graphHeight - 120 + titleHeight, "px") || 0,
|
|
86
|
+
left: side === 'right' && "".concat(graphWidth - 8, "px") || (isDefineChartLeftLabel || isDefineChartBottomLabel) && '40px' || isChartBottomLabel && '-10px' || 0
|
|
87
|
+
};
|
|
88
|
+
var rotatedStyle = {
|
|
89
|
+
width: graphWidth - 8,
|
|
90
|
+
top: side === 'right' ? "".concat(graphHeight - 22, "px") : 0,
|
|
91
|
+
left: 0
|
|
92
|
+
};
|
|
93
|
+
var rotateLabel = function rotateLabel() {
|
|
94
|
+
if (!disabledLabel && (side === 'left' || side === 'right')) {
|
|
95
|
+
setRotatedToHorizontal(true);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var exitEditMode = function exitEditMode() {
|
|
99
|
+
setRotatedToHorizontal(false);
|
|
100
|
+
|
|
101
|
+
// blur active element because rotation is causing editing issues on exit
|
|
102
|
+
requestAnimationFrame(function () {
|
|
103
|
+
var _document$activeEleme, _document$activeEleme2;
|
|
104
|
+
(_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 || (_document$activeEleme2 = _document$activeEleme.blur) === null || _document$activeEleme2 === void 0 || _document$activeEleme2.call(_document$activeEleme);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
108
|
+
"false": true
|
|
109
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
110
|
+
onClick: rotateLabel,
|
|
111
|
+
style: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, rotatedToHorizontal ? rotatedStyle : defaultStyle), isChart ? styles.chartLabel : styles.axisLabel), side === 'left' && !rotatedToHorizontal ? styles.rotateLeftLabel : {}), side === 'right' && !rotatedToHorizontal ? styles.rotateRightLabel : {}), rotatedToHorizontal ? styles.editLabel : {}), isChartBottomLabel || isDefineChartBottomLabel ? styles.customBottom : {}), disabledLabel && !isChart && (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(text)) && styles.displayNone)
|
|
112
|
+
}, disabledLabel ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
113
|
+
style: styles.disabledLabel,
|
|
114
|
+
dangerouslySetInnerHTML: {
|
|
115
|
+
__html: text || ''
|
|
116
|
+
}
|
|
117
|
+
}) : /*#__PURE__*/_react["default"].createElement(_editableHtmlTipTap["default"], {
|
|
118
|
+
markup: text || '',
|
|
119
|
+
onChange: onChange,
|
|
120
|
+
placeholder: !disabledLabel && placeholder,
|
|
121
|
+
toolbarOpts: {
|
|
122
|
+
position: side === 'bottom' ? 'top' : 'bottom',
|
|
123
|
+
noPadding: true,
|
|
124
|
+
noBorder: true
|
|
125
|
+
},
|
|
126
|
+
disableScrollbar: true,
|
|
127
|
+
activePlugins: activePlugins,
|
|
128
|
+
onDone: exitEditMode,
|
|
129
|
+
mathMlOptions: mathMlOptions,
|
|
130
|
+
charactersLimit: charactersLimit
|
|
131
|
+
})));
|
|
132
|
+
};
|
|
133
|
+
LabelComponent.propTypes = {
|
|
134
|
+
disabledLabel: _propTypes["default"].bool,
|
|
135
|
+
graphHeight: _propTypes["default"].number,
|
|
136
|
+
graphWidth: _propTypes["default"].number,
|
|
137
|
+
isChartBottomLabel: _propTypes["default"].bool,
|
|
138
|
+
isDefineChartBottomLabel: _propTypes["default"].bool,
|
|
139
|
+
isChartLeftLabel: _propTypes["default"].bool,
|
|
140
|
+
isDefineChartLeftLabel: _propTypes["default"].bool,
|
|
141
|
+
placeholder: _propTypes["default"].string,
|
|
142
|
+
text: _propTypes["default"].string,
|
|
143
|
+
side: _propTypes["default"].string,
|
|
144
|
+
onChange: _propTypes["default"].func,
|
|
145
|
+
mathMlOptions: _propTypes["default"].object,
|
|
146
|
+
charactersLimit: _propTypes["default"].number,
|
|
147
|
+
titleHeight: _propTypes["default"].number
|
|
148
|
+
};
|
|
149
|
+
var _default = exports["default"] = LabelComponent;
|
|
150
|
+
//# sourceMappingURL=label.js.map
|
package/lib/label.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.js","names":["_react","_interopRequireWildcard","require","_renderUi","_editableHtmlTipTap","_interopRequireDefault","_propTypes","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ownKeys","keys","getOwnPropertySymbols","filter","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","styles","axisLabel","fontSize","textAlign","margin","padding","chartLabel","disabledLabel","pointerEvents","width","editLabel","position","backgroundColor","borderRadius","boxShadow","zIndex","rotateLeftLabel","transform","transformOrigin","rotateRightLabel","customBottom","displayNone","display","LabelComponent","props","graphHeight","graphWidth","isChartBottomLabel","isDefineChartBottomLabel","isChartLeftLabel","isDefineChartLeftLabel","placeholder","text","side","onChange","_props$mathMlOptions","mathMlOptions","charactersLimit","titleHeight","_useState","useState","_useState2","_slicedToArray2","rotatedToHorizontal","setRotatedToHorizontal","activePlugins","isChart","chartValue","defaultStyle","top","concat","left","rotatedStyle","rotateLabel","exitEditMode","requestAnimationFrame","_document$activeEleme","_document$activeEleme2","document","activeElement","blur","createElement","Readable","onClick","style","isEmptyString","extractTextFromHTML","dangerouslySetInnerHTML","__html","markup","toolbarOpts","noPadding","noBorder","disableScrollbar","onDone","propTypes","PropTypes","bool","number","string","func","object","_default","exports"],"sources":["../src/label.jsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { Readable } from '@pie-lib/render-ui';\nimport EditableHtml from '@pie-lib/editable-html-tip-tap';\nimport PropTypes from 'prop-types';\nimport { extractTextFromHTML, isEmptyString } from './utils';\n\nconst styles = {\n axisLabel: {\n fontSize: 12,\n textAlign: 'center',\n margin: 4,\n padding: '4px 0',\n },\n chartLabel: {\n fontSize: 16,\n textAlign: 'center',\n margin: 4,\n padding: '4px 0',\n },\n disabledLabel: {\n pointerEvents: 'none',\n width: '100%',\n },\n editLabel: {\n position: 'absolute',\n backgroundColor: 'white',\n borderRadius: 4,\n boxShadow: '0px 5px 8px rgba(0,0,0,0.15)',\n zIndex: 10,\n },\n rotateLeftLabel: {\n transform: 'rotate(-90deg)',\n transformOrigin: '0 0',\n position: 'absolute',\n },\n rotateRightLabel: {\n transform: 'rotate(90deg)',\n transformOrigin: '0 0',\n position: 'absolute',\n },\n customBottom: {\n position: 'absolute',\n },\n displayNone: {\n display: 'none',\n },\n};\n\nconst LabelComponent = (props) => {\n const {\n disabledLabel,\n graphHeight,\n graphWidth,\n isChartBottomLabel,\n isDefineChartBottomLabel,\n isChartLeftLabel,\n isDefineChartLeftLabel,\n placeholder,\n text,\n side,\n onChange,\n mathMlOptions = {},\n charactersLimit,\n titleHeight,\n } = props;\n\n const [rotatedToHorizontal, setRotatedToHorizontal] = useState(false);\n\n const activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math'];\n\n const isChart = isChartBottomLabel || isChartLeftLabel || isDefineChartBottomLabel || isDefineChartLeftLabel;\n\n const chartValue = side === 'left' && isDefineChartLeftLabel && graphHeight - 220;\n\n const defaultStyle = {\n width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),\n top:\n chartValue ||\n (isChartLeftLabel && `${graphHeight - 70}px`) ||\n (side === 'left' && `${graphHeight - 8}px`) ||\n (isChartBottomLabel && `${graphHeight - 60 + titleHeight}px`) ||\n (side === 'bottom' && `${graphHeight - 120 + titleHeight}px`) ||\n 0,\n left:\n (side === 'right' && `${graphWidth - 8}px`) ||\n ((isDefineChartLeftLabel || isDefineChartBottomLabel) && '40px') ||\n (isChartBottomLabel && '-10px') ||\n 0,\n };\n\n const rotatedStyle = {\n width: graphWidth - 8,\n top: side === 'right' ? `${graphHeight - 22}px` : 0,\n left: 0,\n };\n\n const rotateLabel = () => {\n if (!disabledLabel && (side === 'left' || side === 'right')) {\n setRotatedToHorizontal(true);\n }\n };\n\n const exitEditMode = () => {\n setRotatedToHorizontal(false);\n\n // blur active element because rotation is causing editing issues on exit\n requestAnimationFrame(() => {\n document.activeElement?.blur?.();\n });\n };\n\n return (\n <Readable false>\n <div\n onClick={rotateLabel}\n style={{\n ...(rotatedToHorizontal ? rotatedStyle : defaultStyle),\n ...(isChart ? styles.chartLabel : styles.axisLabel),\n ...(side === 'left' && !rotatedToHorizontal ? styles.rotateLeftLabel : {}),\n ...(side === 'right' && !rotatedToHorizontal ? styles.rotateRightLabel : {}),\n ...(rotatedToHorizontal ? styles.editLabel : {}),\n ...(isChartBottomLabel || isDefineChartBottomLabel ? styles.customBottom : {}),\n ...(disabledLabel && !isChart && isEmptyString(extractTextFromHTML(text)) && styles.displayNone),\n }}\n >\n {disabledLabel ? (\n <div style={styles.disabledLabel} dangerouslySetInnerHTML={{ __html: text || '' }} />\n ) : (\n <EditableHtml\n markup={text || ''}\n onChange={onChange}\n placeholder={!disabledLabel && placeholder}\n toolbarOpts={{\n position: side === 'bottom' ? 'top' : 'bottom',\n noPadding: true,\n noBorder: true,\n }}\n disableScrollbar\n activePlugins={activePlugins}\n onDone={exitEditMode}\n mathMlOptions={mathMlOptions}\n charactersLimit={charactersLimit}\n />\n )}\n </div>\n </Readable>\n );\n};\n\nLabelComponent.propTypes = {\n disabledLabel: PropTypes.bool,\n graphHeight: PropTypes.number,\n graphWidth: PropTypes.number,\n isChartBottomLabel: PropTypes.bool,\n isDefineChartBottomLabel: PropTypes.bool,\n isChartLeftLabel: PropTypes.bool,\n isDefineChartLeftLabel: PropTypes.bool,\n placeholder: PropTypes.string,\n text: PropTypes.string,\n side: PropTypes.string,\n onChange: PropTypes.func,\n mathMlOptions: PropTypes.object,\n charactersLimit: PropTypes.number,\n titleHeight: PropTypes.number,\n};\n\nexport default LabelComponent;\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAA6D,SAAAD,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,wBAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAAAD,CAAA,GAAAW,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAnB,CAAA,EAAAc,EAAA,OAAAP,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAM,EAAA,EAAAP,CAAA,IAAAC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AACC,IAAI;EACxChD,gBAAgB,EAAE+C,qBAAS,CAACC,IAAI;EAChC/C,sBAAsB,EAAE8C,qBAAS,CAACC,IAAI;EACtC9C,WAAW,EAAE6C,qBAAS,CAACG,MAAM;EAC7B/C,IAAI,EAAE4C,qBAAS,CAACG,MAAM;EACtB9C,IAAI,EAAE2C,qBAAS,CAACG,MAAM;EACtB7C,QAAQ,EAAE0C,qBAAS,CAACI,IAAI;EACxB5C,aAAa,EAAEwC,qBAAS,CAACK,MAAM;EAC/B5C,eAAe,EAAEuC,qBAAS,CAACE,MAAM;EACjCxC,WAAW,EAAEsC,qBAAS,CAACE;AACzB,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,cAEa5D,cAAc","ignoreList":[]}
|
package/lib/root.js
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = exports.Root = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
12
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
|
16
|
+
var _styles = require("@mui/material/styles");
|
|
17
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
18
|
+
var _d3Selection = require("d3-selection");
|
|
19
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
20
|
+
var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
|
|
21
|
+
var _types = require("./types");
|
|
22
|
+
var _label = _interopRequireDefault(require("./label"));
|
|
23
|
+
var _utils = require("./utils");
|
|
24
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
25
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
26
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
27
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
29
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
30
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
31
|
+
var StyledRoot = (0, _styles.styled)('div')(function (_ref) {
|
|
32
|
+
var theme = _ref.theme;
|
|
33
|
+
return {
|
|
34
|
+
border: "solid 1px ".concat(_renderUi.color.primaryLight()),
|
|
35
|
+
color: _renderUi.color.defaults.TEXT,
|
|
36
|
+
backgroundColor: theme.palette.common.white,
|
|
37
|
+
touchAction: 'none',
|
|
38
|
+
position: 'relative',
|
|
39
|
+
boxSizing: 'unset' // to override the default border-box in IBX that breaks the component width layout
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
var Wrapper = (0, _styles.styled)('div')({
|
|
43
|
+
display: 'flex',
|
|
44
|
+
position: 'relative'
|
|
45
|
+
});
|
|
46
|
+
var DefineChartSvg = (0, _styles.styled)('svg')({
|
|
47
|
+
paddingLeft: '50px',
|
|
48
|
+
overflow: 'visible'
|
|
49
|
+
});
|
|
50
|
+
var ChartSvg = (0, _styles.styled)('svg')({
|
|
51
|
+
overflow: 'visible'
|
|
52
|
+
});
|
|
53
|
+
var GraphBox = (0, _styles.styled)('g')({
|
|
54
|
+
cursor: 'pointer',
|
|
55
|
+
userSelect: 'none'
|
|
56
|
+
});
|
|
57
|
+
var GraphTitle = (0, _styles.styled)('div')(function (_ref2) {
|
|
58
|
+
var theme = _ref2.theme;
|
|
59
|
+
return {
|
|
60
|
+
color: _renderUi.color.defaults.TEXT,
|
|
61
|
+
fontSize: theme.typography.fontSize + 2,
|
|
62
|
+
padding: "".concat(theme.spacing(1.5), " ").concat(theme.spacing(0.5), " 0"),
|
|
63
|
+
textAlign: 'center',
|
|
64
|
+
'&.disabled': {
|
|
65
|
+
pointerEvents: 'none'
|
|
66
|
+
},
|
|
67
|
+
'&.rightMargin': {
|
|
68
|
+
marginRight: '74px'
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
var ChartTitle = (0, _styles.styled)('div')(function (_ref3) {
|
|
73
|
+
var theme = _ref3.theme;
|
|
74
|
+
return {
|
|
75
|
+
color: _renderUi.color.defaults.TEXT,
|
|
76
|
+
fontSize: theme.typography.fontSize + 4,
|
|
77
|
+
padding: "".concat(theme.spacing(1.5), " ").concat(theme.spacing(0.5), " 0"),
|
|
78
|
+
textAlign: 'center',
|
|
79
|
+
'&.disabled': {
|
|
80
|
+
pointerEvents: 'none'
|
|
81
|
+
},
|
|
82
|
+
'&.rightMargin': {
|
|
83
|
+
marginRight: '74px'
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
var TopPixelGuides = (0, _styles.styled)('div')({
|
|
88
|
+
display: 'flex',
|
|
89
|
+
paddingTop: '6px'
|
|
90
|
+
});
|
|
91
|
+
var TopPixelIndicator = (0, _styles.styled)('div')({
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flexDirection: 'column',
|
|
94
|
+
alignItems: 'center',
|
|
95
|
+
width: '100px',
|
|
96
|
+
pointerEvents: 'none',
|
|
97
|
+
userSelect: 'none'
|
|
98
|
+
});
|
|
99
|
+
var SidePixelGuides = (0, _styles.styled)('div')({
|
|
100
|
+
width: '70px',
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flexDirection: 'column',
|
|
103
|
+
marginRight: '6px'
|
|
104
|
+
});
|
|
105
|
+
var SidePixelIndicator = (0, _styles.styled)('div')({
|
|
106
|
+
textAlign: 'right',
|
|
107
|
+
height: '20px',
|
|
108
|
+
pointerEvents: 'none',
|
|
109
|
+
userSelect: 'none',
|
|
110
|
+
'&:not(:last-child)': {
|
|
111
|
+
marginBottom: '80px'
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
var Root = exports.Root = /*#__PURE__*/function (_React$Component) {
|
|
115
|
+
function Root(props) {
|
|
116
|
+
var _this;
|
|
117
|
+
(0, _classCallCheck2["default"])(this, Root);
|
|
118
|
+
_this = _callSuper(this, Root, [props]);
|
|
119
|
+
(0, _defineProperty2["default"])(_this, "mouseMove", function (g) {
|
|
120
|
+
var _this$props = _this.props,
|
|
121
|
+
graphProps = _this$props.graphProps,
|
|
122
|
+
onMouseMove = _this$props.onMouseMove;
|
|
123
|
+
if (!onMouseMove) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
var scale = graphProps.scale,
|
|
127
|
+
snap = graphProps.snap;
|
|
128
|
+
var coords = (0, _d3Selection.mouse)(g.node());
|
|
129
|
+
var x = scale.x.invert(coords[0]);
|
|
130
|
+
var y = scale.y.invert(coords[1]);
|
|
131
|
+
var snapped = {
|
|
132
|
+
x: snap.x(x),
|
|
133
|
+
y: snap.y(y)
|
|
134
|
+
};
|
|
135
|
+
onMouseMove(snapped);
|
|
136
|
+
});
|
|
137
|
+
(0, _defineProperty2["default"])(_this, "onChangeLabel", function (newValue, side) {
|
|
138
|
+
var _this$props2 = _this.props,
|
|
139
|
+
labels = _this$props2.labels,
|
|
140
|
+
onChangeLabels = _this$props2.onChangeLabels,
|
|
141
|
+
isChart = _this$props2.isChart;
|
|
142
|
+
if (!onChangeLabels) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (isChart) {
|
|
146
|
+
if (side === 'left') {
|
|
147
|
+
onChangeLabels('range', newValue);
|
|
148
|
+
} else {
|
|
149
|
+
onChangeLabels('domain', newValue);
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
onChangeLabels(_objectSpread(_objectSpread({}, labels), {}, (0, _defineProperty2["default"])({}, side, newValue)));
|
|
154
|
+
});
|
|
155
|
+
(0, _defineProperty2["default"])(_this, "measureTitleHeight", function () {
|
|
156
|
+
var titleElement = _this.titleRef;
|
|
157
|
+
if (titleElement) {
|
|
158
|
+
var titleHeight = titleElement.clientHeight;
|
|
159
|
+
_this.setState({
|
|
160
|
+
titleHeight: titleHeight,
|
|
161
|
+
prevTitle: _this.props.title
|
|
162
|
+
});
|
|
163
|
+
if (!_this.resizeObserver && typeof ResizeObserver !== 'undefined') {
|
|
164
|
+
_this.setupVisibilityObserver();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
(0, _defineProperty2["default"])(_this, "handleKeyDown", function () {
|
|
169
|
+
setTimeout(function () {
|
|
170
|
+
_this.measureTitleHeight();
|
|
171
|
+
}, 0);
|
|
172
|
+
});
|
|
173
|
+
// handle edge case where chart is hidden with display:none and then shown with display:block
|
|
174
|
+
(0, _defineProperty2["default"])(_this, "setupVisibilityObserver", function () {
|
|
175
|
+
if (typeof ResizeObserver !== 'undefined' && _this.titleRef) {
|
|
176
|
+
_this.resizeObserver = new ResizeObserver(function (entries) {
|
|
177
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
178
|
+
_step;
|
|
179
|
+
try {
|
|
180
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
181
|
+
var entry = _step.value;
|
|
182
|
+
var _entry$contentRect = entry.contentRect,
|
|
183
|
+
width = _entry$contentRect.width,
|
|
184
|
+
height = _entry$contentRect.height;
|
|
185
|
+
// trigger if element becomes visible and we haven't measured this height yet
|
|
186
|
+
if (width > 0 && height > 0) {
|
|
187
|
+
setTimeout(function () {
|
|
188
|
+
_this.measureTitleHeight();
|
|
189
|
+
}, 10);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch (err) {
|
|
194
|
+
_iterator.e(err);
|
|
195
|
+
} finally {
|
|
196
|
+
_iterator.f();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
_this.resizeObserver.observe(_this.titleRef);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
(0, _defineProperty2["default"])(_this, "cleanupVisibilityObserver", function () {
|
|
203
|
+
if (_this.resizeObserver) {
|
|
204
|
+
_this.resizeObserver.disconnect();
|
|
205
|
+
_this.resizeObserver = null;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
_this.state = {
|
|
209
|
+
titleHeight: 0
|
|
210
|
+
};
|
|
211
|
+
_this.resizeObserver = null;
|
|
212
|
+
return _this;
|
|
213
|
+
}
|
|
214
|
+
(0, _inherits2["default"])(Root, _React$Component);
|
|
215
|
+
return (0, _createClass2["default"])(Root, [{
|
|
216
|
+
key: "componentDidMount",
|
|
217
|
+
value: function componentDidMount() {
|
|
218
|
+
var g = (0, _d3Selection.select)(this.g);
|
|
219
|
+
g.on('mousemove', this.mouseMove.bind(this, g));
|
|
220
|
+
this.measureTitleHeight();
|
|
221
|
+
this.setupVisibilityObserver();
|
|
222
|
+
}
|
|
223
|
+
}, {
|
|
224
|
+
key: "componentWillUnmount",
|
|
225
|
+
value: function componentWillUnmount() {
|
|
226
|
+
var g = (0, _d3Selection.select)(this.g);
|
|
227
|
+
g.on('mousemove', null);
|
|
228
|
+
this.cleanupVisibilityObserver();
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
key: "componentDidUpdate",
|
|
232
|
+
value: function componentDidUpdate(prevProps) {
|
|
233
|
+
if (prevProps.title !== this.props.title) {
|
|
234
|
+
this.measureTitleHeight();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}, {
|
|
238
|
+
key: "render",
|
|
239
|
+
value: function render() {
|
|
240
|
+
var _this2 = this;
|
|
241
|
+
var _this$props3 = this.props,
|
|
242
|
+
disabledTitle = _this$props3.disabledTitle,
|
|
243
|
+
disabledLabels = _this$props3.disabledLabels,
|
|
244
|
+
labels = _this$props3.labels,
|
|
245
|
+
labelsPlaceholders = _this$props3.labelsPlaceholders,
|
|
246
|
+
titlePlaceholder = _this$props3.titlePlaceholder,
|
|
247
|
+
graphProps = _this$props3.graphProps,
|
|
248
|
+
children = _this$props3.children,
|
|
249
|
+
defineChart = _this$props3.defineChart,
|
|
250
|
+
onChangeTitle = _this$props3.onChangeTitle,
|
|
251
|
+
isChart = _this$props3.isChart,
|
|
252
|
+
showLabels = _this$props3.showLabels,
|
|
253
|
+
showPixelGuides = _this$props3.showPixelGuides,
|
|
254
|
+
showTitle = _this$props3.showTitle,
|
|
255
|
+
title = _this$props3.title,
|
|
256
|
+
rootRef = _this$props3.rootRef,
|
|
257
|
+
_this$props3$mathMlOp = _this$props3.mathMlOptions,
|
|
258
|
+
mathMlOptions = _this$props3$mathMlOp === void 0 ? {} : _this$props3$mathMlOp,
|
|
259
|
+
labelsCharactersLimit = _this$props3.labelsCharactersLimit;
|
|
260
|
+
var _graphProps$size = graphProps.size,
|
|
261
|
+
_graphProps$size$widt = _graphProps$size.width,
|
|
262
|
+
width = _graphProps$size$widt === void 0 ? 500 : _graphProps$size$widt,
|
|
263
|
+
_graphProps$size$heig = _graphProps$size.height,
|
|
264
|
+
height = _graphProps$size$heig === void 0 ? 500 : _graphProps$size$heig,
|
|
265
|
+
domain = graphProps.domain,
|
|
266
|
+
range = graphProps.range;
|
|
267
|
+
var topPadding = 40;
|
|
268
|
+
var leftPadding = (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(labels === null || labels === void 0 ? void 0 : labels.left)) && (0, _utils.isEmptyObject)(labelsPlaceholders) ? 48 : 70;
|
|
269
|
+
var rightPadding = (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(labels === null || labels === void 0 ? void 0 : labels.right)) && (0, _utils.isEmptyObject)(labelsPlaceholders) ? 48 : 70;
|
|
270
|
+
var finalWidth = width + leftPadding + rightPadding + (domain.padding || 0) * 2;
|
|
271
|
+
var finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
|
|
272
|
+
var activeTitlePlugins = ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'math'
|
|
273
|
+
// 'languageCharacters'
|
|
274
|
+
];
|
|
275
|
+
var actualHeight = defineChart && showPixelGuides ? height - 160 : height;
|
|
276
|
+
var nbOfVerticalLines = parseInt(width / 100);
|
|
277
|
+
var nbOfHorizontalLines = parseInt(actualHeight / 100);
|
|
278
|
+
var sideGridlinesPadding = parseInt(actualHeight % 100);
|
|
279
|
+
var titleHeight = this.state.titleHeight;
|
|
280
|
+
return /*#__PURE__*/_react["default"].createElement(StyledRoot, null, showPixelGuides && /*#__PURE__*/_react["default"].createElement(TopPixelGuides, {
|
|
281
|
+
style: {
|
|
282
|
+
marginLeft: isChart ? 80 : showLabels ? 30 : 10
|
|
283
|
+
}
|
|
284
|
+
}, (0, _toConsumableArray2["default"])(Array(nbOfVerticalLines + 1).keys()).map(function (value) {
|
|
285
|
+
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
286
|
+
"false": true,
|
|
287
|
+
key: "top-guide-".concat(value)
|
|
288
|
+
}, /*#__PURE__*/_react["default"].createElement(TopPixelIndicator, null, /*#__PURE__*/_react["default"].createElement("div", null, value * 100, "px"), /*#__PURE__*/_react["default"].createElement("div", null, "|")));
|
|
289
|
+
})), showTitle && (disabledTitle ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
290
|
+
ref: function ref(r) {
|
|
291
|
+
return _this2.titleRef = r;
|
|
292
|
+
},
|
|
293
|
+
style: _objectSpread(_objectSpread({}, isChart && {
|
|
294
|
+
width: finalWidth
|
|
295
|
+
}), (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(title)) && {
|
|
296
|
+
display: 'none'
|
|
297
|
+
})
|
|
298
|
+
}, isChart ? /*#__PURE__*/_react["default"].createElement(ChartTitle, {
|
|
299
|
+
className: "disabled",
|
|
300
|
+
dangerouslySetInnerHTML: {
|
|
301
|
+
__html: title || ''
|
|
302
|
+
}
|
|
303
|
+
}) : /*#__PURE__*/_react["default"].createElement(GraphTitle, {
|
|
304
|
+
className: "disabled",
|
|
305
|
+
dangerouslySetInnerHTML: {
|
|
306
|
+
__html: title || ''
|
|
307
|
+
}
|
|
308
|
+
})) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
309
|
+
ref: function ref(r) {
|
|
310
|
+
return _this2.titleRef = r;
|
|
311
|
+
}
|
|
312
|
+
}, isChart ? /*#__PURE__*/_react["default"].createElement(ChartTitle, {
|
|
313
|
+
className: showPixelGuides ? 'rightMargin' : ''
|
|
314
|
+
}, /*#__PURE__*/_react["default"].createElement(_editableHtmlTipTap["default"], {
|
|
315
|
+
style: isChart && {
|
|
316
|
+
width: finalWidth
|
|
317
|
+
},
|
|
318
|
+
markup: title || '',
|
|
319
|
+
onChange: onChangeTitle,
|
|
320
|
+
placeholder: defineChart && titlePlaceholder || !disabledTitle && 'Click here to add a title for this graph',
|
|
321
|
+
toolbarOpts: {
|
|
322
|
+
noPadding: true,
|
|
323
|
+
noBorder: true
|
|
324
|
+
},
|
|
325
|
+
activePlugins: activeTitlePlugins,
|
|
326
|
+
disableScrollbar: true,
|
|
327
|
+
onKeyDown: this.handleKeyDown
|
|
328
|
+
})) : /*#__PURE__*/_react["default"].createElement(GraphTitle, {
|
|
329
|
+
className: showPixelGuides ? 'rightMargin' : ''
|
|
330
|
+
}, /*#__PURE__*/_react["default"].createElement(_editableHtmlTipTap["default"], {
|
|
331
|
+
style: isChart && {
|
|
332
|
+
width: finalWidth
|
|
333
|
+
},
|
|
334
|
+
markup: title || '',
|
|
335
|
+
onChange: onChangeTitle,
|
|
336
|
+
placeholder: defineChart && titlePlaceholder || !disabledTitle && 'Click here to add a title for this graph',
|
|
337
|
+
toolbarOpts: {
|
|
338
|
+
noPadding: true,
|
|
339
|
+
noBorder: true
|
|
340
|
+
},
|
|
341
|
+
activePlugins: activeTitlePlugins,
|
|
342
|
+
disableScrollbar: true,
|
|
343
|
+
onKeyDown: this.handleKeyDown
|
|
344
|
+
})))), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
345
|
+
side: "top",
|
|
346
|
+
text: labels.top,
|
|
347
|
+
disabledLabel: disabledLabels,
|
|
348
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.top,
|
|
349
|
+
graphHeight: finalHeight,
|
|
350
|
+
graphWidth: finalWidth,
|
|
351
|
+
onChange: function onChange(value) {
|
|
352
|
+
return _this2.onChangeLabel(value, 'top');
|
|
353
|
+
},
|
|
354
|
+
mathMlOptions: mathMlOptions,
|
|
355
|
+
charactersLimit: labelsCharactersLimit
|
|
356
|
+
}), /*#__PURE__*/_react["default"].createElement(Wrapper, null, showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
357
|
+
side: "left",
|
|
358
|
+
text: labels.left,
|
|
359
|
+
disabledLabel: disabledLabels,
|
|
360
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.left,
|
|
361
|
+
graphHeight: finalHeight,
|
|
362
|
+
graphWidth: finalWidth,
|
|
363
|
+
isChartLeftLabel: isChart && !defineChart,
|
|
364
|
+
isDefineChartLeftLabel: isChart && defineChart,
|
|
365
|
+
onChange: function onChange(value) {
|
|
366
|
+
return _this2.onChangeLabel(value, 'left');
|
|
367
|
+
},
|
|
368
|
+
mathMlOptions: mathMlOptions,
|
|
369
|
+
charactersLimit: labelsCharactersLimit
|
|
370
|
+
}), defineChart ? /*#__PURE__*/_react["default"].createElement(DefineChartSvg, {
|
|
371
|
+
width: finalWidth,
|
|
372
|
+
height: finalHeight
|
|
373
|
+
}, /*#__PURE__*/_react["default"].createElement(GraphBox, {
|
|
374
|
+
ref: function ref(r) {
|
|
375
|
+
_this2.g = r;
|
|
376
|
+
if (rootRef) {
|
|
377
|
+
rootRef(r);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
transform: "translate(".concat(leftPadding + (domain.padding || 0), ", ").concat(topPadding + (range.padding || 0), ")")
|
|
381
|
+
}, children)) : /*#__PURE__*/_react["default"].createElement(ChartSvg, {
|
|
382
|
+
width: finalWidth,
|
|
383
|
+
height: finalHeight
|
|
384
|
+
}, /*#__PURE__*/_react["default"].createElement(GraphBox, {
|
|
385
|
+
ref: function ref(r) {
|
|
386
|
+
_this2.g = r;
|
|
387
|
+
if (rootRef) {
|
|
388
|
+
rootRef(r);
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
transform: "translate(".concat(leftPadding + (domain.padding || 0), ", ").concat(topPadding + (range.padding || 0), ")")
|
|
392
|
+
}, children)), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
393
|
+
side: "right",
|
|
394
|
+
text: labels.right,
|
|
395
|
+
disabledLabel: disabledLabels,
|
|
396
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.right,
|
|
397
|
+
graphHeight: finalHeight,
|
|
398
|
+
graphWidth: finalWidth,
|
|
399
|
+
onChange: function onChange(value) {
|
|
400
|
+
return _this2.onChangeLabel(value, 'right');
|
|
401
|
+
},
|
|
402
|
+
mathMlOptions: mathMlOptions,
|
|
403
|
+
charactersLimit: labelsCharactersLimit
|
|
404
|
+
}), showPixelGuides && /*#__PURE__*/_react["default"].createElement(SidePixelGuides, {
|
|
405
|
+
style: {
|
|
406
|
+
paddingTop: sideGridlinesPadding,
|
|
407
|
+
marginTop: 31
|
|
408
|
+
}
|
|
409
|
+
}, (0, _toConsumableArray2["default"])(Array(nbOfHorizontalLines + 1).keys()).reverse().map(function (value) {
|
|
410
|
+
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
411
|
+
"false": true,
|
|
412
|
+
key: "top-guide-".concat(value)
|
|
413
|
+
}, /*#__PURE__*/_react["default"].createElement(SidePixelIndicator, null, "\u2501 ", value * 100, "px"));
|
|
414
|
+
}))), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
415
|
+
side: "bottom",
|
|
416
|
+
text: labels.bottom,
|
|
417
|
+
disabledLabel: disabledLabels,
|
|
418
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.bottom,
|
|
419
|
+
graphHeight: finalHeight,
|
|
420
|
+
graphWidth: finalWidth,
|
|
421
|
+
titleHeight: titleHeight,
|
|
422
|
+
isChartBottomLabel: isChart && !defineChart,
|
|
423
|
+
isDefineChartBottomLabel: isChart && defineChart,
|
|
424
|
+
onChange: function onChange(value) {
|
|
425
|
+
return _this2.onChangeLabel(value, 'bottom');
|
|
426
|
+
},
|
|
427
|
+
mathMlOptions: mathMlOptions,
|
|
428
|
+
charactersLimit: labelsCharactersLimit
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
}]);
|
|
432
|
+
}(_react["default"].Component);
|
|
433
|
+
(0, _defineProperty2["default"])(Root, "propTypes", {
|
|
434
|
+
title: _propTypes["default"].string,
|
|
435
|
+
children: _types.ChildrenType,
|
|
436
|
+
defineChart: _propTypes["default"].bool,
|
|
437
|
+
disabledLabels: _propTypes["default"].bool,
|
|
438
|
+
disabledTitle: _propTypes["default"].bool,
|
|
439
|
+
graphProps: _types.GraphPropsType.isRequired,
|
|
440
|
+
isChart: _propTypes["default"].bool,
|
|
441
|
+
labels: _propTypes["default"].object,
|
|
442
|
+
labelsPlaceholders: _propTypes["default"].object,
|
|
443
|
+
onChangeTitle: _propTypes["default"].func,
|
|
444
|
+
onMouseMove: _propTypes["default"].func,
|
|
445
|
+
showLabels: _propTypes["default"].bool,
|
|
446
|
+
showTitle: _propTypes["default"].bool,
|
|
447
|
+
showPixelGuides: _propTypes["default"].bool,
|
|
448
|
+
rootRef: _propTypes["default"].func,
|
|
449
|
+
onChangeLabels: _propTypes["default"].func,
|
|
450
|
+
titlePlaceholder: _propTypes["default"].string,
|
|
451
|
+
mathMlOptions: _propTypes["default"].object,
|
|
452
|
+
labelsCharactersLimit: _propTypes["default"].number
|
|
453
|
+
});
|
|
454
|
+
var _default = exports["default"] = Root;
|
|
455
|
+
//# sourceMappingURL=root.js.map
|