@pie-lib/plot 2.7.4-next.0 → 2.8.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -8
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +6 -2
- package/src/__tests__/__snapshots__/grid-draggable.test.jsx.snap +185 -0
- package/src/__tests__/__snapshots__/root.test.jsx.snap +18 -0
- package/src/__tests__/draggable.test.jsx +23 -0
- package/src/__tests__/grid-draggable.test.jsx +326 -0
- package/src/__tests__/root.test.jsx +118 -0
- package/src/__tests__/trig.test.js +174 -0
- package/src/__tests__/utils.test.js +233 -0
- package/src/grid-draggable.jsx +52 -8
- package/src/label.jsx +14 -3
- package/src/root.jsx +82 -35
- package/src/trig.js +1 -1
- package/src/utils.js +14 -0
- package/lib/draggable.js +0 -65
- package/lib/draggable.js.map +0 -1
- package/lib/graph-props.js +0 -53
- package/lib/graph-props.js.map +0 -1
- package/lib/grid-draggable.js +0 -345
- package/lib/grid-draggable.js.map +0 -1
- package/lib/index.js +0 -59
- package/lib/index.js.map +0 -1
- package/lib/label.js +0 -164
- package/lib/label.js.map +0 -1
- package/lib/root.js +0 -379
- package/lib/root.js.map +0 -1
- package/lib/trig.js +0 -196
- package/lib/trig.js.map +0 -1
- package/lib/types.js +0 -68
- package/lib/types.js.map +0 -1
- package/lib/utils.js +0 -210
- package/lib/utils.js.map +0 -1
package/lib/grid-draggable.js
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
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.gridDraggable = exports.deltaFn = void 0;
|
|
11
|
-
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
|
|
18
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
-
|
|
20
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
21
|
-
|
|
22
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
23
|
-
|
|
24
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
25
|
-
|
|
26
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
27
|
-
|
|
28
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
29
|
-
|
|
30
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
31
|
-
|
|
32
|
-
var _react = _interopRequireDefault(require("react"));
|
|
33
|
-
|
|
34
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
35
|
-
|
|
36
|
-
var _types = require("./types");
|
|
37
|
-
|
|
38
|
-
var _draggable = require("./draggable");
|
|
39
|
-
|
|
40
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
41
|
-
|
|
42
|
-
var utils = _interopRequireWildcard(require("./utils"));
|
|
43
|
-
|
|
44
|
-
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
45
|
-
|
|
46
|
-
var _invariant = _interopRequireDefault(require("invariant"));
|
|
47
|
-
|
|
48
|
-
var _d3Selection = require("d3-selection");
|
|
49
|
-
|
|
50
|
-
var _excluded = ["disabled", "onClick"];
|
|
51
|
-
|
|
52
|
-
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); }
|
|
53
|
-
|
|
54
|
-
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; }
|
|
55
|
-
|
|
56
|
-
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); }; }
|
|
57
|
-
|
|
58
|
-
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; } }
|
|
59
|
-
|
|
60
|
-
var log = (0, _debug["default"])('pie-lib:plot:grid-draggable');
|
|
61
|
-
|
|
62
|
-
var deltaFn = function deltaFn(scale, snap, val) {
|
|
63
|
-
return function (delta) {
|
|
64
|
-
var normalized = delta + scale(0);
|
|
65
|
-
var inverted = scale.invert(normalized);
|
|
66
|
-
var fixDecimalsArithmetic = snap(val + inverted).toFixed(4) * 1000 / 1000;
|
|
67
|
-
return fixDecimalsArithmetic;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Creates a Component that is draggable, within a bounded grid.
|
|
72
|
-
* @param {*} opts
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
exports.deltaFn = deltaFn;
|
|
77
|
-
|
|
78
|
-
var gridDraggable = function gridDraggable(opts) {
|
|
79
|
-
return function (Comp) {
|
|
80
|
-
var _class;
|
|
81
|
-
|
|
82
|
-
(0, _invariant["default"])(!!opts && (0, _isFunction["default"])(opts.fromDelta) && (0, _isFunction["default"])(opts.bounds) && (0, _isFunction["default"])(opts.anchorPoint), 'You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }');
|
|
83
|
-
return _class = /*#__PURE__*/function (_React$Component) {
|
|
84
|
-
(0, _inherits2["default"])(GridDraggable, _React$Component);
|
|
85
|
-
|
|
86
|
-
var _super = _createSuper(GridDraggable);
|
|
87
|
-
|
|
88
|
-
function GridDraggable() {
|
|
89
|
-
var _this;
|
|
90
|
-
|
|
91
|
-
(0, _classCallCheck2["default"])(this, GridDraggable);
|
|
92
|
-
|
|
93
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
94
|
-
args[_key] = arguments[_key];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
98
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "grid", function () {
|
|
99
|
-
var graphProps = _this.props.graphProps;
|
|
100
|
-
var scale = graphProps.scale,
|
|
101
|
-
domain = graphProps.domain,
|
|
102
|
-
range = graphProps.range;
|
|
103
|
-
return {
|
|
104
|
-
x: scale.x(domain.step) - scale.x(0),
|
|
105
|
-
y: scale.y(range.step) - scale.y(0)
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onStart", function (e) {
|
|
109
|
-
var onDragStart = _this.props.onDragStart;
|
|
110
|
-
|
|
111
|
-
if (document.activeElement) {
|
|
112
|
-
document.activeElement.blur();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
_this.setState({
|
|
116
|
-
startX: e.clientX,
|
|
117
|
-
startY: e.clientY
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (onDragStart) {
|
|
121
|
-
onDragStart();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "position", function () {
|
|
125
|
-
var _opts$anchorPoint = opts.anchorPoint(_this.props),
|
|
126
|
-
x = _opts$anchorPoint.x,
|
|
127
|
-
y = _opts$anchorPoint.y;
|
|
128
|
-
|
|
129
|
-
var graphProps = _this.props.graphProps;
|
|
130
|
-
var scale = graphProps.scale,
|
|
131
|
-
snap = graphProps.snap;
|
|
132
|
-
return {
|
|
133
|
-
anchorPoint: {
|
|
134
|
-
x: x,
|
|
135
|
-
y: y
|
|
136
|
-
},
|
|
137
|
-
x: deltaFn(scale.x, snap.x, x),
|
|
138
|
-
y: deltaFn(scale.y, snap.y, y)
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "tiny", function (key, event) {
|
|
142
|
-
var K = key.toUpperCase();
|
|
143
|
-
var end = event["client".concat(K)];
|
|
144
|
-
|
|
145
|
-
var start = _this.state["start".concat(K)];
|
|
146
|
-
|
|
147
|
-
var delta = Math.abs(end - start);
|
|
148
|
-
var out = delta < Math.abs(_this.grid()[key]) / 10;
|
|
149
|
-
log('[tiny] key: ', key, 'delta: ', delta, 'out: ', out);
|
|
150
|
-
return out;
|
|
151
|
-
});
|
|
152
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getScaledBounds", function () {
|
|
153
|
-
var bounds = opts.bounds(_this.props, _this.props.graphProps);
|
|
154
|
-
log('bounds: ', bounds);
|
|
155
|
-
|
|
156
|
-
var grid = _this.grid();
|
|
157
|
-
|
|
158
|
-
var scaled = {
|
|
159
|
-
left: bounds.left / grid.interval * grid.x,
|
|
160
|
-
right: bounds.right / grid.interval * grid.x,
|
|
161
|
-
top: bounds.top / grid.interval * grid.y,
|
|
162
|
-
bottom: bounds.bottom / grid.interval * grid.y
|
|
163
|
-
};
|
|
164
|
-
log('[getScaledBounds]: ', scaled);
|
|
165
|
-
return scaled;
|
|
166
|
-
});
|
|
167
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "skipDragOutsideOfBounds", function (dd, e, graphProps) {
|
|
168
|
-
// ignore drag movement outside of the domain and range.
|
|
169
|
-
var rootNode = graphProps.getRootNode();
|
|
170
|
-
|
|
171
|
-
var _clientPoint = (0, _d3Selection.clientPoint)(rootNode, e),
|
|
172
|
-
_clientPoint2 = (0, _slicedToArray2["default"])(_clientPoint, 2),
|
|
173
|
-
rawX = _clientPoint2[0],
|
|
174
|
-
rawY = _clientPoint2[1];
|
|
175
|
-
|
|
176
|
-
var scale = graphProps.scale,
|
|
177
|
-
domain = graphProps.domain,
|
|
178
|
-
range = graphProps.range;
|
|
179
|
-
var x = scale.x.invert(rawX);
|
|
180
|
-
var y = scale.y.invert(rawY);
|
|
181
|
-
var xOutside = dd.deltaX > 0 && x < domain.min || dd.deltaX < 0 && x > domain.max;
|
|
182
|
-
var yOutside = dd.deltaY > 0 && y > range.max || dd.deltaY < 0 && y < range.min;
|
|
183
|
-
return xOutside || yOutside;
|
|
184
|
-
});
|
|
185
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDrag", function (e, dd) {
|
|
186
|
-
var _this$props = _this.props,
|
|
187
|
-
onDrag = _this$props.onDrag,
|
|
188
|
-
graphProps = _this$props.graphProps;
|
|
189
|
-
|
|
190
|
-
if (!onDrag) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
var bounds = _this.getScaledBounds();
|
|
195
|
-
|
|
196
|
-
if (dd.deltaX < 0 && dd.deltaX < bounds.left) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (dd.deltaX > 0 && dd.deltaX > bounds.right) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (dd.deltaY < 0 && dd.deltaY < bounds.top) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (dd.deltaY > 0 && dd.deltaY > bounds.bottom) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (_this.skipDragOutsideOfBounds(dd, e, graphProps)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
var dragArg = _this.applyDelta({
|
|
217
|
-
x: dd.deltaX,
|
|
218
|
-
y: dd.deltaY
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
if (dragArg !== undefined || dragArg !== null) {
|
|
222
|
-
onDrag(dragArg);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getDelta", function (point) {
|
|
226
|
-
var pos = _this.position();
|
|
227
|
-
|
|
228
|
-
var p = {
|
|
229
|
-
x: pos.x(point.x),
|
|
230
|
-
y: pos.y(point.y)
|
|
231
|
-
};
|
|
232
|
-
return utils.getDelta(pos.anchorPoint, p);
|
|
233
|
-
});
|
|
234
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "applyDelta", function (point) {
|
|
235
|
-
var delta = _this.getDelta(point);
|
|
236
|
-
|
|
237
|
-
log('[applyDelta] delta:', delta);
|
|
238
|
-
return opts.fromDelta(_this.props, delta);
|
|
239
|
-
});
|
|
240
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onStop", function (e, dd) {
|
|
241
|
-
log('[onStop] dd:', dd);
|
|
242
|
-
var _this$props2 = _this.props,
|
|
243
|
-
onDragStop = _this$props2.onDragStop,
|
|
244
|
-
onClick = _this$props2.onClick;
|
|
245
|
-
|
|
246
|
-
if (onDragStop) {
|
|
247
|
-
onDragStop();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
log('[onStop] lastX/Y: ', dd.lastX, dd.lastY);
|
|
251
|
-
|
|
252
|
-
var isClick = _this.tiny('x', e) && _this.tiny('y', e);
|
|
253
|
-
|
|
254
|
-
if (isClick) {
|
|
255
|
-
if (onClick) {
|
|
256
|
-
log('call onClick');
|
|
257
|
-
|
|
258
|
-
_this.setState({
|
|
259
|
-
startX: null
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
var graphProps = _this.props.graphProps;
|
|
263
|
-
var scale = graphProps.scale,
|
|
264
|
-
snap = graphProps.snap;
|
|
265
|
-
|
|
266
|
-
var _clientPoint3 = (0, _d3Selection.clientPoint)(e.target, e),
|
|
267
|
-
_clientPoint4 = (0, _slicedToArray2["default"])(_clientPoint3, 2),
|
|
268
|
-
rawX = _clientPoint4[0],
|
|
269
|
-
rawY = _clientPoint4[1];
|
|
270
|
-
|
|
271
|
-
var x = scale.x.invert(rawX);
|
|
272
|
-
var y = scale.y.invert(rawY);
|
|
273
|
-
x = snap.x(x);
|
|
274
|
-
y = snap.y(y);
|
|
275
|
-
onClick({
|
|
276
|
-
x: x,
|
|
277
|
-
y: y
|
|
278
|
-
});
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
_this.setState({
|
|
284
|
-
startX: null,
|
|
285
|
-
startY: null
|
|
286
|
-
}); // return false to prevent state updates in the underlying draggable - a move will have triggered an update already.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return false;
|
|
290
|
-
});
|
|
291
|
-
return _this;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
(0, _createClass2["default"])(GridDraggable, [{
|
|
295
|
-
key: "render",
|
|
296
|
-
value: function render() {
|
|
297
|
-
/* eslint-disable no-unused-vars */
|
|
298
|
-
//Note: we pull onClick out so that it's not in ...rest.
|
|
299
|
-
var _this$props3 = this.props,
|
|
300
|
-
disabled = _this$props3.disabled,
|
|
301
|
-
onClick = _this$props3.onClick,
|
|
302
|
-
rest = (0, _objectWithoutProperties2["default"])(_this$props3, _excluded);
|
|
303
|
-
/* eslint-enable no-unused-vars */
|
|
304
|
-
|
|
305
|
-
var grid = this.grid(); //prevent the text select icon from rendering.
|
|
306
|
-
|
|
307
|
-
var onMouseDown = function onMouseDown(e) {
|
|
308
|
-
return e.nativeEvent.preventDefault();
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* TODO: This shouldnt be necessary, we should be able to use the r-d classnames.
|
|
312
|
-
* But they aren't being unset. If we continue with this lib, we'll have to fix this.
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
var isDragging = this.state ? !!this.state.startX : false;
|
|
317
|
-
return /*#__PURE__*/_react["default"].createElement(_draggable.DraggableCore, {
|
|
318
|
-
disabled: disabled,
|
|
319
|
-
onMouseDown: onMouseDown,
|
|
320
|
-
onStart: this.onStart,
|
|
321
|
-
onDrag: this.onDrag,
|
|
322
|
-
onStop: this.onStop,
|
|
323
|
-
axis: opts.axis || 'both',
|
|
324
|
-
grid: [grid.x, grid.y]
|
|
325
|
-
}, /*#__PURE__*/_react["default"].createElement(Comp, (0, _extends2["default"])({}, rest, {
|
|
326
|
-
disabled: disabled,
|
|
327
|
-
isDragging: isDragging
|
|
328
|
-
})));
|
|
329
|
-
}
|
|
330
|
-
}]);
|
|
331
|
-
return GridDraggable;
|
|
332
|
-
}(_react["default"].Component), (0, _defineProperty2["default"])(_class, "propTypes", {
|
|
333
|
-
disabled: _propTypes["default"].bool,
|
|
334
|
-
onDragStart: _propTypes["default"].func,
|
|
335
|
-
onDrag: _propTypes["default"].func,
|
|
336
|
-
onDragStop: _propTypes["default"].func,
|
|
337
|
-
onClick: _propTypes["default"].func,
|
|
338
|
-
onMove: _propTypes["default"].func,
|
|
339
|
-
graphProps: _types.GraphPropsType.isRequired
|
|
340
|
-
}), _class;
|
|
341
|
-
};
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
exports.gridDraggable = gridDraggable;
|
|
345
|
-
//# sourceMappingURL=grid-draggable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/grid-draggable.jsx"],"names":["log","deltaFn","scale","snap","val","delta","normalized","inverted","invert","fixDecimalsArithmetic","toFixed","gridDraggable","opts","Comp","fromDelta","bounds","anchorPoint","graphProps","props","domain","range","x","step","y","e","onDragStart","document","activeElement","blur","setState","startX","clientX","startY","clientY","key","event","K","toUpperCase","end","start","state","Math","abs","out","grid","scaled","left","interval","right","top","bottom","dd","rootNode","getRootNode","rawX","rawY","xOutside","deltaX","min","max","yOutside","deltaY","onDrag","getScaledBounds","skipDragOutsideOfBounds","dragArg","applyDelta","undefined","point","pos","position","p","utils","getDelta","onDragStop","onClick","lastX","lastY","isClick","tiny","target","disabled","rest","onMouseDown","nativeEvent","preventDefault","isDragging","onStart","onStop","axis","React","Component","PropTypes","bool","func","onMove","GraphPropsType","isRequired"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AAEO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,KAAD,EAAQC,IAAR,EAAcC,GAAd;AAAA,SAAsB,UAACC,KAAD,EAAW;AACtD,QAAMC,UAAU,GAAGD,KAAK,GAAGH,KAAK,CAAC,CAAD,CAAhC;AACA,QAAMK,QAAQ,GAAGL,KAAK,CAACM,M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M,EAAE8B,sBAAUE,IAHD;AAIjBpB,MAAAA,UAAU,EAAEkB,sBAAUE,IAJL;AAKjBnB,MAAAA,OAAO,EAAEiB,sBAAUE,IALF;AAMjBC,MAAAA,MAAM,EAAEH,sBAAUE,IAND;AAOjB7E,MAAAA,UAAU,EAAE+E,sBAAeC;AAPV,KADrB;AAqMD,GA1M4B;AAAA,CAAtB","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { DraggableCore } from './draggable';\nimport debug from 'debug';\nimport * as utils from './utils';\nimport isFunction from 'lodash/isFunction';\nimport invariant from 'invariant';\nimport { clientPoint } from 'd3-selection';\n\nconst log = debug('pie-lib:plot:grid-draggable');\n\nexport const deltaFn = (scale, snap, val) => (delta) => {\n const normalized = delta + scale(0);\n const inverted = scale.invert(normalized);\n\n const fixDecimalsArithmetic = (snap(val + inverted).toFixed(4) * 1000) / 1000;\n\n return fixDecimalsArithmetic;\n};\n\n/**\n * Creates a Component that is draggable, within a bounded grid.\n * @param {*} opts\n */\nexport const gridDraggable = (opts) => (Comp) => {\n invariant(\n !!opts && isFunction(opts.fromDelta) && isFunction(opts.bounds) && isFunction(opts.anchorPoint),\n 'You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }',\n );\n return class GridDraggable extends React.Component {\n static propTypes = {\n disabled: PropTypes.bool,\n onDragStart: PropTypes.func,\n onDrag: PropTypes.func,\n onDragStop: PropTypes.func,\n onClick: PropTypes.func,\n onMove: PropTypes.func,\n graphProps: GraphPropsType.isRequired,\n };\n grid = () => {\n const { graphProps } = this.props;\n const { scale, domain, range } = graphProps;\n return {\n x: scale.x(domain.step) - scale.x(0),\n y: scale.y(range.step) - scale.y(0),\n };\n };\n onStart = (e) => {\n const { onDragStart } = this.props;\n if (document.activeElement) {\n document.activeElement.blur();\n }\n this.setState({ startX: e.clientX, startY: e.clientY });\n if (onDragStart) {\n onDragStart();\n }\n };\n position = () => {\n const { x, y } = opts.anchorPoint(this.props);\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n\n return {\n anchorPoint: {\n x,\n y,\n },\n x: deltaFn(scale.x, snap.x, x),\n y: deltaFn(scale.y, snap.y, y),\n };\n };\n\n tiny = (key, event) => {\n const K = key.toUpperCase();\n const end = event[`client${K}`];\n const start = this.state[`start${K}`];\n const delta = Math.abs(end - start);\n const out = delta < Math.abs(this.grid()[key]) / 10;\n log('[tiny] key: ', key, 'delta: ', delta, 'out: ', out);\n return out;\n };\n\n getScaledBounds = () => {\n const bounds = opts.bounds(this.props, this.props.graphProps);\n log('bounds: ', bounds);\n const grid = this.grid();\n\n const scaled = {\n left: (bounds.left / grid.interval) * grid.x,\n right: (bounds.right / grid.interval) * grid.x,\n top: (bounds.top / grid.interval) * grid.y,\n bottom: (bounds.bottom / grid.interval) * grid.y,\n };\n log('[getScaledBounds]: ', scaled);\n return scaled;\n };\n\n skipDragOutsideOfBounds = (dd, e, graphProps) => {\n // ignore drag movement outside of the domain and range.\n const rootNode = graphProps.getRootNode();\n const [rawX, rawY] = clientPoint(rootNode, e);\n const { scale, domain, range } = graphProps;\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n\n const xOutside = (dd.deltaX > 0 && x < domain.min) || (dd.deltaX < 0 && x > domain.max);\n const yOutside = (dd.deltaY > 0 && y > range.max) || (dd.deltaY < 0 && y < range.min);\n return xOutside || yOutside;\n };\n\n onDrag = (e, dd) => {\n const { onDrag, graphProps } = this.props;\n\n if (!onDrag) {\n return;\n }\n\n const bounds = this.getScaledBounds();\n\n if (dd.deltaX < 0 && dd.deltaX < bounds.left) {\n return;\n }\n\n if (dd.deltaX > 0 && dd.deltaX > bounds.right) {\n return;\n }\n\n if (dd.deltaY < 0 && dd.deltaY < bounds.top) {\n return;\n }\n\n if (dd.deltaY > 0 && dd.deltaY > bounds.bottom) {\n return;\n }\n\n if (this.skipDragOutsideOfBounds(dd, e, graphProps)) {\n return;\n }\n\n const dragArg = this.applyDelta({ x: dd.deltaX, y: dd.deltaY });\n\n if (dragArg !== undefined || dragArg !== null) {\n onDrag(dragArg);\n }\n };\n\n getDelta = (point) => {\n const pos = this.position();\n\n const p = {\n x: pos.x(point.x),\n y: pos.y(point.y),\n };\n\n return utils.getDelta(pos.anchorPoint, p);\n };\n\n applyDelta = (point) => {\n const delta = this.getDelta(point);\n log('[applyDelta] delta:', delta);\n return opts.fromDelta(this.props, delta);\n };\n\n onStop = (e, dd) => {\n log('[onStop] dd:', dd);\n const { onDragStop, onClick } = this.props;\n\n if (onDragStop) {\n onDragStop();\n }\n\n log('[onStop] lastX/Y: ', dd.lastX, dd.lastY);\n const isClick = this.tiny('x', e) && this.tiny('y', e);\n\n if (isClick) {\n if (onClick) {\n log('call onClick');\n this.setState({ startX: null });\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n const [rawX, rawY] = clientPoint(e.target, e);\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n x = snap.x(x);\n y = snap.y(y);\n onClick({ x, y });\n return false;\n }\n }\n\n this.setState({ startX: null, startY: null });\n // return false to prevent state updates in the underlying draggable - a move will have triggered an update already.\n return false;\n };\n\n render() {\n /* eslint-disable no-unused-vars */\n //Note: we pull onClick out so that it's not in ...rest.\n const { disabled, onClick, ...rest } = this.props;\n /* eslint-enable no-unused-vars */\n\n const grid = this.grid();\n //prevent the text select icon from rendering.\n const onMouseDown = (e) => e.nativeEvent.preventDefault();\n\n /**\n * TODO: This shouldnt be necessary, we should be able to use the r-d classnames.\n * But they aren't being unset. If we continue with this lib, we'll have to fix this.\n */\n const isDragging = this.state ? !!this.state.startX : false;\n\n return (\n <DraggableCore\n disabled={disabled}\n onMouseDown={onMouseDown}\n onStart={this.onStart}\n onDrag={this.onDrag}\n onStop={this.onStop}\n axis={opts.axis || 'both'}\n grid={[grid.x, grid.y]}\n >\n <Comp {...rest} disabled={disabled} isDragging={isDragging} />\n </DraggableCore>\n );\n }\n };\n};\n"],"file":"grid-draggable.js"}
|
package/lib/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "Draggable", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _draggable["default"];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "Root", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function get() {
|
|
19
|
-
return _root["default"];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(exports, "createGraphProps", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function get() {
|
|
25
|
-
return _graphProps.create;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports, "gridDraggable", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function get() {
|
|
31
|
-
return _gridDraggable.gridDraggable;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
exports.utils = exports.types = exports.trig = void 0;
|
|
35
|
-
|
|
36
|
-
var _root = _interopRequireDefault(require("./root"));
|
|
37
|
-
|
|
38
|
-
var _draggable = _interopRequireDefault(require("./draggable"));
|
|
39
|
-
|
|
40
|
-
var _gridDraggable = require("./grid-draggable");
|
|
41
|
-
|
|
42
|
-
var utils = _interopRequireWildcard(require("./utils"));
|
|
43
|
-
|
|
44
|
-
exports.utils = utils;
|
|
45
|
-
|
|
46
|
-
var trig = _interopRequireWildcard(require("./trig"));
|
|
47
|
-
|
|
48
|
-
exports.trig = trig;
|
|
49
|
-
|
|
50
|
-
var types = _interopRequireWildcard(require("./types"));
|
|
51
|
-
|
|
52
|
-
exports.types = types;
|
|
53
|
-
|
|
54
|
-
var _graphProps = require("./graph-props");
|
|
55
|
-
|
|
56
|
-
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); }
|
|
57
|
-
|
|
58
|
-
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; }
|
|
59
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AACA;;;;AACA;;;;AACA","sourcesContent":["import Root from './root';\nimport Draggable from './draggable';\nimport { gridDraggable } from './grid-draggable';\nimport * as utils from './utils';\nimport * as trig from './trig';\nimport * as types from './types';\nimport { create as createGraphProps } from './graph-props';\n\nexport { Root, Draggable, gridDraggable, utils, trig, types, createGraphProps };\n"],"file":"index.js"}
|
package/lib/label.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
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
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
-
|
|
28
|
-
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); }
|
|
29
|
-
|
|
30
|
-
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; }
|
|
31
|
-
|
|
32
|
-
var LabelComponent = function LabelComponent(props) {
|
|
33
|
-
var _cn;
|
|
34
|
-
|
|
35
|
-
var classes = props.classes,
|
|
36
|
-
disabledLabel = props.disabledLabel,
|
|
37
|
-
graphHeight = props.graphHeight,
|
|
38
|
-
graphWidth = props.graphWidth,
|
|
39
|
-
isChartBottomLabel = props.isChartBottomLabel,
|
|
40
|
-
isDefineChartBottomLabel = props.isDefineChartBottomLabel,
|
|
41
|
-
isChartLeftLabel = props.isChartLeftLabel,
|
|
42
|
-
isDefineChartLeftLabel = props.isDefineChartLeftLabel,
|
|
43
|
-
placeholder = props.placeholder,
|
|
44
|
-
text = props.text,
|
|
45
|
-
side = props.side,
|
|
46
|
-
onChange = props.onChange,
|
|
47
|
-
_props$mathMlOptions = props.mathMlOptions,
|
|
48
|
-
mathMlOptions = _props$mathMlOptions === void 0 ? {} : _props$mathMlOptions;
|
|
49
|
-
|
|
50
|
-
var _useState = (0, _react.useState)(false),
|
|
51
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
52
|
-
rotatedToHorizontal = _useState2[0],
|
|
53
|
-
setRotatedToHorizontal = _useState2[1];
|
|
54
|
-
|
|
55
|
-
var activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math' // 'languageCharacters'
|
|
56
|
-
];
|
|
57
|
-
var isChart = isChartBottomLabel || isChartLeftLabel || isDefineChartBottomLabel || isDefineChartLeftLabel;
|
|
58
|
-
var chartValue = side === 'left' && isDefineChartLeftLabel && graphHeight - 220;
|
|
59
|
-
var defaultStyle = {
|
|
60
|
-
width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),
|
|
61
|
-
top: chartValue || isChartLeftLabel && "".concat(graphHeight - 70, "px") || side === 'left' && "".concat(graphHeight - 8, "px") || isChartBottomLabel && "".concat(graphHeight - 30, "px") || side === 'bottom' && "".concat(graphHeight - 90, "px") || 0,
|
|
62
|
-
left: side === 'right' && "".concat(graphWidth - 8, "px") || (isDefineChartLeftLabel || isDefineChartBottomLabel) && '40px' || isChartBottomLabel && '-10px' || 0
|
|
63
|
-
};
|
|
64
|
-
var rotatedStyle = {
|
|
65
|
-
width: graphWidth - 8,
|
|
66
|
-
top: side === 'right' && "".concat(graphHeight - 22, "px") || 0,
|
|
67
|
-
left: 0
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
var rotateLabel = function rotateLabel() {
|
|
71
|
-
return !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
75
|
-
"false": true
|
|
76
|
-
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
77
|
-
className: (0, _classnames["default"])(isChart ? classes.chartLabel : 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 || isDefineChartBottomLabel), _cn)),
|
|
78
|
-
style: rotatedToHorizontal ? rotatedStyle : defaultStyle,
|
|
79
|
-
onClick: rotateLabel
|
|
80
|
-
}, disabledLabel ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
81
|
-
className: classes.disabledLabel,
|
|
82
|
-
dangerouslySetInnerHTML: {
|
|
83
|
-
__html: text || ''
|
|
84
|
-
}
|
|
85
|
-
}) : /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
|
|
86
|
-
markup: text || '',
|
|
87
|
-
onChange: onChange,
|
|
88
|
-
placeholder: !disabledLabel && placeholder,
|
|
89
|
-
toolbarOpts: {
|
|
90
|
-
position: side === 'bottom' ? 'top' : 'bottom',
|
|
91
|
-
noBorder: true
|
|
92
|
-
},
|
|
93
|
-
disableScrollbar: true,
|
|
94
|
-
activePlugins: activePlugins,
|
|
95
|
-
onDone: function onDone() {
|
|
96
|
-
return setRotatedToHorizontal(false);
|
|
97
|
-
},
|
|
98
|
-
mathMlOptions: mathMlOptions
|
|
99
|
-
})));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
LabelComponent.propTypes = {
|
|
103
|
-
classes: _propTypes["default"].object,
|
|
104
|
-
disabledLabel: _propTypes["default"].bool,
|
|
105
|
-
graphHeight: _propTypes["default"].number,
|
|
106
|
-
graphWidth: _propTypes["default"].number,
|
|
107
|
-
isChartBottomLabel: _propTypes["default"].bool,
|
|
108
|
-
isDefineChartBottomLabel: _propTypes["default"].bool,
|
|
109
|
-
isChartLeftLabel: _propTypes["default"].bool,
|
|
110
|
-
isDefineChartLeftLabel: _propTypes["default"].bool,
|
|
111
|
-
placeholder: _propTypes["default"].string,
|
|
112
|
-
text: _propTypes["default"].string,
|
|
113
|
-
side: _propTypes["default"].string,
|
|
114
|
-
onChange: _propTypes["default"].func
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
var _default = (0, _styles.withStyles)(function (theme) {
|
|
118
|
-
return {
|
|
119
|
-
label: {
|
|
120
|
-
fill: _renderUi.color.secondary()
|
|
121
|
-
},
|
|
122
|
-
axisLabel: {
|
|
123
|
-
fontSize: theme.typography.fontSize - 2,
|
|
124
|
-
textAlign: 'center',
|
|
125
|
-
margin: theme.spacing.unit / 2,
|
|
126
|
-
padding: "".concat(theme.spacing.unit / 2, "px 0")
|
|
127
|
-
},
|
|
128
|
-
chartLabel: {
|
|
129
|
-
fontSize: theme.typography.fontSize + 2,
|
|
130
|
-
textAlign: 'center',
|
|
131
|
-
margin: theme.spacing.unit / 2,
|
|
132
|
-
padding: "".concat(theme.spacing.unit / 2, "px 0")
|
|
133
|
-
},
|
|
134
|
-
disabledLabel: {
|
|
135
|
-
pointerEvents: 'none',
|
|
136
|
-
width: '100%'
|
|
137
|
-
},
|
|
138
|
-
editLabel: {
|
|
139
|
-
position: 'absolute',
|
|
140
|
-
backgroundColor: 'white',
|
|
141
|
-
borderRadius: '4px',
|
|
142
|
-
boxShadow: '0px 5px 8px rgba(0, 0, 0, 0.15)',
|
|
143
|
-
zIndex: 10
|
|
144
|
-
},
|
|
145
|
-
rotateLeftLabel: {
|
|
146
|
-
'-webkit-transform': 'rotate(-90deg)',
|
|
147
|
-
transformOrigin: '0 0',
|
|
148
|
-
transformStyle: 'preserve-3d',
|
|
149
|
-
position: 'absolute'
|
|
150
|
-
},
|
|
151
|
-
rotateRightLabel: {
|
|
152
|
-
'-webkit-transform': 'rotate(90deg)',
|
|
153
|
-
transformOrigin: '0 0',
|
|
154
|
-
transformStyle: 'preserve-3d',
|
|
155
|
-
position: 'absolute'
|
|
156
|
-
},
|
|
157
|
-
customBottom: {
|
|
158
|
-
position: 'absolute'
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
})(LabelComponent);
|
|
162
|
-
|
|
163
|
-
exports["default"] = _default;
|
|
164
|
-
//# sourceMappingURL=label.js.map
|
package/lib/label.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/label.jsx"],"names":["LabelComponent","props","classes","disabledLabel","graphHeight","graphWidth","isChartBottomLabel","isDefineChartBottomLabel","isChartLeftLabel","isDefineChartLeftLabel","placeholder","text","side","onChange","mathMlOptions","rotatedToHorizontal","setRotatedToHorizontal","activePlugins","isChart","chartValue","defaultStyle","width","top","left","rotatedStyle","rotateLabel","chartLabel","axisLabel","rotateLeftLabel","rotateRightLabel","editLabel","customBottom","__html","position","noBorder","propTypes","PropTypes","object","bool","number","string","func","theme","label","fill","color","secondary","fontSize","typography","textAlign","margin","spacing","unit","padding","pointerEvents","backgroundColor","borderRadius","boxShadow","zIndex","transformOrigin","transformStyle"],"mappings":";;;;;;;;;;;;;;;AAAA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AHD;AAIf3B,MAAAA,QAAQ,EAAE;AAJK,KA3BmB;AAiCpCJ,IAAAA,gBAAgB,EAAE;AAChB,2BAAqB,eADL;AAEhB8B,MAAAA,eAAe,EAAE,KAFD;AAGhBC,MAAAA,cAAc,EAAE,aAHA;AAIhB3B,MAAAA,QAAQ,EAAE;AAJM,KAjCkB;AAuCpCF,IAAAA,YAAY,EAAE;AACZE,MAAAA,QAAQ,EAAE;AADE;AAvCsB,GAAZ;AAAA,CAAX,EA0CXjC,cA1CW,C","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';\nimport PropTypes from 'prop-types';\n\nconst LabelComponent = (props) => {\n const {\n classes,\n disabledLabel,\n graphHeight,\n graphWidth,\n isChartBottomLabel,\n isDefineChartBottomLabel,\n isChartLeftLabel,\n isDefineChartLeftLabel,\n placeholder,\n text,\n side,\n onChange,\n mathMlOptions = {},\n } = 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 isChart = isChartBottomLabel || isChartLeftLabel || isDefineChartBottomLabel || isDefineChartLeftLabel;\n\n const chartValue = side === 'left' && isDefineChartLeftLabel && graphHeight - 220;\n const defaultStyle = {\n width: chartValue || (side === 'left' || side === 'right' ? graphHeight - 8 : graphWidth - 8),\n top:\n chartValue ||\n (isChartLeftLabel && `${graphHeight - 70}px`) ||\n (side === 'left' && `${graphHeight - 8}px`) ||\n (isChartBottomLabel && `${graphHeight - 30}px`) ||\n (side === 'bottom' && `${graphHeight - 90}px`) ||\n 0,\n left:\n (side === 'right' && `${graphWidth - 8}px`) ||\n ((isDefineChartLeftLabel || isDefineChartBottomLabel) && '40px') ||\n (isChartBottomLabel && '-10px') ||\n 0,\n };\n\n const rotatedStyle = {\n width: graphWidth - 8,\n top: (side === 'right' && `${graphHeight - 22}px`) || 0,\n left: 0,\n };\n\n const rotateLabel = () => !disabledLabel && (side === 'left' || side === 'right') && setRotatedToHorizontal(true);\n\n return (\n <Readable false>\n <div\n className={cn(isChart ? classes.chartLabel : classes.axisLabel, {\n [classes.rotateLeftLabel]: side === 'left' && !rotatedToHorizontal,\n [classes.rotateRightLabel]: side === 'right' && !rotatedToHorizontal,\n [classes.editLabel]: rotatedToHorizontal,\n [classes.customBottom]: isChartBottomLabel || isDefineChartBottomLabel,\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 disableScrollbar\n activePlugins={activePlugins}\n onDone={() => setRotatedToHorizontal(false)}\n mathMlOptions={mathMlOptions}\n />\n )}\n </div>\n </Readable>\n );\n};\nLabelComponent.propTypes = {\n classes: PropTypes.object,\n disabledLabel: PropTypes.bool,\n graphHeight: PropTypes.number,\n graphWidth: PropTypes.number,\n isChartBottomLabel: PropTypes.bool,\n isDefineChartBottomLabel: PropTypes.bool,\n isChartLeftLabel: PropTypes.bool,\n isDefineChartLeftLabel: PropTypes.bool,\n placeholder: PropTypes.string,\n text: PropTypes.string,\n side: PropTypes.string,\n onChange: PropTypes.func,\n};\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: theme.spacing.unit / 2,\n padding: `${theme.spacing.unit / 2}px 0`,\n },\n chartLabel: {\n fontSize: theme.typography.fontSize + 2,\n textAlign: 'center',\n margin: theme.spacing.unit / 2,\n padding: `${theme.spacing.unit / 2}px 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 '-webkit-transform': 'rotate(-90deg)',\n transformOrigin: '0 0',\n transformStyle: 'preserve-3d',\n position: 'absolute',\n },\n rotateRightLabel: {\n '-webkit-transform': 'rotate(90deg)',\n transformOrigin: '0 0',\n transformStyle: 'preserve-3d',\n position: 'absolute',\n },\n customBottom: {\n position: 'absolute',\n },\n}))(LabelComponent);\n"],"file":"label.js"}
|