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

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,128 @@
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
+ placeholder = props.placeholder,
38
+ text = props.text,
39
+ side = props.side,
40
+ onChange = props.onChange;
41
+
42
+ var _useState = (0, _react.useState)(false),
43
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
44
+ rotatedToHorizontal = _useState2[0],
45
+ setRotatedToHorizontal = _useState2[1];
46
+
47
+ var activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math' // 'languageCharacters'
48
+ ];
49
+ var defaultStyle = {
50
+ width: side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8,
51
+ top: side === 'left' && "".concat(graphHeight - 8, "px") || 0,
52
+ left: side === 'right' && "".concat(graphWidth - 8, "px") || 0
53
+ };
54
+ var rotatedStyle = {
55
+ width: graphWidth - 8,
56
+ top: side === 'right' && "".concat(graphHeight - 22, "px") || 0,
57
+ left: 0
58
+ };
59
+
60
+ var rotateLabel = function rotateLabel() {
61
+ return !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);
62
+ };
63
+
64
+ return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
65
+ "false": true
66
+ }, /*#__PURE__*/_react["default"].createElement("div", {
67
+ 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), _cn)),
68
+ style: rotatedToHorizontal ? rotatedStyle : defaultStyle,
69
+ onClick: rotateLabel
70
+ }, disabledLabel ? /*#__PURE__*/_react["default"].createElement("div", {
71
+ className: classes.disabledLabel,
72
+ dangerouslySetInnerHTML: {
73
+ __html: text || ''
74
+ }
75
+ }) : /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
76
+ markup: text || '',
77
+ onChange: onChange,
78
+ placeholder: !disabledLabel && placeholder,
79
+ toolbarOpts: {
80
+ position: side === 'bottom' ? 'top' : 'bottom',
81
+ noBorder: true
82
+ },
83
+ activePlugins: activePlugins,
84
+ onDone: function onDone() {
85
+ return setRotatedToHorizontal(false);
86
+ }
87
+ })));
88
+ };
89
+
90
+ var _default = (0, _styles.withStyles)(function (theme) {
91
+ return {
92
+ label: {
93
+ fill: _renderUi.color.secondary()
94
+ },
95
+ axisLabel: {
96
+ fontSize: theme.typography.fontSize - 2,
97
+ textAlign: 'center',
98
+ margin: '4px',
99
+ padding: '4px 0'
100
+ },
101
+ disabledLabel: {
102
+ pointerEvents: 'none',
103
+ width: '100%'
104
+ },
105
+ editLabel: {
106
+ position: 'absolute',
107
+ backgroundColor: 'white',
108
+ borderRadius: '4px',
109
+ boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',
110
+ zIndex: 10
111
+ },
112
+ rotateLeftLabel: {
113
+ rotate: '-90deg',
114
+ transformOrigin: '0 0',
115
+ transformStyle: 'preserve-3d',
116
+ position: 'absolute'
117
+ },
118
+ rotateRightLabel: {
119
+ rotate: '90deg',
120
+ transformOrigin: '0 0',
121
+ transformStyle: 'preserve-3d',
122
+ position: 'absolute'
123
+ }
124
+ };
125
+ })(LabelComponent);
126
+
127
+ exports["default"] = _default;
128
+ //# sourceMappingURL=label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.js","names":["LabelComponent","props","classes","disabledLabel","graphHeight","graphWidth","placeholder","text","side","onChange","useState","rotatedToHorizontal","setRotatedToHorizontal","activePlugins","defaultStyle","width","top","left","rotatedStyle","rotateLabel","cn","axisLabel","rotateLeftLabel","rotateRightLabel","editLabel","__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 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 defaultStyle = {\n width: side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8,\n top: (side === 'left' && `${graphHeight - 8}px`) || 0,\n left: (side === 'right' && `${graphWidth - 8}px`) || 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 })}\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}))(LabelComponent);\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,KAAK,EAAI;EAAA;;EAC9B,IACEC,OADF,GASID,KATJ,CACEC,OADF;EAAA,IAEEC,aAFF,GASIF,KATJ,CAEEE,aAFF;EAAA,IAGEC,WAHF,GASIH,KATJ,CAGEG,WAHF;EAAA,IAIEC,UAJF,GASIJ,KATJ,CAIEI,UAJF;EAAA,IAKEC,WALF,GASIL,KATJ,CAKEK,WALF;EAAA,IAMEC,IANF,GASIN,KATJ,CAMEM,IANF;EAAA,IAOEC,IAPF,GASIP,KATJ,CAOEO,IAPF;EAAA,IAQEC,QARF,GASIR,KATJ,CAQEQ,QARF;;EAUA,gBAAsD,IAAAC,eAAA,EAAS,KAAT,CAAtD;EAAA;EAAA,IAAOC,mBAAP;EAAA,IAA4BC,sBAA5B;;EACA,IAAMC,aAAa,GAAG,CACpB,MADoB,EAEpB,QAFoB,EAGpB,WAHoB,EAIpB,eAJoB,EAKpB,MALoB,CAMpB;EANoB,CAAtB;EASA,IAAMC,YAAY,GAAG;IACnBC,KAAK,EAAEP,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,OAA5B,GAAsCJ,WAAW,GAAG,CAApD,GAAwDC,UAAU,GAAG,CADzD;IAEnBW,G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,KAApB,GAA4B,QAD3B;MAEXmB,QAAQ,EAAE;IAFC,CAJf;IAQE,aAAa,EAAEd,aARjB;IASE,MAAM,EAAE;MAAA,OAAMD,sBAAsB,CAAC,KAAD,CAA5B;IAAA;EATV,EAZJ,CADF,CADF;AA6BD,CAjED;;eAmEe,IAAAgB,kBAAA,EAAW,UAAAC,KAAK;EAAA,OAAK;IAClCC,KAAK,EAAE;MACLC,IAAI,EAAEC,eAAA,CAAMC,SAAN;IADD,CAD2B;IAIlCZ,SAAS,EAAE;MACTa,QAAQ,EAAEL,KAAK,CAACM,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;MAETE,SAAS,EAAE,QAFF;MAGTC,MAAM,EAAE,KAHC;MAITC,OAAO,EAAE;IAJA,CAJuB;IAUlCnC,aAAa,EAAE;MACboC,aAAa,EAAE,MADF;MAEbxB,KAAK,EAAE;IAFM,CAVmB;IAclCS,SAAS,EAAE;MACTE,QAAQ,EAAE,UADD;MAETc,eAAe,EAAE,OAFR;MAGTC,YAAY,EAAE,KAHL;MAITC,SAAS,EAAE,iCAJF;MAKTC,MAAM,EAAE;IALC,CAduB;IAqBlCrB,eAAe,EAAE;MACfsB,MAAM,EAAE,QADO;MAEfC,eAAe,EAAE,KAFF;MAGfC,cAAc,EAAE,aAHD;MAIfpB,QAAQ,EAAE;IAJK,CArBiB;IA2BlCH,gBAAgB,EAAE;MAChBqB,MAAM,EAAE,OADQ;MAEhBC,eAAe,EAAE,KAFD;MAGhBC,cAAc,EAAE,aAHA;MAIhBpB,QAAQ,EAAE;IAJM;EA3BgB,CAAL;AAAA,CAAhB,EAiCX1B,cAjCW,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,12 @@ 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
+ onChangeLabels(_objectSpread(_objectSpread({}, labels), {}, (0, _defineProperty2["default"])({}, side, newValue)));
92
+ });
81
93
  return _this;
