@pie-lib/plot 2.1.10-next.605 → 2.1.10-next.657

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/lib/label.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ var _renderUi = require("@pie-lib/render-ui");
19
+
20
+ var _classnames = _interopRequireDefault(require("classnames"));
21
+
22
+ var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
23
+
24
+ var _styles = require("@material-ui/core/styles");
25
+
26
+ 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); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
30
+ var LabelComponent = function LabelComponent(props) {
31
+ var _cn;
32
+
33
+ var classes = props.classes,
34
+ disabledLabel = props.disabledLabel,
35
+ graphHeight = props.graphHeight,
36
+ graphWidth = props.graphWidth,
37
+ isChartBottomLabel = props.isChartBottomLabel,
38
+ isChartLeftLabel = props.isChartLeftLabel,
39
+ placeholder = props.placeholder,
40
+ text = props.text,
41
+ side = props.side,
42
+ onChange = props.onChange;
43
+
44
+ var _useState = (0, _react.useState)(false),
45
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
46
+ rotatedToHorizontal = _useState2[0],
47
+ setRotatedToHorizontal = _useState2[1];
48
+
49
+ var activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math' // 'languageCharacters'
50
+ ];
51
+ var chartValue = side === 'left' && isChartLeftLabel && graphHeight - 148;
52
+ var defaultStyle = {
53
+ width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),
54
+ top: chartValue || side === 'left' && "".concat(graphHeight - 8, "px") || side === 'bottom' && "".concat(graphHeight - 90, "px") || 0,
55
+ left: side === 'right' && "".concat(graphWidth - 8, "px") || (isChartLeftLabel || isChartBottomLabel) && '50px' || 0
56
+ };
57
+ var rotatedStyle = {
58
+ width: graphWidth - 8,
59
+ top: side === 'right' && "".concat(graphHeight - 22, "px") || 0,
60
+ left: 0
61
+ };
62
+
63
+ var rotateLabel = function rotateLabel() {
64
+ return !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);
65
+ };
66
+
67
+ return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
68
+ "false": true
69
+ }, /*#__PURE__*/_react["default"].createElement("div", {
70
+ className: (0, _classnames["default"])(classes.axisLabel, (_cn = {}, (0, _defineProperty2["default"])(_cn, classes.rotateLeftLabel, side === 'left' && !rotatedToHorizontal), (0, _defineProperty2["default"])(_cn, classes.rotateRightLabel, side === 'right' && !rotatedToHorizontal), (0, _defineProperty2["default"])(_cn, classes.editLabel, rotatedToHorizontal), (0, _defineProperty2["default"])(_cn, classes.customBottom, isChartBottomLabel), _cn)),
71
+ style: rotatedToHorizontal ? rotatedStyle : defaultStyle,
72
+ onClick: rotateLabel
73
+ }, disabledLabel ? /*#__PURE__*/_react["default"].createElement("div", {
74
+ className: classes.disabledLabel,
75
+ dangerouslySetInnerHTML: {
76
+ __html: text || ''
77
+ }
78
+ }) : /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
79
+ markup: text || '',
80
+ onChange: onChange,
81
+ placeholder: !disabledLabel && placeholder,
82
+ toolbarOpts: {
83
+ position: side === 'bottom' ? 'top' : 'bottom',
84
+ noBorder: true
85
+ },
86
+ activePlugins: activePlugins,
87
+ onDone: function onDone() {
88
+ return setRotatedToHorizontal(false);
89
+ }
90
+ })));
91
+ };
92
+
93
+ var _default = (0, _styles.withStyles)(function (theme) {
94
+ return {
95
+ label: {
96
+ fill: _renderUi.color.secondary()
97
+ },
98
+ axisLabel: {
99
+ fontSize: theme.typography.fontSize - 2,
100
+ textAlign: 'center',
101
+ margin: '4px',
102
+ padding: '4px 0'
103
+ },
104
+ disabledLabel: {
105
+ pointerEvents: 'none',
106
+ width: '100%'
107
+ },
108
+ editLabel: {
109
+ position: 'absolute',
110
+ backgroundColor: 'white',
111
+ borderRadius: '4px',
112
+ boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',
113
+ zIndex: 10
114
+ },
115
+ rotateLeftLabel: {
116
+ rotate: '-90deg',
117
+ transformOrigin: '0 0',
118
+ transformStyle: 'preserve-3d',
119
+ position: 'absolute'
120
+ },
121
+ rotateRightLabel: {
122
+ rotate: '90deg',
123
+ transformOrigin: '0 0',
124
+ transformStyle: 'preserve-3d',
125
+ position: 'absolute'
126
+ },
127
+ customBottom: {
128
+ position: 'absolute'
129
+ }
130
+ };
131
+ })(LabelComponent);
132
+
133
+ exports["default"] = _default;
134
+ //# sourceMappingURL=label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.js","names":["LabelComponent","props","classes","disabledLabel","graphHeight","graphWidth","isChartBottomLabel","isChartLeftLabel","placeholder","text","side","onChange","useState","rotatedToHorizontal","setRotatedToHorizontal","activePlugins","chartValue","defaultStyle","width","top","left","rotatedStyle","rotateLabel","cn","axisLabel","rotateLeftLabel","rotateRightLabel","editLabel","customBottom","__html","position","noBorder","withStyles","theme","label","fill","color","secondary","fontSize","typography","textAlign","margin","padding","pointerEvents","backgroundColor","borderRadius","boxShadow","zIndex","rotate","transformOrigin","transformStyle"],"sources":["../src/label.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { color, Readable } from '@pie-lib/render-ui';\nimport cn from 'classnames';\nimport EditableHtml from '@pie-lib/editable-html';\nimport { withStyles } from '@material-ui/core/styles';\n\nconst LabelComponent = props => {\n const {\n classes,\n disabledLabel,\n graphHeight,\n graphWidth,\n isChartBottomLabel,\n isChartLeftLabel,\n placeholder,\n text,\n side,\n onChange\n } = props;\n const [rotatedToHorizontal, setRotatedToHorizontal] = useState(false);\n const activePlugins = [\n 'bold',\n 'italic',\n 'underline',\n 'strikethrough',\n 'math'\n // 'languageCharacters'\n ];\n\n const chartValue = side === 'left' && isChartLeftLabel && graphHeight - 148;\n const defaultStyle = {\n width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),\n top:\n chartValue ||\n (side === 'left' && `${graphHeight - 8}px`) ||\n (side === 'bottom' && `${graphHeight - 90}px`) ||\n 0,\n left:\n (side === 'right' && `${graphWidth - 8}px`) ||\n ((isChartLeftLabel || isChartBottomLabel) && '50px') ||\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 !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);\n\n return (\n <Readable false>\n <div\n className={cn(classes.axisLabel, {\n [classes.rotateLeftLabel]: side === 'left' && !rotatedToHorizontal,\n [classes.rotateRightLabel]: side === 'right' && !rotatedToHorizontal,\n [classes.editLabel]: rotatedToHorizontal,\n [classes.customBottom]: isChartBottomLabel\n })}\n style={rotatedToHorizontal ? rotatedStyle : defaultStyle}\n onClick={rotateLabel}\n >\n {disabledLabel ? (\n <div className={classes.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 noBorder: true\n }}\n activePlugins={activePlugins}\n onDone={() => setRotatedToHorizontal(false)}\n />\n )}\n </div>\n </Readable>\n );\n};\n\nexport default withStyles(theme => ({\n label: {\n fill: color.secondary()\n },\n axisLabel: {\n fontSize: theme.typography.fontSize - 2,\n textAlign: 'center',\n margin: '4px',\n padding: '4px 0'\n },\n disabledLabel: {\n pointerEvents: 'none',\n width: '100%'\n },\n editLabel: {\n position: 'absolute',\n backgroundColor: 'white',\n borderRadius: '4px',\n boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',\n zIndex: 10\n },\n rotateLeftLabel: {\n rotate: '-90deg',\n transformOrigin: '0 0',\n transformStyle: 'preserve-3d',\n position: 'absolute'\n },\n rotateRightLabel: {\n rotate: '90deg',\n transformOrigin: '0 0',\n transformStyle: 'preserve-3d',\n position: 'absolute'\n },\n customBottom: {\n position: 'absolute'\n }\n}))(LabelComponent);\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,KAAK,EAAI;EAAA;;EAC9B,IACEC,OADF,GAWID,KAXJ,CACEC,OADF;EAAA,IAEEC,aAFF,GAWIF,KAXJ,CAEEE,aAFF;EAAA,IAGEC,WAHF,GAWIH,KAXJ,CAGEG,WAHF;EAAA,IAIEC,UAJF,GAWIJ,KAXJ,CAIEI,UAJF;EA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c,QAAQ,EAAEL,KAAK,CAACM,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;MAETE,SAAS,EAAE,QAFF;MAGTC,MAAM,EAAE,KAHC;MAITC,OAAO,EAAE;IAJA,CAJuB;IAUlCvC,aAAa,EAAE;MACbwC,aAAa,EAAE,MADF;MAEbzB,KAAK,EAAE;IAFM,CAVmB;IAclCS,SAAS,EAAE;MACTG,QAAQ,EAAE,UADD;MAETc,eAAe,EAAE,OAFR;MAGTC,YAAY,EAAE,KAHL;MAITC,SAAS,EAAE,iCAJF;MAKTC,MAAM,EAAE;IALC,CAduB;IAqBlCtB,eAAe,EAAE;MACfuB,MAAM,EAAE,QADO;MAEfC,eAAe,EAAE,KAFF;MAGfC,cAAc,EAAE,aAHD;MAIfpB,QAAQ,EAAE;IAJK,CArBiB;IA2BlCJ,gBAAgB,EAAE;MAChBsB,MAAM,EAAE,OADQ;MAEhBC,eAAe,EAAE,KAFD;MAGhBC,cAAc,EAAE,aAHA;MAIhBpB,QAAQ,EAAE;IAJM,CA3BgB;IAiClCF,YAAY,EAAE;MACZE,QAAQ,EAAE;IADE;EAjCoB,CAAL;AAAA,CAAhB,EAoCX9B,cApCW,C"}
package/lib/root.js CHANGED
@@ -39,6 +39,12 @@ var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
39
39
 
