@pie-lib/plot 2.14.0 → 2.16.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 +10 -15
- package/lib/draggable.js +65 -0
- package/lib/draggable.js.map +1 -0
- package/lib/graph-props.js +53 -0
- package/lib/graph-props.js.map +1 -0
- package/lib/grid-draggable.js +381 -0
- package/lib/grid-draggable.js.map +1 -0
- package/lib/index.js +59 -0
- package/lib/index.js.map +1 -0
- package/lib/label.js +176 -0
- package/lib/label.js.map +1 -0
- package/lib/root.js +422 -0
- package/lib/root.js.map +1 -0
- package/lib/trig.js +196 -0
- package/lib/trig.js.map +1 -0
- package/lib/types.js +68 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.js +232 -0
- package/lib/utils.js.map +1 -0
- package/package.json +4 -4
package/lib/root.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.Root = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
+
|
|
18
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
+
|
|
20
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
+
|
|
22
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
+
|
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
+
|
|
26
|
+
var _react = _interopRequireDefault(require("react"));
|
|
27
|
+
|
|
28
|
+
var _types = require("./types");
|
|
29
|
+
|
|
30
|
+
var _styles = require("@material-ui/core/styles");
|
|
31
|
+
|
|
32
|
+
var _d3Selection = require("d3-selection");
|
|
33
|
+
|
|
34
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
35
|
+
|
|
36
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
37
|
+
|
|
38
|
+
var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
|
|
39
|
+
|
|
40
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
41
|
+
|
|
42
|
+
var _label = _interopRequireDefault(require("./label"));
|
|
43
|
+
|
|
44
|
+
var _utils = require("./utils");
|
|
45
|
+
|
|
46
|
+
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; }
|
|
47
|
+
|
|
48
|
+
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; }
|
|
49
|
+
|
|
50
|
+
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); }; }
|
|
51
|
+
|
|
52
|
+
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; } }
|
|
53
|
+
|
|
54
|
+
var Root = /*#__PURE__*/function (_React$Component) {
|
|
55
|
+
(0, _inherits2["default"])(Root, _React$Component);
|
|
56
|
+
|
|
57
|
+
var _super = _createSuper(Root);
|
|
58
|
+
|
|
59
|
+
function Root(props) {
|
|
60
|
+
var _this;
|
|
61
|
+
|
|
62
|
+
(0, _classCallCheck2["default"])(this, Root);
|
|
63
|
+
_this = _super.call(this, props);
|
|
64
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "mouseMove", function (g) {
|
|
65
|
+
var _this$props = _this.props,
|
|
66
|
+
graphProps = _this$props.graphProps,
|
|
67
|
+
onMouseMove = _this$props.onMouseMove;
|
|
68
|
+
|
|
69
|
+
if (!onMouseMove) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var scale = graphProps.scale,
|
|
74
|
+
snap = graphProps.snap;
|
|
75
|
+
var coords = (0, _d3Selection.mouse)(g._groups[0][0]);
|
|
76
|
+
var x = scale.x.invert(coords[0]);
|
|
77
|
+
var y = scale.y.invert(coords[1]);
|
|
78
|
+
var snapped = {
|
|
79
|
+
x: snap.x(x),
|
|
80
|
+
y: snap.y(y)
|
|
81
|
+
};
|
|
82
|
+
onMouseMove(snapped);
|
|
83
|
+
});
|
|
84
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChangeLabel", function (newValue, side) {
|
|
85
|
+
var _this$props2 = _this.props,
|
|
86
|
+
labels = _this$props2.labels,
|
|
87
|
+
onChangeLabels = _this$props2.onChangeLabels,
|
|
88
|
+
isChart = _this$props2.isChart;
|
|
89
|
+
|
|
90
|
+
if (!onChangeLabels) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (isChart) {
|
|
95
|
+
if (side === 'left') {
|
|
96
|
+
onChangeLabels('range', newValue);
|
|
97
|
+
} else {
|
|
98
|
+
onChangeLabels('domain', newValue);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
onChangeLabels(_objectSpread(_objectSpread({}, labels), {}, (0, _defineProperty2["default"])({}, side, newValue)));
|
|
105
|
+
});
|
|
106
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "measureTitleHeight", function () {
|
|
107
|
+
var titleElement = document.getElementById('editable-title');
|
|
108
|
+
|
|
109
|
+
if (titleElement) {
|
|
110
|
+
var titleHeight = titleElement.clientHeight;
|
|
111
|
+
|
|
112
|
+
_this.setState({
|
|
113
|
+
titleHeight: titleHeight,
|
|
114
|
+
prevTitle: _this.props.title
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleKeyDown", function () {
|
|
119
|
+
setTimeout(_this.measureTitleHeight, 0);
|
|
120
|
+
});
|
|
121
|
+
_this.state = {
|
|
122
|
+
titleHeight: 0
|
|
123
|
+
};
|
|
124
|
+
return _this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
(0, _createClass2["default"])(Root, [{
|
|
128
|
+
key: "componentDidMount",
|
|
129
|
+
value: function componentDidMount() {
|
|
130
|
+
var g = (0, _d3Selection.select)(this.g);
|
|
131
|
+
g.on('mousemove', this.mouseMove.bind(this, g));
|
|
132
|
+
this.measureTitleHeight();
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "componentWillUnmount",
|
|
136
|
+
value: function componentWillUnmount() {
|
|
137
|
+
var g = (0, _d3Selection.select)(this.g);
|
|
138
|
+
g.on('mousemove', null);
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "componentDidUpdate",
|
|
142
|
+
value: function componentDidUpdate(prevProps) {
|
|
143
|
+
if (prevProps.title !== this.props.title) {
|
|
144
|
+
this.measureTitleHeight();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: "render",
|
|
149
|
+
value: function render() {
|
|
150
|
+
var _this2 = this;
|
|
151
|
+
|
|
152
|
+
var _this$props3 = this.props,
|
|
153
|
+
disabledTitle = _this$props3.disabledTitle,
|
|
154
|
+
disabledLabels = _this$props3.disabledLabels,
|
|
155
|
+
labels = _this$props3.labels,
|
|
156
|
+
labelsPlaceholders = _this$props3.labelsPlaceholders,
|
|
157
|
+
titlePlaceholder = _this$props3.titlePlaceholder,
|
|
158
|
+
graphProps = _this$props3.graphProps,
|
|
159
|
+
children = _this$props3.children,
|
|
160
|
+
classes = _this$props3.classes,
|
|
161
|
+
defineChart = _this$props3.defineChart,
|
|
162
|
+
onChangeTitle = _this$props3.onChangeTitle,
|
|
163
|
+
isChart = _this$props3.isChart,
|
|
164
|
+
showLabels = _this$props3.showLabels,
|
|
165
|
+
showPixelGuides = _this$props3.showPixelGuides,
|
|
166
|
+
showTitle = _this$props3.showTitle,
|
|
167
|
+
title = _this$props3.title,
|
|
168
|
+
rootRef = _this$props3.rootRef,
|
|
169
|
+
_this$props3$mathMlOp = _this$props3.mathMlOptions,
|
|
170
|
+
mathMlOptions = _this$props3$mathMlOp === void 0 ? {} : _this$props3$mathMlOp,
|
|
171
|
+
labelsCharactersLimit = _this$props3.labelsCharactersLimit;
|
|
172
|
+
var _graphProps$size = graphProps.size,
|
|
173
|
+
_graphProps$size$widt = _graphProps$size.width,
|
|
174
|
+
width = _graphProps$size$widt === void 0 ? 500 : _graphProps$size$widt,
|
|
175
|
+
_graphProps$size$heig = _graphProps$size.height,
|
|
176
|
+
height = _graphProps$size$heig === void 0 ? 500 : _graphProps$size$heig,
|
|
177
|
+
domain = graphProps.domain,
|
|
178
|
+
range = graphProps.range;
|
|
179
|
+
var topPadding = 40;
|
|
180
|
+
var leftPadding = (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(labels === null || labels === void 0 ? void 0 : labels.left)) && (0, _utils.isEmptyObject)(labelsPlaceholders) ? 48 : 70;
|
|
181
|
+
var rightPadding = (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(labels === null || labels === void 0 ? void 0 : labels.right)) && (0, _utils.isEmptyObject)(labelsPlaceholders) ? 48 : 70;
|
|
182
|
+
var finalWidth = width + leftPadding + rightPadding + (domain.padding || 0) * 2;
|
|
183
|
+
var finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
|
|
184
|
+
var activeTitlePlugins = ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'math' // 'languageCharacters'
|
|
185
|
+
];
|
|
186
|
+
var actualHeight = defineChart && showPixelGuides ? height - 160 : height;
|
|
187
|
+
var nbOfVerticalLines = parseInt(width / 100);
|
|
188
|
+
var nbOfHorizontalLines = parseInt(actualHeight / 100);
|
|
189
|
+
var sideGridlinesPadding = parseInt(actualHeight % 100);
|
|
190
|
+
var titleHeight = this.state.titleHeight;
|
|
191
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
192
|
+
className: classes.root
|
|
193
|
+
}, showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
|
|
194
|
+
className: classes.topPixelGuides,
|
|
195
|
+
style: {
|
|
196
|
+
marginLeft: isChart ? 80 : showLabels ? 30 : 10
|
|
197
|
+
}
|
|
198
|
+
}, (0, _toConsumableArray2["default"])(Array(nbOfVerticalLines + 1).keys()).map(function (value) {
|
|
199
|
+
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
200
|
+
"false": true,
|
|
201
|
+
key: "top-guide-".concat(value)
|
|
202
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
203
|
+
className: classes.topPixelIndicator
|
|
204
|
+
}, /*#__PURE__*/_react["default"].createElement("div", null, value * 100, "px"), /*#__PURE__*/_react["default"].createElement("div", null, "|")));
|
|
205
|
+
})), showTitle && (disabledTitle ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
206
|
+
id: "editable-title",
|
|
207
|
+
style: _objectSpread(_objectSpread({}, isChart && {
|
|
208
|
+
width: finalWidth
|
|
209
|
+
}), (0, _utils.isEmptyString)((0, _utils.extractTextFromHTML)(title)) && {
|
|
210
|
+
display: 'none'
|
|
211
|
+
}),
|
|
212
|
+
className: (0, _classnames["default"])(isChart ? classes.chartTitle : classes.graphTitle, classes.disabledTitle),
|
|
213
|
+
dangerouslySetInnerHTML: {
|
|
214
|
+
__html: title || ''
|
|
215
|
+
}
|
|
216
|
+
}) : /*#__PURE__*/_react["default"].createElement("div", {
|
|
217
|
+
id: "editable-title"
|
|
218
|
+
}, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
|
|
219
|
+
style: isChart && {
|
|
220
|
+
width: finalWidth
|
|
221
|
+
},
|
|
222
|
+
className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.rightMargin, showPixelGuides), isChart ? classes.chartTitle : classes.graphTitle),
|
|
223
|
+
markup: title || '',
|
|
224
|
+
onChange: onChangeTitle,
|
|
225
|
+
placeholder: defineChart && titlePlaceholder || !disabledTitle && 'Click here to add a title for this graph',
|
|
226
|
+
toolbarOpts: {
|
|
227
|
+
noPadding: true,
|
|
228
|
+
noBorder: true
|
|
229
|
+
},
|
|
230
|
+
activePlugins: activeTitlePlugins,
|
|
231
|
+
disableScrollbar: true,
|
|
232
|
+
onKeyDown: this.handleKeyDown
|
|
233
|
+
}))), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
234
|
+
side: "top",
|
|
235
|
+
text: labels.top,
|
|
236
|
+
disabledLabel: disabledLabels,
|
|
237
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.top,
|
|
238
|
+
graphHeight: finalHeight,
|
|
239
|
+
graphWidth: finalWidth,
|
|
240
|
+
onChange: function onChange(value) {
|
|
241
|
+
return _this2.onChangeLabel(value, 'top');
|
|
242
|
+
},
|
|
243
|
+
mathMlOptions: mathMlOptions,
|
|
244
|
+
charactersLimit: labelsCharactersLimit
|
|
245
|
+
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
246
|
+
className: classes.wrapper
|
|
247
|
+
}, showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
248
|
+
side: "left",
|
|
249
|
+
text: labels.left,
|
|
250
|
+
disabledLabel: disabledLabels,
|
|
251
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.left,
|
|
252
|
+
graphHeight: finalHeight,
|
|
253
|
+
graphWidth: finalWidth,
|
|
254
|
+
isChartLeftLabel: isChart && !defineChart,
|
|
255
|
+
isDefineChartLeftLabel: isChart && defineChart,
|
|
256
|
+
onChange: function onChange(value) {
|
|
257
|
+
return _this2.onChangeLabel(value, 'left');
|
|
258
|
+
},
|
|
259
|
+
mathMlOptions: mathMlOptions,
|
|
260
|
+
charactersLimit: labelsCharactersLimit
|
|
261
|
+
}), /*#__PURE__*/_react["default"].createElement("svg", {
|
|
262
|
+
width: finalWidth,
|
|
263
|
+
height: finalHeight,
|
|
264
|
+
className: defineChart ? classes.defineChart : classes.chart
|
|
265
|
+
}, /*#__PURE__*/_react["default"].createElement("g", {
|
|
266
|
+
ref: function ref(r) {
|
|
267
|
+
_this2.g = r;
|
|
268
|
+
|
|
269
|
+
if (rootRef) {
|
|
270
|
+
rootRef(r);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
className: classes.graphBox,
|
|
274
|
+
transform: "translate(".concat(leftPadding + (domain.padding || 0), ", ").concat(topPadding + (range.padding || 0), ")")
|
|
275
|
+
}, children)), showLabels && !isChart && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
276
|
+
side: "right",
|
|
277
|
+
text: labels.right,
|
|
278
|
+
disabledLabel: disabledLabels,
|
|
279
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.right,
|
|
280
|
+
graphHeight: finalHeight,
|
|
281
|
+
graphWidth: finalWidth,
|
|
282
|
+
onChange: function onChange(value) {
|
|
283
|
+
return _this2.onChangeLabel(value, 'right');
|
|
284
|
+
},
|
|
285
|
+
mathMlOptions: mathMlOptions,
|
|
286
|
+
charactersLimit: labelsCharactersLimit
|
|
287
|
+
}), showPixelGuides && /*#__PURE__*/_react["default"].createElement("div", {
|
|
288
|
+
className: classes.sidePixelGuides,
|
|
289
|
+
style: {
|
|
290
|
+
paddingTop: sideGridlinesPadding,
|
|
291
|
+
marginTop: 31
|
|
292
|
+
}
|
|
293
|
+
}, (0, _toConsumableArray2["default"])(Array(nbOfHorizontalLines + 1).keys()).reverse().map(function (value) {
|
|
294
|
+
return /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
295
|
+
"false": true,
|
|
296
|
+
key: "top-guide-".concat(value)
|
|
297
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
298
|
+
className: classes.sidePixelIndicator
|
|
299
|
+
}, "\u2501 ", value * 100, "px"));
|
|
300
|
+
}))), showLabels && /*#__PURE__*/_react["default"].createElement(_label["default"], {
|
|
301
|
+
side: "bottom",
|
|
302
|
+
text: labels.bottom,
|
|
303
|
+
disabledLabel: disabledLabels,
|
|
304
|
+
placeholder: labelsPlaceholders === null || labelsPlaceholders === void 0 ? void 0 : labelsPlaceholders.bottom,
|
|
305
|
+
graphHeight: finalHeight,
|
|
306
|
+
graphWidth: finalWidth,
|
|
307
|
+
titleHeight: titleHeight,
|
|
308
|
+
isChartBottomLabel: isChart && !defineChart,
|
|
309
|
+
isDefineChartBottomLabel: isChart && defineChart,
|
|
310
|
+
onChange: function onChange(value) {
|
|
311
|
+
return _this2.onChangeLabel(value, 'bottom');
|
|
312
|
+
},
|
|
313
|
+
mathMlOptions: mathMlOptions,
|
|
314
|
+
charactersLimit: labelsCharactersLimit
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
}]);
|
|
318
|
+
return Root;
|
|
319
|
+
}(_react["default"].Component); // use default color theme style to avoid color contrast issues
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
exports.Root = Root;
|
|
323
|
+
(0, _defineProperty2["default"])(Root, "propTypes", {
|
|
324
|
+
title: _propTypes["default"].string,
|
|
325
|
+
children: _types.ChildrenType,
|
|
326
|
+
defineChart: _propTypes["default"].bool,
|
|
327
|
+
disabledLabels: _propTypes["default"].bool,
|
|
328
|
+
disabledTitle: _propTypes["default"].bool,
|
|
329
|
+
graphProps: _types.GraphPropsType.isRequired,
|
|
330
|
+
isChart: _propTypes["default"].bool,
|
|
331
|
+
labels: _propTypes["default"].object,
|
|
332
|
+
labelsPlaceholders: _propTypes["default"].object,
|
|
333
|
+
onChangeTitle: _propTypes["default"].func,
|
|
334
|
+
onMouseMove: _propTypes["default"].func,
|
|
335
|
+
classes: _propTypes["default"].object.isRequired,
|
|
336
|
+
showLabels: _propTypes["default"].bool,
|
|
337
|
+
showTitle: _propTypes["default"].bool,
|
|
338
|
+
showPixelGuides: _propTypes["default"].bool,
|
|
339
|
+
rootRef: _propTypes["default"].func,
|
|
340
|
+
onChangeLabels: _propTypes["default"].func,
|
|
341
|
+
titlePlaceholder: _propTypes["default"].string,
|
|
342
|
+
mathMlOptions: _propTypes["default"].object,
|
|
343
|
+
labelsCharactersLimit: _propTypes["default"].number
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
var styles = function styles(theme) {
|
|
347
|
+
return {
|
|
348
|
+
root: {
|
|
349
|
+
border: "solid 1px ".concat(_renderUi.color.primaryLight()),
|
|
350
|
+
color: _renderUi.color.defaults.TEXT,
|
|
351
|
+
backgroundColor: theme.palette.common.white,
|
|
352
|
+
touchAction: 'none',
|
|
353
|
+
position: 'relative'
|
|
354
|
+
},
|
|
355
|
+
wrapper: {
|
|
356
|
+
display: 'flex',
|
|
357
|
+
position: 'relative'
|
|
358
|
+
},
|
|
359
|
+
svg: {},
|
|
360
|
+
defineChart: {
|
|
361
|
+
paddingLeft: '50px',
|
|
362
|
+
overflow: 'visible'
|
|
363
|
+
},
|
|
364
|
+
chart: {
|
|
365
|
+
overflow: 'visible'
|
|
366
|
+
},
|
|
367
|
+
graphBox: {
|
|
368
|
+
cursor: 'pointer',
|
|
369
|
+
userSelect: 'none'
|
|
370
|
+
},
|
|
371
|
+
graphTitle: {
|
|
372
|
+
color: _renderUi.color.defaults.TEXT,
|
|
373
|
+
fontSize: theme.typography.fontSize + 2,
|
|
374
|
+
padding: "".concat(theme.spacing.unit * 1.5, "px ").concat(theme.spacing.unit / 2, "px 0"),
|
|
375
|
+
textAlign: 'center'
|
|
376
|
+
},
|
|
377
|
+
chartTitle: {
|
|
378
|
+
color: _renderUi.color.defaults.TEXT,
|
|
379
|
+
fontSize: theme.typography.fontSize + 4,
|
|
380
|
+
padding: "".concat(theme.spacing.unit * 1.5, "px ").concat(theme.spacing.unit / 2, "px 0"),
|
|
381
|
+
textAlign: 'center'
|
|
382
|
+
},
|
|
383
|
+
disabledTitle: {
|
|
384
|
+
pointerEvents: 'none'
|
|
385
|
+
},
|
|
386
|
+
rightMargin: {
|
|
387
|
+
marginRight: '74px'
|
|
388
|
+
},
|
|
389
|
+
topPixelGuides: {
|
|
390
|
+
display: 'flex',
|
|
391
|
+
paddingTop: '6px'
|
|
392
|
+
},
|
|
393
|
+
topPixelIndicator: {
|
|
394
|
+
display: 'flex',
|
|
395
|
+
flexDirection: 'column',
|
|
396
|
+
alignItems: 'center',
|
|
397
|
+
width: '100px',
|
|
398
|
+
pointerEvents: 'none',
|
|
399
|
+
userSelect: 'none'
|
|
400
|
+
},
|
|
401
|
+
sidePixelGuides: {
|
|
402
|
+
width: '70px',
|
|
403
|
+
display: 'flex',
|
|
404
|
+
flexDirection: 'column',
|
|
405
|
+
marginRight: '6px'
|
|
406
|
+
},
|
|
407
|
+
sidePixelIndicator: {
|
|
408
|
+
textAlign: 'right',
|
|
409
|
+
height: '20px',
|
|
410
|
+
pointerEvents: 'none',
|
|
411
|
+
userSelect: 'none',
|
|
412
|
+
'&:not(:last-child)': {
|
|
413
|
+
marginBottom: '80px'
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
var _default = (0, _styles.withStyles)(styles)(Root);
|
|
420
|
+
|
|
421
|
+
exports["default"] = _default;
|
|
422
|
+
//# sourceMappingURL=root.js.map
|
package/lib/root.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/root.jsx"],"names":["Root","props","g","graphProps","onMouseMove","scale","snap","coords","_groups","x","invert","y","snapped","newValue","side","labels","onChangeLabels","isChart","titleElement","document","getElementById","titleHeight","clientHeight","setState","prevTitle","title","setTimeout","measureTitleHeight","state","on","mouseMove","bind","prevProps","disabledTitle","disabledLabels","labelsPlaceholders","titlePlaceholder","children","classes","defineChart","onChangeTitle","showLabels","showPixelGuides","showTitle","rootRef","mathMlOptions","labelsCharactersLimit","size","width","height","domain","range","topPadding","leftPadding","left","rightPadding","right","finalWidth","padding","finalHeight","activeTitlePlugins","actualHeight","nbOfVerticalLines","parseInt","nbOfHorizontalLines","sideGridlinesPadding","root","topPixelGuides","marginLeft","Array","keys","map","value","topPixelIndicator","display","chartTitle","graphTitle","__html","rightMargin","noPadding","noBorder","handleKeyDown","top","onChangeLabel","wrapper","chart","r","graphBox","sidePixelGuides","paddingTop","marginTop","reverse","sidePixelIndicator","bottom","React","Component","PropTypes","string","ChildrenType","bool","GraphPropsType","isRequired","object","func","number","styles","theme","border","color","primaryLight","defaults","TEXT","backgroundColor","palette","common","white","touchAction","position","svg","paddingLeft","overflow","cursor","userSelect","fontSize","typography","spacing","unit","textAlign","pointerEvents","marginRight","flexDirection","alignItems","marginBottom"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;IAEaA,I;;;;;AACX,gBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,kGA8BP,UAACC,CAAD,EAAO;AACjB,wBAAoC,MAAKD,KAAzC;AAAA,UAAQE,UAAR,eAAQA,UAAR;AAAA,UAAoBC,WAApB,eAAoBA,WAApB;;AAEA,UAAI,CAACA,WAAL,EAAkB;AAChB;AACD;;AAED,UAAQC,KAAR,GAAwBF,UAAxB,CAAQE,KAAR;AAAA,UAAeC,IAAf,GAAwBH,UAAxB,CAAeG,IAAf;AACA,UAAMC,MAAM,GAAG,wBAAML,CAAC,CAACM,OAAF,CAAU,CAAV,EAAa,CAAb,CAAN,CAAf;AACA,UAAMC,CAAC,GAAGJ,KAAK,CAACI,CAAN,CAAQC,MAAR,CAAeH,MAAM,CAAC,CAAD,CAArB,CAAV;AACA,UAAMI,CAAC,GAAGN,KAAK,CAACM,CAAN,CAAQD,MAAR,CAAeH,MAAM,CAAC,CAAD,CAArB,CAAV;AAEA,UAAMK,OAAO,GAAG;AACdH,QAAAA,CAAC,EAAEH,IAAI,CAACG,CAAL,CAAOA,CAAP,CADW;AAEdE,QAAAA,CAAC,EAAEL,IAAI,CAACK,CAAL,CAAOA,CAAP;AAFW,OAAhB;AAKAP,MAAAA,WAAW,CAACQ,OAAD,CAAX;AACD,KAhDkB;AAAA,sGAmEH,UAACC,QAAD,EAAWC,IAAX,EAAoB;AAClC,yBAA4C,MAAKb,KAAjD;AAAA,UAAQc,MAAR,gBAAQA,MAAR;AAAA,UAAgBC,cAAhB,gBAAgBA,cAAhB;AAAA,UAAgCC,OAAhC,gBAAgCA,OAAhC;;AAEA,UAAI,CAACD,cAAL,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EAAE,MALE;AAMjBN,MAAAA,UAAU,EAAE;AANK,KA9CM;AAsDzBlC,IAAAA,eAAe,EAAE;AACfxC,MAAAA,KAAK,EAAE,MADQ;AAEf0B,MAAAA,OAAO,EAAE,MAFM;AAGfwD,MAAAA,aAAa,EAAE,QAHA;AAIfD,MAAAA,WAAW,EAAE;AAJE,KAtDQ;AA4DzBrC,IAAAA,kBAAkB,EAAE;AAClBmC,MAAAA,SAAS,EAAE,OADO;AAElB9E,MAAAA,MAAM,EAAE,MAFU;AAGlB+E,MAAAA,aAAa,EAAE,MAHG;AAIlBN,MAAAA,UAAU,EAAE,MAJM;AAMlB,4BAAsB;AACpBU,QAAAA,YAAY,EAAE;AADM;AANJ;AA5DK,GAAZ;AAAA,CAAf;;eAwEe,wBAAW3B,MAAX,EAAmBzG,IAAnB,C","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';\nimport { extractTextFromHTML, isEmptyObject, isEmptyString } from './utils';\n\nexport class Root extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n titleHeight: 0,\n };\n }\n\n static propTypes = {\n title: PropTypes.string,\n children: ChildrenType,\n defineChart: PropTypes.bool,\n disabledLabels: PropTypes.bool,\n disabledTitle: PropTypes.bool,\n graphProps: GraphPropsType.isRequired,\n isChart: PropTypes.bool,\n labels: PropTypes.object,\n labelsPlaceholders: PropTypes.object,\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 onChangeLabels: PropTypes.func,\n titlePlaceholder: PropTypes.string,\n mathMlOptions: PropTypes.object,\n labelsCharactersLimit: PropTypes.number,\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 this.measureTitleHeight();\n }\n\n componentWillUnmount() {\n const g = select(this.g);\n g.on('mousemove', null);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.title !== this.props.title) {\n this.measureTitleHeight();\n }\n }\n\n onChangeLabel = (newValue, side) => {\n const { labels, onChangeLabels, isChart } = this.props;\n\n if (!onChangeLabels) {\n return;\n }\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 measureTitleHeight = () => {\n const titleElement = document.getElementById('editable-title');\n if (titleElement) {\n const titleHeight = titleElement.clientHeight;\n this.setState({ titleHeight, prevTitle: this.props.title });\n }\n };\n\n handleKeyDown = () => {\n setTimeout(this.measureTitleHeight, 0);\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 mathMlOptions = {},\n labelsCharactersLimit,\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 = isEmptyString(extractTextFromHTML(labels?.left)) && isEmptyObject(labelsPlaceholders) ? 48 : 70;\n const rightPadding =\n isEmptyString(extractTextFromHTML(labels?.right)) && isEmptyObject(labelsPlaceholders) ? 48 : 70;\n const finalWidth = width + leftPadding + rightPadding + (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 'superscript',\n 'subscript',\n 'strikethrough',\n 'math',\n // 'languageCharacters'\n ];\n\n const actualHeight = defineChart && showPixelGuides ? height - 160 : height;\n const nbOfVerticalLines = parseInt(width / 100);\n const nbOfHorizontalLines = parseInt(actualHeight / 100);\n const sideGridlinesPadding = parseInt(actualHeight % 100);\n const { titleHeight } = this.state;\n return (\n <div className={classes.root}>\n {showPixelGuides && (\n <div className={classes.topPixelGuides} style={{ marginLeft: isChart ? 80 : showLabels ? 30 : 10 }}>\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 id=\"editable-title\"\n style={{\n ...(isChart && { width: finalWidth }),\n ...(isEmptyString(extractTextFromHTML(title)) && { display: 'none' }),\n }}\n className={cn(isChart ? classes.chartTitle : classes.graphTitle, classes.disabledTitle)}\n dangerouslySetInnerHTML={{ __html: title || '' }}\n />\n ) : (\n <div id=\"editable-title\">\n <EditableHtml\n style={\n isChart && {\n width: finalWidth,\n }\n }\n className={cn(\n { [classes.rightMargin]: showPixelGuides },\n isChart ? classes.chartTitle : classes.graphTitle,\n )}\n markup={title || ''}\n onChange={onChangeTitle}\n placeholder={\n (defineChart && titlePlaceholder) || (!disabledTitle && 'Click here to add a title for this graph')\n }\n toolbarOpts={{ noPadding: true, noBorder: true }}\n activePlugins={activeTitlePlugins}\n disableScrollbar\n onKeyDown={this.handleKeyDown}\n />\n </div>\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 mathMlOptions={mathMlOptions}\n charactersLimit={labelsCharactersLimit}\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 isDefineChartLeftLabel={isChart && defineChart}\n onChange={(value) => this.onChangeLabel(value, 'left')}\n mathMlOptions={mathMlOptions}\n charactersLimit={labelsCharactersLimit}\n />\n )}\n <svg width={finalWidth} height={finalHeight} className={defineChart ? classes.defineChart : classes.chart}>\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 + (domain.padding || 0)}, ${topPadding + (range.padding || 0)})`}\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 mathMlOptions={mathMlOptions}\n charactersLimit={labelsCharactersLimit}\n />\n )}\n {showPixelGuides && (\n <div\n className={classes.sidePixelGuides}\n style={{\n paddingTop: sideGridlinesPadding,\n marginTop: 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 titleHeight={titleHeight}\n isChartBottomLabel={isChart && !defineChart}\n isDefineChartBottomLabel={isChart && defineChart}\n onChange={(value) => this.onChangeLabel(value, 'bottom')}\n mathMlOptions={mathMlOptions}\n charactersLimit={labelsCharactersLimit}\n />\n )}\n </div>\n );\n }\n}\n\n// use default color theme style to avoid color contrast issues\nconst styles = (theme) => ({\n root: {\n border: `solid 1px ${color.primaryLight()}`,\n color: color.defaults.TEXT,\n backgroundColor: theme.palette.common.white,\n touchAction: 'none',\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.defaults.TEXT,\n fontSize: theme.typography.fontSize + 2,\n padding: `${theme.spacing.unit * 1.5}px ${theme.spacing.unit / 2}px 0`,\n textAlign: 'center',\n },\n chartTitle: {\n color: color.defaults.TEXT,\n fontSize: theme.typography.fontSize + 4,\n padding: `${theme.spacing.unit * 1.5}px ${theme.spacing.unit / 2}px 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 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 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"],"file":"root.js"}
|
package/lib/trig.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.toRadians = exports.toDegrees = exports.hypotenuse = exports.getOpposingSide = exports.edges = exports.diffEdge = exports.angle = exports.acuteYAngle = exports.acuteXAngle = void 0;
|
|
9
|
+
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
|
|
12
|
+
var _pointGeometry = _interopRequireDefault(require("@mapbox/point-geometry"));
|
|
13
|
+
|
|
14
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
15
|
+
|
|
16
|
+
var log = (0, _debug["default"])('pie-lib:plot:trig');
|
|
17
|
+
|
|
18
|
+
var toDegrees = function toDegrees(radians) {
|
|
19
|
+
return radians * (180 / Math.PI);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.toDegrees = toDegrees;
|
|
23
|
+
|
|
24
|
+
var toRadians = function toRadians(degrees) {
|
|
25
|
+
return degrees * (Math.PI / 180);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* return angle in radians between 2 points using counting degrees counter clockwise
|
|
29
|
+
*
|
|
30
|
+
* 0,0 + 1,1 = 45 in radians
|
|
31
|
+
* 1,1 + 0,0 = 45?
|
|
32
|
+
* @param {Point} a
|
|
33
|
+
* @param {Point} b
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.toRadians = toRadians;
|
|
38
|
+
|
|
39
|
+
var angle = function angle(a, b) {
|
|
40
|
+
var vd = b.y - a.y;
|
|
41
|
+
var hd = b.x - a.x;
|
|
42
|
+
log(a, b, 'vd: ', vd, 'hd: ', hd);
|
|
43
|
+
var radians = Math.atan2(vd, hd);
|
|
44
|
+
return radians < 0 ? radians + Math.PI * 2 : radians;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.angle = angle;
|
|
48
|
+
var NINETY = Math.PI / 2;
|
|
49
|
+
var ONE_EIGHTY = Math.PI;
|
|
50
|
+
var TWO_SEVENTY = ONE_EIGHTY + NINETY;
|
|
51
|
+
|
|
52
|
+
var acuteXAngle = function acuteXAngle(a) {
|
|
53
|
+
log(toDegrees(a));
|
|
54
|
+
|
|
55
|
+
if (a < NINETY) {
|
|
56
|
+
return a;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (a < ONE_EIGHTY) {
|
|
60
|
+
return Math.abs(ONE_EIGHTY - a);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (a < TWO_SEVENTY) {
|
|
64
|
+
return Math.abs(ONE_EIGHTY - a);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Math.abs(Math.PI * 2 - a);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.acuteXAngle = acuteXAngle;
|
|
71
|
+
|
|
72
|
+
var acuteYAngle = function acuteYAngle(a) {
|
|
73
|
+
return NINETY - acuteXAngle(a);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
exports.acuteYAngle = acuteYAngle;
|
|
77
|
+
|
|
78
|
+
var hypotenuse = function hypotenuse(a, alpha) {
|
|
79
|
+
var out = Math.abs(a / Math.sin(alpha));
|
|
80
|
+
return out;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* return 2 edge points for a,b within domain + range.
|
|
84
|
+
* - one edge is from following a -> b to the bounds
|
|
85
|
+
* - one edge is from following b -> a to the bounds
|
|
86
|
+
* @param {{min: number, max: number}} domain
|
|
87
|
+
* @param {{min: number, max: number}} range
|
|
88
|
+
* @param {{x: number, y: number}} a
|
|
89
|
+
* @param {{x: number, y: number}} b
|
|
90
|
+
* @returns [{x: number, y: number}, {x: number, y: number}]
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
exports.hypotenuse = hypotenuse;
|
|
95
|
+
|
|
96
|
+
var edges = function edges(domain, range) {
|
|
97
|
+
return function (a, b) {
|
|
98
|
+
// const xDest =
|
|
99
|
+
var destX = a.x < b.x ? domain.max : domain.min;
|
|
100
|
+
var destY = a.y < b.y ? range.max : range.min;
|
|
101
|
+
var aToB = diffEdge((0, _utils.xy)(destX, destY), a, b);
|
|
102
|
+
var dX = b.x < a.x ? domain.max : domain.min;
|
|
103
|
+
var dY = b.y < a.y ? range.max : range.min;
|
|
104
|
+
var bToA = diffEdge((0, _utils.xy)(dX, dY), b, a);
|
|
105
|
+
return [aToB, bToA];
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/** get length of side A of a triangle from H and angle Alpha */
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
exports.edges = edges;
|
|
112
|
+
|
|
113
|
+
var getOpposingSide = function getOpposingSide(hyp, angle) {
|
|
114
|
+
log('[getOpposingSide] hyp: ', hyp, 'angle:', angle);
|
|
115
|
+
return Math.abs(hyp * Math.sin(angle));
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.getOpposingSide = getOpposingSide;
|
|
119
|
+
|
|
120
|
+
var getShortestSide = function getShortestSide(xh, yh) {
|
|
121
|
+
if (Number.isFinite(xh) && Number.isFinite(yh)) {
|
|
122
|
+
if (xh === 0 && yh > 0) {
|
|
123
|
+
return 'y';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (yh === 0 && xh > 0) {
|
|
127
|
+
return 'x';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return xh < yh ? 'x' : 'y';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isNaN(xh) && !isNaN(yh)) {
|
|
134
|
+
return 'y';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!isNaN(xh) && isNaN(yh)) {
|
|
138
|
+
return 'x';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (xh === Infinity) {
|
|
142
|
+
return 'y';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (yh === Infinity) {
|
|
146
|
+
return 'x';
|
|
147
|
+
} // eslint-disable-next-line no-console
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
console.warn('hypotenuse - which is shorter? x:', xh, 'y:', yh);
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* return the difference between bounds and a as a Point
|
|
154
|
+
* @param {*} bounds
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
var diffEdge = function diffEdge(bounds, a, b) {
|
|
159
|
+
var l = log.enabled ? log.bind(log, "diffEdge: [".concat(a.x, ",").concat(a.y, " -> ").concat(b.x, ",").concat(b.y, "]")) : function () {};
|
|
160
|
+
var xRadians = angle(a, b);
|
|
161
|
+
l('x angle', toDegrees(xRadians));
|
|
162
|
+
var yRadians = Math.abs(xRadians - toRadians(90));
|
|
163
|
+
l('y angle', toDegrees(yRadians));
|
|
164
|
+
var xSide = Math.abs(a.x - bounds.x);
|
|
165
|
+
/**
|
|
166
|
+
* Draw 2 triangles:
|
|
167
|
+
* 1 with a horizontal line from a to the graph x edge
|
|
168
|
+
* 1 with a vertical line from a to the graph y edge
|
|
169
|
+
* Calculate the hypotenuse for both, whichever is shorter
|
|
170
|
+
* indicates that we should use that triangle to get the edge point.
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
var xH = hypotenuse(xSide, yRadians);
|
|
174
|
+
var ySide = Math.abs(a.y - bounds.y);
|
|
175
|
+
var yH = hypotenuse(ySide, xRadians);
|
|
176
|
+
l('x: side', xSide, 'h:', xH);
|
|
177
|
+
l('y: side', ySide, 'h:', yH);
|
|
178
|
+
var side = getShortestSide(xH, yH);
|
|
179
|
+
|
|
180
|
+
if (side !== 'x' && side !== 'y') {
|
|
181
|
+
throw new Error('Cant decide which hypotenuse to use');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var point = side === 'x' ? new _pointGeometry["default"](xSide, getOpposingSide(xH, xRadians)) : new _pointGeometry["default"](getOpposingSide(yH, yRadians), ySide);
|
|
185
|
+
l('point:', point);
|
|
186
|
+
var multiplier = new _pointGeometry["default"](b.x < a.x ? -1 : 1, b.y < a.y ? -1 : 1);
|
|
187
|
+
l('multiplier:', multiplier);
|
|
188
|
+
var out = point.multByPoint(multiplier);
|
|
189
|
+
l('out:', out);
|
|
190
|
+
var normalized = out.add(new _pointGeometry["default"](a.x, a.y));
|
|
191
|
+
l('normalized:', normalized);
|
|
192
|
+
return normalized;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
exports.diffEdge = diffEdge;
|
|
196
|
+
//# sourceMappingURL=trig.js.map
|