82
94
  }
83
95
 
@@ -98,18 +110,21 @@ var Root = /*#__PURE__*/function (_React$Component) {
98
110
  value: function render() {
99
111
  var _this2 = this;
100
112
 
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;
113
+ var _this$props3 = this.props,
114
+ disabledTitle = _this$props3.disabledTitle,
115
+ disabledLabels = _this$props3.disabledLabels,
116
+ labels = _this$props3.labels,
117
+ labelsPlaceholders = _this$props3.labelsPlaceholders,
118
+ graphProps = _this$props3.graphProps,
119
+ children = _this$props3.children,
120
+ classes = _this$props3.classes,
121
+ onChangeTitle = _this$props3.onChangeTitle,
122
+ thisIsChart = _this$props3.thisIsChart,
123
+ showLabels = _this$props3.showLabels,
124
+ showPixelGuides = _this$props3.showPixelGuides,
125
+ showTitle = _this$props3.showTitle,
126
+ title = _this$props3.title,
127
+ rootRef = _this$props3.rootRef;
113
128
  var _graphProps$size = graphProps.size,
114
129
  _graphProps$size$widt = _graphProps$size.width,
115
130
  width = _graphProps$size$widt === void 0 ? 500 : _graphProps$size$widt,
@@ -117,10 +132,10 @@ var Root = /*#__PURE__*/function (_React$Component) {
117
132
  height = _graphProps$size$heig === void 0 ? 500 : _graphProps$size$heig,
118
133
  domain = graphProps.domain,
119
134
  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;
135
+ var topPadding = 40;
136
+ var leftPadding = showLabels ? 80 : 60;
137
+ var finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;
138
+ var finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
124
139
  var activeTitlePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math' // 'languageCharacters'
125
140
  ];
126
141
  var actualHeight = thisIsChart && showPixelGuides ? height - 80 : height;
@@ -132,7 +147,7 @@ var Root = /*#__PURE__*/function (_React$Component) {
132
147
  }, showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
133
148
  className: classes.topPixelGuides,
134
149
  style: {
135
- marginLeft: thisIsChart ? 10 : 20
150
+ marginLeft: thisIsChart ? 10 : showLabels ? 30 : 10
136
151
  }
137
152
  }, (0, _toConsumableArray2["default"])(Array(nbOfVerticalLines + 1).keys()).map(function (value) {
138
153
  return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
@@ -141,19 +156,43 @@ var Root = /*#__PURE__*/function (_React$Component) {
141
156
  }, /*#__PURE__*/_react["default"].createElement("div", {
142
157
  className: classes.topPixelIndicator
143
158
  }, /*#__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),
159
+ })), showTitle && (disabledTitle ? /*#__PURE__*/_react["default"].createElement("div", {
160
+ className: (0, _classnames["default"])(classes.graphTitle, classes.disabledTitle),
161
+ dangerouslySetInnerHTML: {
162
+ __html: title || ''
163
+ }
164
+ }) : /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
165
+ className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.rightMargin, showPixelGuides), classes.graphTitle),
146
166
  markup: title || '',
147
- width: finalWidth,
148
167
  onChange: onChangeTitle,
149
168
  placeholder: !disabledTitle && 'Click here to add a title for this graph',
150
169
  toolbarOpts: {
151
170
  noBorder: true
152
171
  },
153
172
  activePlugins: activeTitlePlugins
173
+ })), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
174
+ side: "top",
175
+ text: labels.top,
176
+ disabledLabel: disabledLabels,
177
+ placeholder: labelsPlaceholders.top,
178
+ graphHeight: finalHeight,
179
+ graphWidth: finalWidth,
180
+ onChange: function onChange(value) {
181
+ return _this2.onChangeLabel(value, 'top');
182
+ }
154
183
  }), /*#__PURE__*/_react["default"].createElement("div", {
155
184
  className: classes.wrapper
156
- }, /*#__PURE__*/_react["default"].createElement("svg", {
185
+ }, showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
186
+ side: "left",
187
+ text: labels.left,
188
+ disabledLabel: disabledLabels,
189
+ placeholder: labelsPlaceholders.left,
190
+ graphHeight: finalHeight,
191
+ graphWidth: finalWidth,
192
+ onChange: function onChange(value) {
193
+ return _this2.onChangeLabel(value, 'left');
194
+ }
195
+ }), /*#__PURE__*/_react["default"].createElement("svg", {
157
196
  width: finalWidth,
158
197
  height: finalHeight,
159
198
  className: classes.svg
@@ -166,12 +205,22 @@ var Root = /*#__PURE__*/function (_React$Component) {
166
205
  }
167
206
  },
168
207
  className: classes.graphBox,
169
- transform: "translate(".concat(padding, ", ").concat(padding, ")")
170
- }, children)), showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
208
+ transform: "translate(".concat(leftPadding, ", ").concat(topPadding, ")")
209
+ }, children)), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
210
+ side: "right",
211
+ text: labels.right,
212
+ disabledLabel: disabledLabels,
213
+ placeholder: labelsPlaceholders.right,
214
+ graphHeight: finalHeight,
215
+ graphWidth: finalWidth,
216
+ onChange: function onChange(value) {
217
+ return _this2.onChangeLabel(value, 'right');
218
+ }
219
+ }), showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
171
220
  className: classes.sidePixelGuides,