40
40
  var _classnames = _interopRequireDefault(require("classnames"));
41
41
 
42
+ var _label = _interopRequireDefault(require("./label"));
43
+
44
+ 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; }
45
+
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
47
+
42
48
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
43
49
 
44
50
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -78,6 +84,24 @@ var Root = /*#__PURE__*/function (_React$Component) {
78
84
  };
79
85
  onMouseMove(snapped);
80
86
  });
87
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChangeLabel", function (newValue, side) {
88
+ var _this$props2 = _this.props,
89
+ labels = _this$props2.labels,
90
+ onChangeLabels = _this$props2.onChangeLabels,
91
+ isChart = _this$props2.isChart;
92
+
93
+ if (isChart) {
94
+ if (side === 'left') {
95
+ onChangeLabels('range', newValue);
96
+ } else {
97
+ onChangeLabels('domain', newValue);
98
+ }
99
+
100
+ return;
101
+ }
102
+
103
+ onChangeLabels(_objectSpread(_objectSpread({}, labels), {}, (0, _defineProperty2["default"])({}, side, newValue)));
104
+ });
81
105
  return _this;
82
106
  }
83
107
 
@@ -98,18 +122,23 @@ var Root = /*#__PURE__*/function (_React$Component) {
98
122
  value: function render() {
99
123
  var _this2 = this;
100
124
 
101
- var _this$props2 = this.props,
102
- disabledTitle = _this$props2.disabledTitle,
103
- graphProps = _this$props2.graphProps,
104
- children = _this$props2.children,
105
- classes = _this$props2.classes,
106
- onChangeTitle = _this$props2.onChangeTitle,
107
- thisIsChart = _this$props2.thisIsChart,
108
- showLabels = _this$props2.showLabels,
109
- showPixelGuides = _this$props2.showPixelGuides,
110
- showTitle = _this$props2.showTitle,
111
- title = _this$props2.title,
112
- rootRef = _this$props2.rootRef;
125
+ var _this$props3 = this.props,
126
+ disabledTitle = _this$props3.disabledTitle,
127
+ disabledLabels = _this$props3.disabledLabels,
128
+ labels = _this$props3.labels,
129
+ labelsPlaceholders = _this$props3.labelsPlaceholders,
130
+ titlePlaceholder = _this$props3.titlePlaceholder,
131
+ graphProps = _this$props3.graphProps,
132
+ children = _this$props3.children,
133
+ classes = _this$props3.classes,
134
+ defineChart = _this$props3.defineChart,
135
+ onChangeTitle = _this$props3.onChangeTitle,
136
+ isChart = _this$props3.isChart,
137
+ showLabels = _this$props3.showLabels,
138
+ showPixelGuides = _this$props3.showPixelGuides,
139
+ showTitle = _this$props3.showTitle,
140
+ title = _this$props3.title,
141
+ rootRef = _this$props3.rootRef;
113
142
  var _graphProps$size = graphProps.size,
114
143
  _graphProps$size$widt = _graphProps$size.width,
115
144
  width = _graphProps$size$widt === void 0 ? 500 : _graphProps$size$widt,
@@ -117,13 +146,13 @@ var Root = /*#__PURE__*/function (_React$Component) {
117
146
  height = _graphProps$size$heig === void 0 ? 500 : _graphProps$size$heig,
118
147
  domain = graphProps.domain,
119
148
  range = graphProps.range;
120
- var padding = showLabels ? 70 : 40;
121
- var extraPadding = showLabels ? 16 : 40;
122
- var finalWidth = width + padding * 2 + (domain.padding || 0) * 2 + extraPadding;
123
- var finalHeight = height + padding * 2 + (range.padding || 0) * 2;
149
+ var topPadding = 40;
150
+ var leftPadding = showLabels ? 80 : 60;
151
+ var finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;
152
+ var finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
124
153
  var activeTitlePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math' // 'languageCharacters'
125
154
  ];
126
- var actualHeight = thisIsChart && showPixelGuides ? height - 80 : height;
155
+ var actualHeight = defineChart && showPixelGuides ? height - 150 : height;
127
156
  var nbOfVerticalLines = parseInt(width / 100);
128
157
  var nbOfHorizontalLines = parseInt(actualHeight / 100);
129
158
  var sideGridlinesPadding = parseInt(actualHeight % 100);
@@ -132,7 +161,7 @@ var Root = /*#__PURE__*/function (_React$Component) {
132
161
  }, showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
133
162
  className: classes.topPixelGuides,
134
163
  style: {
135
- marginLeft: thisIsChart ? 10 : 20
164
+ marginLeft: isChart ? 60 : showLabels ? 30 : 10
136
165
  }
137
166
  }, (0, _toConsumableArray2["default"])(Array(nbOfVerticalLines + 1).keys()).map(function (value) {
138
167
  return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
@@ -141,22 +170,47 @@ var Root = /*#__PURE__*/function (_React$Component) {
141
170
  }, /*#__PURE__*/_react["default"].createElement("div", {
142
171
  className: classes.topPixelIndicator
143
172
  }, /*#__PURE__*/_react["default"].createElement("div", null, value * 100, "px"), /*#__PURE__*/_react["default"].createElement("div", null, "|")));
144
- })), showTitle && /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
145
- className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.disabledTitle, disabledTitle), classes.graphTitle),
173
+ })), showTitle && (disabledTitle ? /*#__PURE__*/_react["default"].createElement("div", {
174
+ className: (0, _classnames["default"])(classes.graphTitle, classes.disabledTitle),
175
+ dangerouslySetInnerHTML: {
176
+ __html: title || ''
177
+ }
178
+ }) : /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
179
+ className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.rightMargin, showPixelGuides), classes.graphTitle),
146
180
  markup: title || '',
147
- width: finalWidth,
148
181
  onChange: onChangeTitle,
149
- placeholder: !disabledTitle && 'Click here to add a title for this graph',
182
+ placeholder: defineChart && titlePlaceholder || !disabledTitle && 'Click here to add a title for this graph',
150
183
  toolbarOpts: {
151
184
  noBorder: true
152
185
  },
153
186
  activePlugins: activeTitlePlugins
187
+ })), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
188
+ side: "top",
189
+ text: labels.top,
190
+ disabledLabel: disabledLabels,
191
+ placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.top,
192
+ graphHeight: finalHeight,
193
+ graphWidth: finalWidth,
194
+ onChange: function onChange(value) {
195
+ return _this2.onChangeLabel(value, 'top');
196
+ }
154
197
  }), /*#__PURE__*/_react["default"].createElement("div", {
155
198
  className: classes.wrapper
156
- }, /*#__PURE__*/_react["default"].createElement("svg", {
199
+ }, showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
200
+ side: "left",
201
+ text: labels.left,
202
+ disabledLabel: disabledLabels,
203
+ placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.left,
204
+ graphHeight: finalHeight,
205
+ graphWidth: finalWidth,
206
+ isChartLeftLabel: isChart && defineChart,
207
+ onChange: function onChange(value) {
208
+ return _this2.onChangeLabel(value, 'left');
209
+ }
210
+ }), /*#__PURE__*/_react["default"].createElement("svg", {
157
211
  width: finalWidth,
158
212
  height: finalHeight,
159
- className: classes.svg
213
+ className: defineChart ? classes.defineChart : classes.chart
160
214
  }, /*#__PURE__*/_react["default"].createElement("g", {
161
215
  ref: function ref(r) {
162
216
  _this2.g = r;
@@ -166,12 +220,22 @@ var Root = /*#__PURE__*/function (_React$Component) {
166
220
  }
167
221
  },
168
222
  className: classes.graphBox,
169
- transform: "translate(".concat(padding, ", ").concat(padding, ")")
170
- }, children)), showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
223
+ transform: "translate(".concat(leftPadding, ", ").concat(topPadding, ")")
224
+ }, children)), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
225
+ side: "right",
226
+ text: labels.right,
227
+ disabledLabel: disabledLabels,
228
+ placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.right,
229
+ graphHeight: finalHeight,
230
+ graphWidth: finalWidth,
231
+ onChange: function onChange(value) {
232
+ return _this2.onChangeLabel(value, 'right');
233
+ }
234
+ }), showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
171
235
  className: classes.sidePixelGuides,
172
236
  style: {
173
237
  paddingTop: sideGridlinesPadding,
174
- marginTop: thisIsChart ? 25 : 60
238
+ marginTop: defineChart ? 25 : 31
175
239
  }
176
240
  }, (0, _toConsumableArray2["default"])(Array(nbOfHorizontalLines + 1).keys()).reverse().map(function (value) {
177
241
  return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
@@ -180,7 +244,18 @@ var Root = /*#__PURE__*/function (_React$Component) {
180
244
  }, /*#__PURE__*/_react["default"].createElement("div", {
181
245
  className: classes.sidePixelIndicator
182
246
  }, "\u2501 ", value * 100, "px"));
183
- }))));
247
+ }))), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
248
+ side: "bottom",
249
+ text: labels.bottom,
250
+ disabledLabel: disabledLabels,
251
+ placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.bottom,
252
+ graphHeight: finalHeight,
253
+ graphWidth: finalWidth,
254
+ isChartBottomLabel: isChart && defineChart,
255
+ onChange: function onChange(value) {
256
+ return _this2.onChangeLabel(value, 'bottom');
257
+ }
258
+ }));
184
259
  }