172
221
  style: {
173
222
  paddingTop: sideGridlinesPadding,
174
- marginTop: thisIsChart ? 25 : 60
223
+ marginTop: thisIsChart ? 25 : 31
175
224
  }
176
225
  }, (0, _toConsumableArray2["default"])(Array(nbOfHorizontalLines + 1).keys()).reverse().map(function (value) {
177
226
  return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
@@ -180,7 +229,17 @@ var Root = /*#__PURE__*/function (_React$Component) {
180
229
  }, /*#__PURE__*/_react["default"].createElement("div", {
181
230
  className: classes.sidePixelIndicator
182
231
  }, "\u2501 ", value * 100, "px"));
183
- }))));
232
+ }))), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
233
+ side: "bottom",
234
+ text: labels.bottom,
235
+ disabledLabel: disabledLabels,
236
+ placeholder: labelsPlaceholders.bottom,
237
+ graphHeight: finalHeight,
238
+ graphWidth: finalWidth,
239
+ onChange: function onChange(value) {
240
+ return _this2.onChangeLabel(value, 'bottom');
241
+ }
242
+ }));
184
243
  }
185
244
  }]);
186
245
  return Root;
@@ -209,7 +268,8 @@ var styles = function styles(theme) {
209
268
  backgroundColor: _renderUi.color.background()
210
269
  },