185
260
  }]);
186
261
  return Root;
@@ -206,12 +281,21 @@ var styles = function styles(theme) {
206
281
  root: {
207
282
  border: "solid 1px ".concat(_renderUi.color.primaryLight()),
208
283
  color: _renderUi.color.text(),
209
- backgroundColor: _renderUi.color.background()
284
+ backgroundColor: _renderUi.color.background(),
285
+ position: 'relative'
210
286
  },
211
287
  wrapper: {
212
- display: 'flex'
288
+ display: 'flex',
289
+ position: 'relative'
213
290
  },
214
291
  svg: {},
292
+ defineChart: {
293
+ paddingLeft: '50px',
294
+ overflow: 'visible'
295
+ },
296
+ chart: {
297
+ overflow: 'visible'
298
+ },
215
299
  graphBox: {
216
300
  cursor: 'pointer',
217
301
  userSelect: 'none'
@@ -225,6 +309,9 @@ var styles = function styles(theme) {
225
309
  disabledTitle: {
226
310
  pointerEvents: 'none'
227
311
  },
312
+ rightMargin: {
313
+ marginRight: '74px'
314
+ },
228
315
  topPixelGuides: {
229
316
  display: 'flex',
230
317
  paddingTop: '6px'
package/lib/root.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"root.js","names":["Root","g","props","graphProps","onMouseMove","scale","snap","coords","mouse","_groups","x","invert","y","snapped","select","on","mouseMove","bind","disabledTitle","children","classes","onChangeTitle","thisIsChart","showLabels","showPixelGuides","showTitle","title","rootRef","size","width","height","domain","range","padding","extraPadding","finalWidth","finalHeight","activeTitlePlugins","actualHeight","nbOfVerticalLines","parseInt","nbOfHorizontalLines","sideGridlinesPadding","root","topPixelGuides","marginLeft","Array","keys","map","value","topPixelIndicator","cn","graphTitle","noBorder","wrapper","svg","r","graphBox","sidePixelGuides","paddingTop","marginTop","reverse","sidePixelIndicator","React","Component","PropTypes","string","ChildrenType","bool","GraphPropsType","isRequired","func","object","styles","theme","border","color","primaryLight","text","backgroundColor","background","display","cursor","userSelect","fontSize","typography","textAlign","pointerEvents","flexDirection","alignItems","marginRight","marginBottom","withStyles"],"sources":["../src/root.jsx"],"sourcesContent":["import React from 'react';\nimport { ChildrenType } from './types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { select, mouse } from 'd3-selection';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { color, Readable } from '@pie-lib/render-ui';\nimport EditableHtml from '@pie-lib/editable-html';\nimport cn from 'classnames';\n\nexport class Root extends React.Component {\n static propTypes = {\n title: PropTypes.string,\n children: ChildrenType,\n disabledTitle: PropTypes.bool,\n graphProps: GraphPropsType.isRequired,\n onChangeTitle: PropTypes.func,\n onMouseMove: PropTypes.func,\n classes: PropTypes.object.isRequired,\n showLabels: PropTypes.bool,\n showTitle: PropTypes.bool,\n showPixelGuides: PropTypes.bool,\n rootRef: PropTypes.func\n };\n\n mouseMove = g => {\n const { graphProps, onMouseMove } = this.props;\n\n if (!onMouseMove) {\n return;\n }\n\n const { scale, snap } = graphProps;\n const coords = mouse(g._groups[0][0]);\n const x = scale.x.invert(coords[0]);\n const y = scale.y.invert(coords[1]);\n\n const snapped = {\n x: snap.x(x),\n y: snap.y(y)\n };\n\n onMouseMove(snapped);\n };\n\n componentDidMount() {\n const g = select(this.g);\n g.on('mousemove', this.mouseMove.bind(this, g));\n }\n\n componentWillUnmount() {\n const g = select(this.g);\n g.on('mousemove', null);\n }\n\n render() {\n const {\n disabledTitle,\n graphProps,\n children,\n classes,\n onChangeTitle,\n thisIsChart,\n showLabels,\n showPixelGuides,\n showTitle,\n title,\n rootRef\n } = this.props;\n const {\n size: { width = 500, height = 500 },\n domain,\n range\n } = graphProps;\n\n const padding = showLabels ? 70 : 40;\n const extraPadding = showLabels ? 16 : 40;\n const finalWidth = width + padding * 2 + (domain.padding || 0) * 2 + extraPadding;\n const finalHeight = height + padding * 2 + (range.padding || 0) * 2;\n\n const activeTitlePlugins = [\n 'bold',\n 'italic',\n 'underline',\n 'strikethrough',\n 'math'\n // 'languageCharacters'\n ];\n\n const actualHeight = thisIsChart && showPixelGuides ? height - 80 : height;\n const nbOfVerticalLines = parseInt(width / 100);\n const nbOfHorizontalLines = parseInt(actualHeight / 100);\n const sideGridlinesPadding = parseInt(actualHeight % 100);\n\n return (\n <div className={classes.root}>\n {showPixelGuides && (\n <div className={classes.topPixelGuides} style={{ marginLeft: thisIsChart ? 10 : 20 }}>\n {[...Array(nbOfVerticalLines + 1).keys()].map(value => (\n <Readable false key={`top-guide-${value}`}>\n <div className={classes.topPixelIndicator}>\n <div>{value * 100}px</div>\n <div>|</div>\n </div>\n </Readable>\n ))}\n </div>\n )}\n {showTitle && (\n <EditableHtml\n className={cn(\n {\n [classes.disabledTitle]: disabledTitle\n },\n classes.graphTitle\n )}\n markup={title || ''}\n width={finalWidth}\n onChange={onChangeTitle}\n placeholder={!disabledTitle && 'Click here to add a title for this graph'}\n toolbarOpts={{ noBorder: true }}\n activePlugins={activeTitlePlugins}\n />\n )}\n <div className={classes.wrapper}>\n <svg width={finalWidth} height={finalHeight} className={classes.svg}>\n <g\n ref={r => {\n this.g = r;\n if (rootRef) {\n rootRef(r);\n }\n }}\n className={classes.graphBox}\n transform={`translate(${padding}, ${padding})`}\n >\n {children}\n </g>\n </svg>\n {showPixelGuides && (\n <div\n className={classes.sidePixelGuides}\n style={{\n paddingTop: sideGridlinesPadding,\n marginTop: thisIsChart ? 25 : 60\n }}\n >\n {[...Array(nbOfHorizontalLines + 1).keys()].reverse().map(value => (\n <Readable false key={`top-guide-${value}`}>\n <div className={classes.sidePixelIndicator}>━ {value * 100}px</div>\n </Readable>\n ))}\n </div>\n )}\n </div>\n </div>\n );\n }\n}\nconst styles = theme => ({\n root: {\n border: `solid 1px ${color.primaryLight()}`,\n color: color.text(),\n backgroundColor: color.background()\n },\n wrapper: {\n display: 'flex'\n },\n svg: {},\n graphBox: {\n cursor: 'pointer',\n userSelect: 'none'\n },\n graphTitle: {\n color: color.text(),\n fontSize: theme.typography.fontSize + 2,\n padding: '12px 4px 0',\n textAlign: 'center'\n },\n disabledTitle: {\n pointerEvents: 'none'\n },\n topPixelGuides: {\n display: 'flex',\n paddingTop: '6px'\n },\n topPixelIndicator: {\n color: color.primaryLight(),\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n width: '100px',\n pointerEvents: 'none',\n userSelect: 'none'\n },\n sidePixelGuides: {\n width: '70px',\n display: 'flex',\n flexDirection: 'column',\n marginRight: '6px'\n },\n sidePixelIndicator: {\n color: color.primaryLight(),\n textAlign: 'right',\n height: '20px',\n pointerEvents: 'none',\n userSelect: 'none',\n\n '&:not(:last-child)': {\n marginBottom: '80px'\n }\n }\n});\n\nexport default withStyles(styles)(Root);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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B,sBAAsB;QACpBQ,YAAY,EAAE;MADM;IAPJ;EA1CG,CAAL;AAAA,CAApB;;eAuDe,IAAAC,kBAAA,EAAWnB,MAAX,EAAmBzE,IAAnB,C"}
1
+ {"version":3,"file":"root.js","names":["Root","g","props","graphProps","onMouseMove","scale","snap","coords","mouse","_groups","x","invert","y","snapped","newValue","side","labels","onChangeLabels","isChart","select","on","mouseMove","bind","disabledTitle","disabledLabels","labelsPlaceholders","titlePlaceholder","children","classes","defineChart","onChangeTitle","showLabels","showPixelGuides","showTitle","title","rootRef","size","width","height","domain","range","topPadding","leftPadding","finalWidth","padding","finalHeight","activeTitlePlugins","actualHeight","nbOfVerticalLines","parseInt","nbOfHorizontalLines","sideGridlinesPadding","root","topPixelGuides","marginLeft","Array","keys","map","value","topPixelIndicator","cn","graphTitle","__html","rightMargin","noBorder","top","onChangeLabel","wrapper","left","chart","r","graphBox","right","sidePixelGuides","paddingTop","marginTop","reverse","sidePixelIndicator","bottom","React","Component","PropTypes","string","ChildrenType","bool","GraphPropsType","isRequired","func","object","styles","theme","border","color","primaryLight","text","backgroundColor","background","position","display","svg","paddingLeft","overflow","cursor","userSelect","fontSize","typography","textAlign","pointerEvents","marginRight","flexDirection","alignItems","marginBottom","withStyles"],"sources":["../src/root.jsx"],"sourcesContent":["import React from 'react';\nimport { ChildrenType } from './types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { select, mouse } from 'd3-selection';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { color, Readable } from '@pie-lib/render-ui';\nimport EditableHtml from '@pie-lib/editable-html';\nimport cn from 'classnames';\nimport Label from './label';\n\nexport class Root extends React.Component {\n static propTypes = {\n title: PropTypes.string,\n children: ChildrenType,\n disabledTitle: PropTypes.bool,\n graphProps: GraphPropsType.isRequired,\n onChangeTitle: PropTypes.func,\n onMouseMove: PropTypes.func,\n classes: PropTypes.object.isRequired,\n showLabels: PropTypes.bool,\n showTitle: PropTypes.bool,\n showPixelGuides: PropTypes.bool,\n rootRef: PropTypes.func\n };\n\n mouseMove = g => {\n const { graphProps, onMouseMove } = this.props;\n\n if (!onMouseMove) {\n return;\n }\n\n const { scale, snap } = graphProps;\n const coords = mouse(g._groups[0][0]);\n const x = scale.x.invert(coords[0]);\n const y = scale.y.invert(coords[1]);\n\n const snapped = {\n x: snap.x(x),\n y: snap.y(y)\n };\n\n onMouseMove(snapped);\n };\n\n componentDidMount() {\n const g = select(this.g);\n g.on('mousemove', this.mouseMove.bind(this, g));\n }\n\n componentWillUnmount() {\n const g = select(this.g);\n g.on('mousemove', null);\n }\n\n onChangeLabel = (newValue, side) => {\n const { labels, onChangeLabels, isChart } = this.props;\n\n if (isChart) {\n if (side === 'left') {\n onChangeLabels('range', newValue);\n } else {\n onChangeLabels('domain', newValue);\n }\n\n return;\n }\n\n onChangeLabels({\n ...labels,\n [side]: newValue\n });\n };\n\n render() {\n const {\n disabledTitle,\n disabledLabels,\n labels,\n labelsPlaceholders,\n titlePlaceholder,\n graphProps,\n children,\n classes,\n defineChart,\n onChangeTitle,\n isChart,\n showLabels,\n showPixelGuides,\n showTitle,\n title,\n rootRef\n } = this.props;\n const {\n size: { width = 500, height = 500 },\n domain,\n range\n } = graphProps;\n\n const topPadding = 40;\n const leftPadding = showLabels ? 80 : 60;\n const finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;\n const finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;\n\n const activeTitlePlugins = [\n 'bold',\n 'italic',\n 'underline',\n 'strikethrough',\n 'math'\n // 'languageCharacters'\n ];\n\n const actualHeight = defineChart && showPixelGuides ? height - 150 : height;\n const nbOfVerticalLines = parseInt(width / 100);\n const nbOfHorizontalLines = parseInt(actualHeight / 100);\n const sideGridlinesPadding = parseInt(actualHeight % 100);\n\n return (\n <div className={classes.root}>\n {showPixelGuides && (\n <div\n className={classes.topPixelGuides}\n style={{ marginLeft: isChart ? 60 : showLabels ? 30 : 10 }}\n >\n {[...Array(nbOfVerticalLines + 1).keys()].map(value => (\n <Readable false key={`top-guide-${value}`}>\n <div className={classes.topPixelIndicator}>\n <div>{value * 100}px</div>\n <div>|</div>\n </div>\n </Readable>\n ))}\n </div>\n )}\n {showTitle &&\n (disabledTitle ? (\n <div\n className={cn(classes.graphTitle, classes.disabledTitle)}\n dangerouslySetInnerHTML={{ __html: title || '' }}\n />\n ) : (\n <EditableHtml\n className={cn({ [classes.rightMargin]: showPixelGuides }, classes.graphTitle)}\n markup={title || ''}\n onChange={onChangeTitle}\n placeholder={\n (defineChart && titlePlaceholder) ||\n (!disabledTitle && 'Click here to add a title for this graph')\n }\n toolbarOpts={{ noBorder: true }}\n activePlugins={activeTitlePlugins}\n />\n ))}\n {showLabels && !isChart && (\n <Label\n side=\"top\"\n text={labels.top}\n disabledLabel={disabledLabels}\n placeholder={labelsPlaceholders?.top}\n graphHeight={finalHeight}\n graphWidth={finalWidth}\n onChange={value => this.onChangeLabel(value, 'top')}\n />\n )}\n <div className={classes.wrapper}>\n {showLabels && (\n <Label\n side=\"left\"\n text={labels.left}\n disabledLabel={disabledLabels}\n placeholder={labelsPlaceholders?.left}\n graphHeight={finalHeight}\n graphWidth={finalWidth}\n isChartLeftLabel={isChart && defineChart}\n onChange={value => this.onChangeLabel(value, 'left')}\n />\n )}\n <svg\n width={finalWidth}\n height={finalHeight}\n className={defineChart ? classes.defineChart : classes.chart}\n >\n <g\n ref={r => {\n this.g = r;\n if (rootRef) {\n rootRef(r);\n }\n }}\n className={classes.graphBox}\n transform={`translate(${leftPadding}, ${topPadding})`}\n >\n {children}\n </g>\n </svg>\n {showLabels && !isChart && (\n <Label\n side=\"right\"\n text={labels.right}\n disabledLabel={disabledLabels}\n placeholder={labelsPlaceholders?.right}\n graphHeight={finalHeight}\n graphWidth={finalWidth}\n onChange={value => this.onChangeLabel(value, 'right')}\n />\n )}\n {showPixelGuides && (\n <div\n className={classes.sidePixelGuides}\n style={{\n paddingTop: sideGridlinesPadding,\n marginTop: defineChart ? 25 : 31\n }}\n >\n {[...Array(nbOfHorizontalLines + 1).keys()].reverse().map(value => (\n <Readable false key={`top-guide-${value}`}>\n <div className={classes.sidePixelIndicator}>━ {value * 100}px</div>\n </Readable>\n ))}\n </div>\n )}\n </div>\n {showLabels && (\n <Label\n side=\"bottom\"\n text={labels.bottom}\n disabledLabel={disabledLabels}\n placeholder={labelsPlaceholders?.bottom}\n graphHeight={finalHeight}\n graphWidth={finalWidth}\n isChartBottomLabel={isChart && defineChart}\n onChange={value => this.onChangeLabel(value, 'bottom')}\n />\n )}\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n root: {\n border: `solid 1px ${color.primaryLight()}`,\n color: color.text(),\n backgroundColor: color.background(),\n position: 'relative'\n },\n wrapper: {\n display: 'flex',\n position: 'relative'\n },\n svg: {},\n defineChart: {\n paddingLeft: '50px',\n overflow: 'visible'\n },\n chart: {\n overflow: 'visible'\n },\n graphBox: {\n cursor: 'pointer',\n userSelect: 'none'\n },\n graphTitle: {\n color: color.text(),\n fontSize: theme.typography.fontSize + 2,\n padding: '12px 4px 0',\n textAlign: 'center'\n },\n disabledTitle: {\n pointerEvents: 'none'\n },\n rightMargin: {\n marginRight: '74px'\n },\n topPixelGuides: {\n display: 'flex',\n paddingTop: '6px'\n },\n topPixelIndicator: {\n color: color.primaryLight(),\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n width: '100px',\n pointerEvents: 'none',\n userSelect: 'none'\n },\n sidePixelGuides: {\n width: '70px',\n display: 'flex',\n flexDirection: 'column',\n marginRight: '6px'\n },\n sidePixelIndicator: {\n color: color.primaryLight(),\n textAlign: 'right',\n height: '20px',\n pointerEvents: 'none',\n userSelect: 'none',\n\n '&:not(:last-child)': {\n marginBottom: '80px'\n }\n }\n});\n\nexport default withStyles(styles)(Root);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;;;IAEaA,I;;;;;;;;;;;;;;;kGA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Be,KAAK,EAAEA,eAAA,CAAMC,YAAN,EADW;MAElBa,SAAS,EAAE,OAFO;MAGlBpE,MAAM,EAAE,MAHU;MAIlBqE,aAAa,EAAE,MAJG;MAKlBJ,UAAU,EAAE,MALM;MAOlB,sBAAsB;QACpBQ,YAAY,EAAE;MADM;IAPJ;EAtDG,CAAL;AAAA,CAApB;;eAmEe,IAAAC,kBAAA,EAAWvB,MAAX,EAAmBzF,IAAnB,C"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.1.10-next.605+e53e3c32",
6
+ "version": "2.1.10-next.657+05b98cfc",
7
7
  "description": "Some underlying components for building charts/graphs",
8
8
  "keywords": [
9
9
  "react",
@@ -38,6 +38,6 @@
38
38
  "peerDependencies": {
39
39
  "react": "^16.8.1"
40
40
  },
41
- "gitHead": "e53e3c32ecfe4eada6509f82ce533abbdeb11884",
41
+ "gitHead": "05b98cfc01698e15619790bba8d5809b6619d86d",
42
42
  "scripts": {}
43
43
  }
package/src/label.jsx ADDED
@@ -0,0 +1,121 @@
1
+ import React, { useState } from 'react';
2
+ import { color, Readable } from '@pie-lib/render-ui';
3
+ import cn from 'classnames';
4
+ import EditableHtml from '@pie-lib/editable-html';
5
+ import { withStyles } from '@material-ui/core/styles';
6
+
7
+ const LabelComponent = props => {
8
+ const {
9
+ classes,
10
+ disabledLabel,
11
+ graphHeight,
12
+ graphWidth,
13
+ isChartBottomLabel,
14
+ isChartLeftLabel,
15
+ placeholder,
16
+ text,
17
+ side,
18
+ onChange
19
+ } = props;
20
+ const [rotatedToHorizontal, setRotatedToHorizontal] = useState(false);
21
+ const activePlugins = [
22
+ 'bold',
23
+ 'italic',
24
+ 'underline',
25
+ 'strikethrough',
26
+ 'math'
27
+ // 'languageCharacters'
28
+ ];
29
+
30
+ const chartValue = side === 'left' && isChartLeftLabel && graphHeight - 148;
31
+ const defaultStyle = {
32
+ width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),
33
+ top:
34
+ chartValue ||
35
+ (side === 'left' && `${graphHeight - 8}px`) ||
36
+ (side === 'bottom' && `${graphHeight - 90}px`) ||
37
+ 0,
38
+ left:
39
+ (side === 'right' && `${graphWidth - 8}px`) ||
40
+ ((isChartLeftLabel || isChartBottomLabel) && '50px') ||
41
+ 0
42
+ };
43
+
44
+ const rotatedStyle = {
45
+ width: graphWidth - 8,
46
+ top: (side === 'right' && `${graphHeight - 22}px`) || 0,
47
+ left: 0
48
+ };
49
+
50
+ const rotateLabel = () =>
51
+ !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);
52
+
53
+ return (
54
+ <Readable false>
55
+ <div
56
+ className={cn(classes.axisLabel, {
57
+ [classes.rotateLeftLabel]: side === 'left' && !rotatedToHorizontal,
58
+ [classes.rotateRightLabel]: side === 'right' && !rotatedToHorizontal,
59
+ [classes.editLabel]: rotatedToHorizontal,
60
+ [classes.customBottom]: isChartBottomLabel
61
+ })}
62
+ style={rotatedToHorizontal ? rotatedStyle : defaultStyle}
63
+ onClick={rotateLabel}
64
+ >
65
+ {disabledLabel ? (
66
+ <div className={classes.disabledLabel} dangerouslySetInnerHTML={{ __html: text || '' }} />
67
+ ) : (
68
+ <EditableHtml
69
+ markup={text || ''}
70
+ onChange={onChange}
71
+ placeholder={!disabledLabel && placeholder}
72
+ toolbarOpts={{
73
+ position: side === 'bottom' ? 'top' : 'bottom',
74
+ noBorder: true
75
+ }}
76
+ activePlugins={activePlugins}
77
+ onDone={() => setRotatedToHorizontal(false)}
78
+ />
79
+ )}
80
+ </div>
81
+ </Readable>
82
+ );
83
+ };
84
+
85
+ export default withStyles(theme => ({
86
+ label: {
87
+ fill: color.secondary()
88
+ },
89
+ axisLabel: {
90
+ fontSize: theme.typography.fontSize - 2,
91
+ textAlign: 'center',
92
+ margin: '4px',
93
+ padding: '4px 0'
94
+ },
95
+ disabledLabel: {
96
+ pointerEvents: 'none',
97
+ width: '100%'
98
+ },
99
+ editLabel: {
100
+ position: 'absolute',
101
+ backgroundColor: 'white',
102
+ borderRadius: '4px',
103
+ boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',
104
+ zIndex: 10
105
+ },
106
+ rotateLeftLabel: {
107
+ rotate: '-90deg',
108
+ transformOrigin: '0 0',
109
+ transformStyle: 'preserve-3d',
110
+ position: 'absolute'
111
+ },
112
+ rotateRightLabel: {
113
+ rotate: '90deg',
114
+ transformOrigin: '0 0',
115
+ transformStyle: 'preserve-3d',
116
+ position: 'absolute'
117
+ },
118
+ customBottom: {
119
+ position: 'absolute'
120
+ }
121
+ }))(LabelComponent);
package/src/root.jsx CHANGED
@@ -7,6 +7,7 @@ import { GraphPropsType } from './types';
7
7
  import { color, Readable } from '@pie-lib/render-ui';
8
8
  import EditableHtml from '@pie-lib/editable-html';
9
9
  import cn from 'classnames';
10
+ import Label from './label';
10
11
 
11
12
  export class Root extends React.Component {
12
13
  static propTypes = {
@@ -53,14 +54,38 @@ export class Root extends React.Component {
53
54
  g.on('mousemove', null);
54
55
  }
55
56
 
57
+ onChangeLabel = (newValue, side) => {
58
+ const { labels, onChangeLabels, isChart } = this.props;
59
+
60
+ if (isChart) {
61
+ if (side === 'left') {
62
+ onChangeLabels('range', newValue);
63
+ } else {
64
+ onChangeLabels('domain', newValue);
65
+ }
66
+
67
+ return;
68
+ }
69
+
70
+ onChangeLabels({
71
+ ...labels,
72
+ [side]: newValue
73
+ });
74
+ };
75
+
56
76
  render() {
57
77
  const {
58
78
  disabledTitle,
79
+ disabledLabels,
80
+ labels,
81
+ labelsPlaceholders,
82
+ titlePlaceholder,
59
83
  graphProps,
60
84
  children,
61
85
  classes,
86
+ defineChart,
62
87
  onChangeTitle,
63
- thisIsChart,
88
+ isChart,
64
89
  showLabels,
65
90
  showPixelGuides,
66
91
  showTitle,
@@ -73,10 +98,10 @@ export class Root extends React.Component {
73
98
  range
74
99
  } = graphProps;
75
100
 
76
- const padding = showLabels ? 70 : 40;
77
- const extraPadding = showLabels ? 16 : 40;
78
- const finalWidth = width + padding * 2 + (domain.padding || 0) * 2 + extraPadding;
79
- const finalHeight = height + padding * 2 + (range.padding || 0) * 2;
101
+ const topPadding = 40;
102
+ const leftPadding = showLabels ? 80 : 60;
103
+ const finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;
104
+ const finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
80
105
 
81
106
  const activeTitlePlugins = [
82
107
  'bold',
@@ -87,7 +112,7 @@ export class Root extends React.Component {
87
112
  // 'languageCharacters'
88
113
  ];
89
114
 
90
- const actualHeight = thisIsChart && showPixelGuides ? height - 80 : height;
115
+ const actualHeight = defineChart && showPixelGuides ? height - 150 : height;
91
116
  const nbOfVerticalLines = parseInt(width / 100);
92
117
  const nbOfHorizontalLines = parseInt(actualHeight / 100);
93
118
  const sideGridlinesPadding = parseInt(actualHeight % 100);
@@ -95,7 +120,10 @@ export class Root extends React.Component {
95
120
  return (
96
121
  <div className={classes.root}>
97
122
  {showPixelGuides && (
98
- <div className={classes.topPixelGuides} style={{ marginLeft: thisIsChart ? 10 : 20 }}>
123
+ <div
124
+ className={classes.topPixelGuides}
125
+ style={{ marginLeft: isChart ? 60 : showLabels ? 30 : 10 }}
126
+ >
99
127
  {[...Array(nbOfVerticalLines + 1).keys()].map(value => (
100
128
  <Readable false key={`top-guide-${value}`}>
101
129
  <div className={classes.topPixelIndicator}>
@@ -106,24 +134,54 @@ export class Root extends React.Component {
106
134
  ))}
107
135
  </div>
108
136
  )}
109
- {showTitle && (
110
- <EditableHtml
111
- className={cn(
112
- {
113
- [classes.disabledTitle]: disabledTitle
114
- },
115
- classes.graphTitle
116
- )}
117
- markup={title || ''}
118
- width={finalWidth}
119
- onChange={onChangeTitle}
120
- placeholder={!disabledTitle && 'Click here to add a title for this graph'}
121
- toolbarOpts={{ noBorder: true }}
122
- activePlugins={activeTitlePlugins}
137
+ {showTitle &&
138
+ (disabledTitle ? (
139
+ <div
140
+ className={cn(classes.graphTitle, classes.disabledTitle)}
141
+ dangerouslySetInnerHTML={{ __html: title || '' }}
142
+ />
143
+ ) : (
144
+ <EditableHtml
145
+ className={cn({ [classes.rightMargin]: showPixelGuides }, classes.graphTitle)}
146
+ markup={title || ''}
147
+ onChange={onChangeTitle}
148
+ placeholder={
149
+ (defineChart && titlePlaceholder) ||
150
+ (!disabledTitle && 'Click here to add a title for this graph')
151
+ }
152
+ toolbarOpts={{ noBorder: true }}
153
+ activePlugins={activeTitlePlugins}
154
+ />
155
+ ))}
156
+ {showLabels && !isChart && (
157
+ <Label
158
+ side="top"
159
+ text={labels.top}
160
+ disabledLabel={disabledLabels}
161
+ placeholder={labelsPlaceholders?.top}
162
+ graphHeight={finalHeight}
163
+ graphWidth={finalWidth}
164
+ onChange={value => this.onChangeLabel(value, 'top')}
123
165
  />
124
166
  )}
125
167
  <div className={classes.wrapper}>
126
- <svg width={finalWidth} height={finalHeight} className={classes.svg}>
168
+ {showLabels && (
169
+ <Label
170
+ side="left"
171
+ text={labels.left}
172
+ disabledLabel={disabledLabels}
173
+ placeholder={labelsPlaceholders?.left}
174
+ graphHeight={finalHeight}
175
+ graphWidth={finalWidth}
176
+ isChartLeftLabel={isChart && defineChart}
177
+ onChange={value => this.onChangeLabel(value, 'left')}
178
+ />
179
+ )}
180
+ <svg
181
+ width={finalWidth}
182
+ height={finalHeight}
183
+ className={defineChart ? classes.defineChart : classes.chart}
184
+ >
127
185
  <g
128
186
  ref={r => {
129
187
  this.g = r;
@@ -132,17 +190,28 @@ export class Root extends React.Component {
132
190
  }
133
191
  }}
134
192
  className={classes.graphBox}
135
- transform={`translate(${padding}, ${padding})`}
193
+ transform={`translate(${leftPadding}, ${topPadding})`}
136
194
  >
137
195
  {children}
138
196
  </g>
139
197
  </svg>
198
+ {showLabels && !isChart && (
199
+ <Label
200
+ side="right"
201
+ text={labels.right}
202
+ disabledLabel={disabledLabels}
203
+ placeholder={labelsPlaceholders?.right}
204
+ graphHeight={finalHeight}
205
+ graphWidth={finalWidth}
206
+ onChange={value => this.onChangeLabel(value, 'right')}
207
+ />
208
+ )}
140
209
  {showPixelGuides && (
141
210
  <div
142
211
  className={classes.sidePixelGuides}
143
212
  style={{
144
213
  paddingTop: sideGridlinesPadding,
145
- marginTop: thisIsChart ? 25 : 60
214
+ marginTop: defineChart ? 25 : 31
146
215
  }}
147
216
  >
148
217
  {[...Array(nbOfHorizontalLines + 1).keys()].reverse().map(value => (
@@ -153,20 +222,42 @@ export class Root extends React.Component {
153
222
  </div>
154
223
  )}
155
224
  </div>
225
+ {showLabels && (
226
+ <Label
227
+ side="bottom"
228
+ text={labels.bottom}
229
+ disabledLabel={disabledLabels}
230
+ placeholder={labelsPlaceholders?.bottom}
231
+ graphHeight={finalHeight}
232
+ graphWidth={finalWidth}
233
+ isChartBottomLabel={isChart && defineChart}
234
+ onChange={value => this.onChangeLabel(value, 'bottom')}
235
+ />
236
+ )}
156
237
  </div>
157
238
  );
158
239
  }
159
240
  }
241
+
160
242
  const styles = theme => ({
161
243
  root: {
162
244
  border: `solid 1px ${color.primaryLight()}`,
163
245
  color: color.text(),
164
- backgroundColor: color.background()
246
+ backgroundColor: color.background(),
247
+ position: 'relative'
165
248
  },
166
249
  wrapper: {
167
- display: 'flex'
250
+ display: 'flex',
251
+ position: 'relative'
168
252
  },
169
253
  svg: {},
254
+ defineChart: {
255
+ paddingLeft: '50px',
256
+ overflow: 'visible'
257
+ },
258
+ chart: {
259
+ overflow: 'visible'
260
+ },
170
261
  graphBox: {
171
262
  cursor: 'pointer',
172
263
  userSelect: 'none'
@@ -180,6 +271,9 @@ const styles = theme => ({
180
271
  disabledTitle: {
181
272
  pointerEvents: 'none'
182
273
  },
274
+ rightMargin: {
275
+ marginRight: '74px'
276
+ },
183
277
  topPixelGuides: {
184
278
  display: 'flex',
185
279
  paddingTop: '6px'