211
270
  wrapper: {
212
- display: 'flex'
271
+ display: 'flex',
272
+ position: 'relative'
213
273
  },
214
274
  svg: {},
215
275
  graphBox: {
@@ -225,6 +285,9 @@ var styles = function styles(theme) {
225
285
  disabledTitle: {
226
286
  pointerEvents: 'none'
227
287
  },
288
+ rightMargin: {
289
+ marginRight: '74px'
290
+ },
228
291
  topPixelGuides: {
229
292
  display: 'flex',
230
293
  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":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;IAEaA,I;;;;;;;;;;;;;;;kGAeC,UAAAC,CAAC,EAAI;MACf,kBAAoC,MAAKC,KAAzC;MAAA,IAAQC,UAAR,eAAQA,UAAR;MAAA,IAAoBC,WAApB,eAAoBA,WAApB;;MAEA,IAAI,CAACA,WAAL,EAAkB;QAChB;MACD;;MAED,IAAQC,KAAR,GAAwBF,UAAxB,CAAQE,KAAR;MAAA,IAAeC,IAAf,GAAwBH,UAAxB,CAAeG,IAAf;MACA,IAAMC,MAAM,GAAG,IAAAC,kBAAA,EAAMP,CAAC,CAACQ,OAAF,CAAU,CAAV,EAAa,CAAb,CAAN,CAAf;MACA,IAAMC,CAAC,GAAGL,KAAK,CAACK,CAAN,CAAQC,MAAR,CAAeJ,MAAM,CAAC,CAAD,CAArB,CAAV;MACA,IAAMK,CAAC,GAAGP,KAAK,CAACO,CAAN,CAAQD,MAAR,CAAeJ,MAAM,CAAC,CAAD,CAArB,CAAV;MAEA,IAAMM,OAAO,GAAG;QACdH,CAAC,EAAEJ,IAAI,CAACI,CAA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iB,EAAE;MACjB0B,KAAK,EAAEA,eAAA,CAAMC,YAAN,EADU;MAEjBI,OAAO,EAAE,MAFQ;MAGjBO,aAAa,EAAE,QAHE;MAIjBC,UAAU,EAAE,QAJK;MAKjB5D,KAAK,EAAE,OALU;MAMjB0D,aAAa,EAAE,MANE;MAOjBJ,UAAU,EAAE;IAPK,CA3BI;IAoCvBzB,eAAe,EAAE;MACf7B,KAAK,EAAE,MADQ;MAEfoD,OAAO,EAAE,MAFM;MAGfO,aAAa,EAAE,QAHA;MAIfE,WAAW,EAAE;IAJE,CApCM;IA0CvB5B,kBAAkB,EAAE;MAClBc,KAAK,EAAEA,eAAA,CAAMC,YAAN,EADW;MAElBS,SAAS,EAAE,OAFO;MAGlBxD,MAAM,EAAE,MAHU;MAIlByD,aAAa,EAAE,MAJG;MAKlBJ,UAAU,EAAE,MALM;MAOlB,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","select","on","mouseMove","bind","disabledTitle","disabledLabels","labelsPlaceholders","children","classes","onChangeTitle","thisIsChart","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","svg","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","display","position","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 } = this.props;\n\n onChangeLabels({\n ...labels,\n [side]: newValue\n });\n };\n\n render() {\n const {\n disabledTitle,\n disabledLabels,\n labels,\n labelsPlaceholders,\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 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 = 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\n className={classes.topPixelGuides}\n style={{ marginLeft: thisIsChart ? 10 : 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={!disabledTitle && 'Click here to add a title for this graph'}\n toolbarOpts={{ noBorder: true }}\n activePlugins={activeTitlePlugins}\n />\n ))}\n {showLabels && (\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 onChange={value => this.onChangeLabel(value, 'left')}\n />\n )}\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(${leftPadding}, ${topPadding})`}\n >\n {children}\n </g>\n </svg>\n {showLabels && (\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: thisIsChart ? 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 onChange={value => this.onChangeLabel(value, 'bottom')}\n />\n )}\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 position: 'relative'\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 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\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CAF5B;MAGVzD,OAAO,EAAE,YAHC;MAIV2D,SAAS,EAAE;IAJD,CAfW;IAqBvB/E,aAAa,EAAE;MACbgF,aAAa,EAAE;IADF,CArBQ;IAwBvBzC,WAAW,EAAE;MACX0C,WAAW,EAAE;IADF,CAxBU;IA2BvBpD,cAAc,EAAE;MACd4C,OAAO,EAAE,MADK;MAEdvB,UAAU,EAAE;IAFE,CA3BO;IA+BvBf,iBAAiB,EAAE;MACjBiC,KAAK,EAAEA,eAAA,CAAMC,YAAN,EADU;MAEjBI,OAAO,EAAE,MAFQ;MAGjBS,aAAa,EAAE,QAHE;MAIjBC,UAAU,EAAE,QAJK;MAKjBtE,KAAK,EAAE,OALU;MAMjBmE,aAAa,EAAE,MANE;MAOjBJ,UAAU,EAAE;IAPK,CA/BI;IAwCvB3B,eAAe,EAAE;MACfpC,KAAK,EAAE,MADQ;MAEf4D,OAAO,EAAE,MAFM;MAGfS,aAAa,EAAE,QAHA;MAIfD,WAAW,EAAE;IAJE,CAxCM;IA8CvB5B,kBAAkB,EAAE;MAClBe,KAAK,EAAEA,eAAA,CAAMC,YAAN,EADW;MAElBU,SAAS,EAAE,OAFO;MAGlBjE,MAAM,EAAE,MAHU;MAIlBkE,aAAa,EAAE,MAJG;MAKlBJ,UAAU,EAAE,MALM;MAOlB,sBAAsB;QACpBQ,YAAY,EAAE;MADM;IAPJ;EA9CG,CAAL;AAAA,CAApB;;eA2De,IAAAC,kBAAA,EAAWpB,MAAX,EAAmBvF,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.624+902972ab",
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": "902972ab86b0fcd40ddd0e7c809efe9922605668",
42
42
  "scripts": {}
43
43
  }
package/src/label.jsx ADDED
@@ -0,0 +1,107 @@
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
+ placeholder,
14
+ text,
15
+ side,
16
+ onChange
17
+ } = props;
18
+ const [rotatedToHorizontal, setRotatedToHorizontal] = useState(false);
19
+ const activePlugins = [
20
+ 'bold',
21
+ 'italic',
22
+ 'underline',
23
+ 'strikethrough',
24
+ 'math'
25
+ // 'languageCharacters'
26
+ ];
27
+
28
+ const defaultStyle = {
29
+ width: side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8,
30
+ top: (side === 'left' && `${graphHeight - 8}px`) || 0,
31
+ left: (side === 'right' && `${graphWidth - 8}px`) || 0
32
+ };
33
+
34
+ const rotatedStyle = {
35
+ width: graphWidth - 8,
36
+ top: (side === 'right' && `${graphHeight - 22}px`) || 0,
37
+ left: 0
38
+ };
39
+
40
+ const rotateLabel = () =>
41
+ !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);
42
+
43
+ return (
44
+ <Readable false>
45
+ <div
46
+ className={cn(classes.axisLabel, {
47
+ [classes.rotateLeftLabel]: side === 'left' && !rotatedToHorizontal,
48
+ [classes.rotateRightLabel]: side === 'right' && !rotatedToHorizontal,
49
+ [classes.editLabel]: rotatedToHorizontal
50
+ })}
51
+ style={rotatedToHorizontal ? rotatedStyle : defaultStyle}
52
+ onClick={rotateLabel}
53
+ >
54
+ {disabledLabel ? (
55
+ <div className={classes.disabledLabel} dangerouslySetInnerHTML={{ __html: text || '' }} />
56
+ ) : (
57
+ <EditableHtml
58
+ markup={text || ''}
59
+ onChange={onChange}
60
+ placeholder={!disabledLabel && placeholder}
61
+ toolbarOpts={{
62
+ position: side === 'bottom' ? 'top' : 'bottom',
63
+ noBorder: true
64
+ }}
65
+ activePlugins={activePlugins}
66
+ onDone={() => setRotatedToHorizontal(false)}
67
+ />
68
+ )}
69
+ </div>
70
+ </Readable>
71
+ );
72
+ };
73
+
74
+ export default withStyles(theme => ({
75
+ label: {
76
+ fill: color.secondary()
77
+ },
78
+ axisLabel: {
79
+ fontSize: theme.typography.fontSize - 2,
80
+ textAlign: 'center',
81
+ margin: '4px',
82
+ padding: '4px 0'
83
+ },
84
+ disabledLabel: {
85
+ pointerEvents: 'none',
86
+ width: '100%'
87
+ },
88
+ editLabel: {
89
+ position: 'absolute',
90
+ backgroundColor: 'white',
91
+ borderRadius: '4px',
92
+ boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',
93
+ zIndex: 10
94
+ },
95
+ rotateLeftLabel: {
96
+ rotate: '-90deg',
97
+ transformOrigin: '0 0',
98
+ transformStyle: 'preserve-3d',
99
+ position: 'absolute'
100
+ },
101
+ rotateRightLabel: {
102
+ rotate: '90deg',
103
+ transformOrigin: '0 0',
104
+ transformStyle: 'preserve-3d',
105
+ position: 'absolute'
106
+ }
107
+ }))(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,9 +54,21 @@ export class Root extends React.Component {
53
54
  g.on('mousemove', null);
54
55
  }
55
56
 
57
+ onChangeLabel = (newValue, side) => {
58
+ const { labels, onChangeLabels } = this.props;
59
+
60
+ onChangeLabels({
61
+ ...labels,
62
+ [side]: newValue
63
+ });
64
+ };
65
+
56
66
  render() {
57
67
  const {
58
68
  disabledTitle,
69
+ disabledLabels,
70
+ labels,
71
+ labelsPlaceholders,
59
72
  graphProps,
60
73
  children,
61
74
  classes,
@@ -73,10 +86,10 @@ export class Root extends React.Component {
73
86
  range
74
87
  } = graphProps;
75
88
 
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;
89
+ const topPadding = 40;
90
+ const leftPadding = showLabels ? 80 : 60;
91
+ const finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;
92
+ const finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
80
93
 
81
94
  const activeTitlePlugins = [
82
95
  'bold',
@@ -95,7 +108,10 @@ export class Root extends React.Component {
95
108
  return (
96
109
  <div className={classes.root}>
97
110
  {showPixelGuides && (
98
- <div className={classes.topPixelGuides} style={{ marginLeft: thisIsChart ? 10 : 20 }}>
111
+ <div
112
+ className={classes.topPixelGuides}
113
+ style={{ marginLeft: thisIsChart ? 10 : showLabels ? 30 : 10 }}
114
+ >
99
115
  {[...Array(nbOfVerticalLines + 1).keys()].map(value => (
100
116
  <Readable false key={`top-guide-${value}`}>
101
117
  <div className={classes.topPixelIndicator}>
@@ -106,23 +122,45 @@ export class Root extends React.Component {
106
122
  ))}
107
123
  </div>
108
124
  )}
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}
125
+ {showTitle &&
126
+ (disabledTitle ? (
127
+ <div
128
+ className={cn(classes.graphTitle, classes.disabledTitle)}
129
+ dangerouslySetInnerHTML={{ __html: title || '' }}
130
+ />
131
+ ) : (
132
+ <EditableHtml
133
+ className={cn({ [classes.rightMargin]: showPixelGuides }, classes.graphTitle)}
134
+ markup={title || ''}
135
+ onChange={onChangeTitle}
136
+ placeholder={!disabledTitle && 'Click here to add a title for this graph'}
137
+ toolbarOpts={{ noBorder: true }}
138
+ activePlugins={activeTitlePlugins}
139
+ />
140
+ ))}
141
+ {showLabels && (
142
+ <Label
143
+ side="top"
144
+ text={labels.top}
145
+ disabledLabel={disabledLabels}
146
+ placeholder={labelsPlaceholders.top}
147
+ graphHeight={finalHeight}
148
+ graphWidth={finalWidth}
149
+ onChange={value => this.onChangeLabel(value, 'top')}
123
150
  />
124
151
  )}
125
152
  <div className={classes.wrapper}>
153
+ {showLabels && (
154
+ <Label
155
+ side="left"
156
+ text={labels.left}
157
+ disabledLabel={disabledLabels}
158
+ placeholder={labelsPlaceholders.left}
159
+ graphHeight={finalHeight}
160
+ graphWidth={finalWidth}
161
+ onChange={value => this.onChangeLabel(value, 'left')}
162
+ />
163
+ )}
126
164
  <svg width={finalWidth} height={finalHeight} className={classes.svg}>
127
165
  <g
128
166
  ref={r => {
@@ -132,17 +170,28 @@ export class Root extends React.Component {
132
170
  }
133
171
  }}
134
172
  className={classes.graphBox}
135
- transform={`translate(${padding}, ${padding})`}
173
+ transform={`translate(${leftPadding}, ${topPadding})`}
136
174
  >
137
175
  {children}
138
176
  </g>
139
177
  </svg>
178
+ {showLabels && (
179
+ <Label
180
+ side="right"
181
+ text={labels.right}
182
+ disabledLabel={disabledLabels}
183
+ placeholder={labelsPlaceholders.right}
184
+ graphHeight={finalHeight}
185
+ graphWidth={finalWidth}
186
+ onChange={value => this.onChangeLabel(value, 'right')}
187
+ />
188
+ )}
140
189
  {showPixelGuides && (
141
190
  <div
142
191
  className={classes.sidePixelGuides}
143
192
  style={{
144
193
  paddingTop: sideGridlinesPadding,
145
- marginTop: thisIsChart ? 25 : 60
194
+ marginTop: thisIsChart ? 25 : 31
146
195
  }}
147
196
  >
148
197
  {[...Array(nbOfHorizontalLines + 1).keys()].reverse().map(value => (
@@ -153,6 +202,17 @@ export class Root extends React.Component {
153
202
  </div>
154
203
  )}
155
204
  </div>
205
+ {showLabels && (
206
+ <Label
207
+ side="bottom"
208
+ text={labels.bottom}
209
+ disabledLabel={disabledLabels}
210
+ placeholder={labelsPlaceholders.bottom}
211
+ graphHeight={finalHeight}
212
+ graphWidth={finalWidth}
213
+ onChange={value => this.onChangeLabel(value, 'bottom')}
214
+ />
215
+ )}
156
216
  </div>
157
217
  );
158
218
  }
@@ -164,7 +224,8 @@ const styles = theme => ({
164
224
  backgroundColor: color.background()
165
225
  },
166
226
  wrapper: {
167
- display: 'flex'
227
+ display: 'flex',
228
+ position: 'relative'
168
229
  },
169
230
  svg: {},
170
231
  graphBox: {
@@ -180,6 +241,9 @@ const styles = theme => ({
180
241
  disabledTitle: {
181
242
  pointerEvents: 'none'
182
243
  },
244
+ rightMargin: {
245
+ marginRight: '74px'
246
+ },
183
247
  topPixelGuides: {
184
248
  display: 'flex',
185
249
  paddingTop: '6px'