@pie-lib/plot 4.0.4-next.3 → 4.0.4-next.31
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/dist/_virtual/_rolldown/runtime.js +20 -0
- package/dist/draggable.d.ts +13 -0
- package/dist/draggable.js +13 -0
- package/dist/graph-props.d.ts +22 -0
- package/dist/graph-props.js +29 -0
- package/dist/grid-draggable.d.ts +91 -0
- package/dist/grid-draggable.js +168 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +8 -0
- package/dist/label.d.ts +30 -0
- package/dist/label.js +132 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
- package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js +503 -0
- package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/cjs.js +5 -0
- package/dist/root.d.ts +68 -0
- package/dist/root.js +302 -0
- package/dist/trig.d.ts +41 -0
- package/dist/trig.js +47 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.js +46 -0
- package/dist/utils.d.ts +44 -0
- package/dist/utils.js +82 -0
- package/package.json +35 -25
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -838
- package/LICENSE.md +0 -5
- package/lib/draggable.js +0 -44
- package/lib/draggable.js.map +0 -1
- package/lib/graph-props.js +0 -46
- package/lib/graph-props.js.map +0 -1
- package/lib/grid-draggable.js +0 -361
- package/lib/grid-draggable.js.map +0 -1
- package/lib/index.js +0 -44
- package/lib/index.js.map +0 -1
- package/lib/label.js +0 -173
- package/lib/label.js.map +0 -1
- package/lib/root.js +0 -474
- package/lib/root.js.map +0 -1
- package/lib/trig.js +0 -149
- package/lib/trig.js.map +0 -1
- package/lib/types.js +0 -40
- package/lib/types.js.map +0 -1
- package/lib/utils.js +0 -165
- package/lib/utils.js.map +0 -1
- package/src/__tests__/draggable.test.jsx +0 -41
- package/src/__tests__/grid-draggable.test.jsx +0 -487
- package/src/__tests__/root.test.jsx +0 -277
- package/src/__tests__/trig.test.js +0 -163
- package/src/__tests__/utils.test.js +0 -229
- package/src/draggable.jsx +0 -11
- package/src/graph-props.js +0 -34
- package/src/grid-draggable.jsx +0 -332
- package/src/index.js +0 -9
- package/src/label.jsx +0 -199
- package/src/root.jsx +0 -485
- package/src/trig.js +0 -151
- package/src/types.js +0 -41
- package/src/utils.js +0 -167
package/src/root.jsx
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { styled } from '@mui/material/styles';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { pointer, select } from 'd3-selection';
|
|
5
|
-
|
|
6
|
-
import { color, Readable } from '@pie-lib/render-ui';
|
|
7
|
-
import EditableHtml from '@pie-lib/editable-html-tip-tap';
|
|
8
|
-
import { ChildrenType, GraphPropsType } from './types';
|
|
9
|
-
import Label from './label';
|
|
10
|
-
import { extractTextFromHTML, isEmptyObject, isEmptyString } from './utils';
|
|
11
|
-
|
|
12
|
-
const centerPlaceholder = {
|
|
13
|
-
'& .ProseMirror p.is-editor-empty::before, & .ProseMirror div.is-editor-empty::before': {
|
|
14
|
-
left: 0,
|
|
15
|
-
right: 0,
|
|
16
|
-
width: '100%',
|
|
17
|
-
textAlign: 'center',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const StyledRoot = styled('div')(({ theme }) => ({
|
|
22
|
-
border: `solid 1px ${color.primaryLight()}`,
|
|
23
|
-
color: color.defaults.TEXT,
|
|
24
|
-
backgroundColor: theme.palette.common.white,
|
|
25
|
-
touchAction: 'none',
|
|
26
|
-
position: 'relative',
|
|
27
|
-
boxSizing: 'unset', // to override the default border-box in IBX that breaks the component width layout
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const Wrapper = styled('div')({
|
|
31
|
-
display: 'flex',
|
|
32
|
-
position: 'relative',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const DefineChartSvg = styled('svg')({
|
|
36
|
-
paddingLeft: '50px',
|
|
37
|
-
overflow: 'visible',
|
|
38
|
-
boxSizing: 'content-box',
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const ChartSvg = styled('svg')({
|
|
42
|
-
overflow: 'visible',
|
|
43
|
-
boxSizing: 'content-box',
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const GraphBox = styled('g')({
|
|
47
|
-
cursor: 'pointer',
|
|
48
|
-
userSelect: 'none',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const GraphTitle = styled('div')(({ theme }) => ({
|
|
52
|
-
color: color.defaults.TEXT,
|
|
53
|
-
fontSize: theme.typography.fontSize + 2,
|
|
54
|
-
padding: `${theme.spacing(1.5)} ${theme.spacing(0.5)} 0`,
|
|
55
|
-
textAlign: 'center',
|
|
56
|
-
'&.disabled': {
|
|
57
|
-
pointerEvents: 'none',
|
|
58
|
-
},
|
|
59
|
-
'&.rightMargin': {
|
|
60
|
-
marginRight: '74px',
|
|
61
|
-
},
|
|
62
|
-
'& p': {
|
|
63
|
-
margin: 0,
|
|
64
|
-
},
|
|
65
|
-
...centerPlaceholder,
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
const ChartTitle = styled('div')(({ theme }) => ({
|
|
69
|
-
color: color.defaults.TEXT,
|
|
70
|
-
fontSize: theme.typography.fontSize + 4,
|
|
71
|
-
padding: `${theme.spacing(1.5)} ${theme.spacing(0.5)} 0`,
|
|
72
|
-
textAlign: 'center',
|
|
73
|
-
'&.disabled': {
|
|
74
|
-
pointerEvents: 'none',
|
|
75
|
-
},
|
|
76
|
-
'&.rightMargin': {
|
|
77
|
-
marginRight: '74px',
|
|
78
|
-
},
|
|
79
|
-
'& p': {
|
|
80
|
-
margin: 0,
|
|
81
|
-
},
|
|
82
|
-
...centerPlaceholder,
|
|
83
|
-
}));
|
|
84
|
-
|
|
85
|
-
const TopPixelGuides = styled('div')({
|
|
86
|
-
display: 'flex',
|
|
87
|
-
paddingTop: '6px',
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const TopPixelIndicator = styled('div')({
|
|
91
|
-
display: 'flex',
|
|
92
|
-
flexDirection: 'column',
|
|
93
|
-
alignItems: 'center',
|
|
94
|
-
width: '100px',
|
|
95
|
-
pointerEvents: 'none',
|
|
96
|
-
userSelect: 'none',
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const SidePixelGuides = styled('div')({
|
|
100
|
-
width: '70px',
|
|
101
|
-
display: 'flex',
|
|
102
|
-
flexDirection: 'column',
|
|
103
|
-
marginRight: '6px',
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const SidePixelIndicator = styled('div')({
|
|
107
|
-
textAlign: 'right',
|
|
108
|
-
height: '20px',
|
|
109
|
-
pointerEvents: 'none',
|
|
110
|
-
userSelect: 'none',
|
|
111
|
-
'&:not(:last-child)': {
|
|
112
|
-
marginBottom: '80px',
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
export class Root extends React.Component {
|
|
117
|
-
constructor(props) {
|
|
118
|
-
super(props);
|
|
119
|
-
this.state = {
|
|
120
|
-
titleHeight: 0,
|
|
121
|
-
};
|
|
122
|
-
this.resizeObserver = null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
static propTypes = {
|
|
126
|
-
title: PropTypes.string,
|
|
127
|
-
children: ChildrenType,
|
|
128
|
-
defineChart: PropTypes.bool,
|
|
129
|
-
disabledLabels: PropTypes.bool,
|
|
130
|
-
disabledTitle: PropTypes.bool,
|
|
131
|
-
graphProps: GraphPropsType.isRequired,
|
|
132
|
-
isChart: PropTypes.bool,
|
|
133
|
-
labels: PropTypes.object,
|
|
134
|
-
labelsPlaceholders: PropTypes.object,
|
|
135
|
-
onChangeTitle: PropTypes.func,
|
|
136
|
-
onMouseMove: PropTypes.func,
|
|
137
|
-
showLabels: PropTypes.bool,
|
|
138
|
-
showTitle: PropTypes.bool,
|
|
139
|
-
showPixelGuides: PropTypes.bool,
|
|
140
|
-
rootRef: PropTypes.func,
|
|
141
|
-
onChangeLabels: PropTypes.func,
|
|
142
|
-
titlePlaceholder: PropTypes.string,
|
|
143
|
-
mathMlOptions: PropTypes.object,
|
|
144
|
-
labelsCharactersLimit: PropTypes.number,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
mouseMove = (g, event) => {
|
|
148
|
-
const { graphProps, onMouseMove } = this.props;
|
|
149
|
-
|
|
150
|
-
if (!onMouseMove) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const { scale, snap } = graphProps;
|
|
155
|
-
const coords = pointer(event, g.node());
|
|
156
|
-
const x = scale.x.invert(coords[0]);
|
|
157
|
-
const y = scale.y.invert(coords[1]);
|
|
158
|
-
|
|
159
|
-
const snapped = {
|
|
160
|
-
x: snap.x(x),
|
|
161
|
-
y: snap.y(y),
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
onMouseMove(snapped);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
componentDidMount() {
|
|
168
|
-
const g = select(this.g);
|
|
169
|
-
g.on('mousemove', this.mouseMove.bind(this, g));
|
|
170
|
-
this.measureTitleHeight();
|
|
171
|
-
this.setupVisibilityObserver();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
componentWillUnmount() {
|
|
175
|
-
const g = select(this.g);
|
|
176
|
-
g.on('mousemove', null);
|
|
177
|
-
this.cleanupVisibilityObserver();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
componentDidUpdate(prevProps) {
|
|
181
|
-
if (prevProps.title !== this.props.title) {
|
|
182
|
-
this.measureTitleHeight();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
onChangeLabel = (newValue, side) => {
|
|
187
|
-
const { labels, onChangeLabels, isChart } = this.props;
|
|
188
|
-
|
|
189
|
-
if (!onChangeLabels) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (isChart) {
|
|
194
|
-
if (side === 'left') {
|
|
195
|
-
onChangeLabels('range', newValue);
|
|
196
|
-
} else {
|
|
197
|
-
onChangeLabels('domain', newValue);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
onChangeLabels({
|
|
204
|
-
...labels,
|
|
205
|
-
[side]: newValue,
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
measureTitleHeight = () => {
|
|
210
|
-
const titleElement = this.titleRef;
|
|
211
|
-
if (titleElement) {
|
|
212
|
-
const titleHeight = titleElement.clientHeight;
|
|
213
|
-
this.setState({ titleHeight, prevTitle: this.props.title });
|
|
214
|
-
|
|
215
|
-
if (!this.resizeObserver && typeof ResizeObserver !== 'undefined') {
|
|
216
|
-
this.setupVisibilityObserver();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
handleKeyDown = () => {
|
|
222
|
-
setTimeout(() => {
|
|
223
|
-
this.measureTitleHeight();
|
|
224
|
-
}, 0);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// handle edge case where chart is hidden with display:none and then shown with display:block
|
|
228
|
-
setupVisibilityObserver = () => {
|
|
229
|
-
if (typeof ResizeObserver !== 'undefined' && this.titleRef) {
|
|
230
|
-
this.resizeObserver = new ResizeObserver((entries) => {
|
|
231
|
-
for (let entry of entries) {
|
|
232
|
-
const { width, height } = entry.contentRect;
|
|
233
|
-
// trigger if element becomes visible and we haven't measured this height yet
|
|
234
|
-
if (width > 0 && height > 0) {
|
|
235
|
-
setTimeout(() => {
|
|
236
|
-
this.measureTitleHeight();
|
|
237
|
-
}, 10);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
this.resizeObserver.observe(this.titleRef);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
cleanupVisibilityObserver = () => {
|
|
248
|
-
if (this.resizeObserver) {
|
|
249
|
-
this.resizeObserver.disconnect();
|
|
250
|
-
this.resizeObserver = null;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
render() {
|
|
255
|
-
const {
|
|
256
|
-
disabledTitle,
|
|
257
|
-
disabledLabels,
|
|
258
|
-
labels,
|
|
259
|
-
labelsPlaceholders,
|
|
260
|
-
titlePlaceholder,
|
|
261
|
-
graphProps,
|
|
262
|
-
children,
|
|
263
|
-
defineChart,
|
|
264
|
-
onChangeTitle,
|
|
265
|
-
isChart,
|
|
266
|
-
showLabels,
|
|
267
|
-
showPixelGuides,
|
|
268
|
-
showTitle,
|
|
269
|
-
title,
|
|
270
|
-
rootRef,
|
|
271
|
-
mathMlOptions = {},
|
|
272
|
-
labelsCharactersLimit,
|
|
273
|
-
} = this.props;
|
|
274
|
-
const {
|
|
275
|
-
size: { width = 500, height = 500 },
|
|
276
|
-
domain,
|
|
277
|
-
range,
|
|
278
|
-
} = graphProps;
|
|
279
|
-
|
|
280
|
-
const topPadding = 40;
|
|
281
|
-
const leftPadding = isEmptyString(extractTextFromHTML(labels?.left)) && isEmptyObject(labelsPlaceholders) ? 48 : 70;
|
|
282
|
-
const rightPadding =
|
|
283
|
-
isEmptyString(extractTextFromHTML(labels?.right)) && isEmptyObject(labelsPlaceholders) ? 48 : 70;
|
|
284
|
-
const finalWidth = width + leftPadding + rightPadding + (domain.padding || 0) * 2;
|
|
285
|
-
const finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
|
|
286
|
-
|
|
287
|
-
const activeTitlePlugins = [
|
|
288
|
-
'bold',
|
|
289
|
-
'italic',
|
|
290
|
-
'underline',
|
|
291
|
-
'superscript',
|
|
292
|
-
'subscript',
|
|
293
|
-
'strikethrough',
|
|
294
|
-
'math',
|
|
295
|
-
// 'languageCharacters'
|
|
296
|
-
];
|
|
297
|
-
|
|
298
|
-
const actualHeight = defineChart && showPixelGuides ? height - 160 : height;
|
|
299
|
-
const nbOfVerticalLines = parseInt(width / 100);
|
|
300
|
-
const nbOfHorizontalLines = parseInt(actualHeight / 100);
|
|
301
|
-
const sideGridlinesPadding = parseInt(actualHeight % 100);
|
|
302
|
-
const { titleHeight } = this.state;
|
|
303
|
-
|
|
304
|
-
return (
|
|
305
|
-
<StyledRoot>
|
|
306
|
-
{showPixelGuides && (
|
|
307
|
-
<TopPixelGuides style={{ marginLeft: isChart ? 80 : showLabels ? 30 : 10 }}>
|
|
308
|
-
{[...Array(nbOfVerticalLines + 1).keys()].map((value) => (
|
|
309
|
-
<Readable false key={`top-guide-${value}`}>
|
|
310
|
-
<TopPixelIndicator>
|
|
311
|
-
<div>{value * 100}px</div>
|
|
312
|
-
<div>|</div>
|
|
313
|
-
</TopPixelIndicator>
|
|
314
|
-
</Readable>
|
|
315
|
-
))}
|
|
316
|
-
</TopPixelGuides>
|
|
317
|
-
)}
|
|
318
|
-
{showTitle &&
|
|
319
|
-
(disabledTitle ? (
|
|
320
|
-
<div
|
|
321
|
-
ref={(r) => (this.titleRef = r)}
|
|
322
|
-
style={{
|
|
323
|
-
...(isChart && { width: finalWidth }),
|
|
324
|
-
...(isEmptyString(extractTextFromHTML(title)) && { display: 'none' }),
|
|
325
|
-
}}
|
|
326
|
-
>
|
|
327
|
-
{isChart ? (
|
|
328
|
-
<ChartTitle className="disabled" dangerouslySetInnerHTML={{ __html: title || '' }} />
|
|
329
|
-
) : (
|
|
330
|
-
<GraphTitle className="disabled" dangerouslySetInnerHTML={{ __html: title || '' }} />
|
|
331
|
-
)}
|
|
332
|
-
</div>
|
|
333
|
-
) : (
|
|
334
|
-
<div ref={(r) => (this.titleRef = r)}>
|
|
335
|
-
{isChart ? (
|
|
336
|
-
<ChartTitle className={showPixelGuides ? 'rightMargin' : ''}>
|
|
337
|
-
<EditableHtml
|
|
338
|
-
{...(isChart && {
|
|
339
|
-
width: finalWidth,
|
|
340
|
-
})}
|
|
341
|
-
markup={title || ''}
|
|
342
|
-
onChange={onChangeTitle}
|
|
343
|
-
placeholder={
|
|
344
|
-
(defineChart && titlePlaceholder) ||
|
|
345
|
-
(!disabledTitle && 'Click here to add a title for this graph')
|
|
346
|
-
}
|
|
347
|
-
toolbarOpts={{ noPadding: true, noBorder: true }}
|
|
348
|
-
activePlugins={activeTitlePlugins}
|
|
349
|
-
disableScrollbar
|
|
350
|
-
onKeyDown={this.handleKeyDown}
|
|
351
|
-
/>
|
|
352
|
-
</ChartTitle>
|
|
353
|
-
) : (
|
|
354
|
-
<GraphTitle className={showPixelGuides ? 'rightMargin' : ''}>
|
|
355
|
-
<EditableHtml
|
|
356
|
-
{...(isChart && {
|
|
357
|
-
width: finalWidth,
|
|
358
|
-
})}
|
|
359
|
-
markup={title || ''}
|
|
360
|
-
onChange={onChangeTitle}
|
|
361
|
-
placeholder={
|
|
362
|
-
(defineChart && titlePlaceholder) ||
|
|
363
|
-
(!disabledTitle && 'Click here to add a title for this graph')
|
|
364
|
-
}
|
|
365
|
-
toolbarOpts={{ noPadding: true, noBorder: true }}
|
|
366
|
-
activePlugins={activeTitlePlugins}
|
|
367
|
-
disableScrollbar
|
|
368
|
-
onKeyDown={this.handleKeyDown}
|
|
369
|
-
/>
|
|
370
|
-
</GraphTitle>
|
|
371
|
-
)}
|
|
372
|
-
</div>
|
|
373
|
-
))}
|
|
374
|
-
{showLabels && !isChart && (
|
|
375
|
-
<Label
|
|
376
|
-
side="top"
|
|
377
|
-
text={labels.top}
|
|
378
|
-
disabledLabel={disabledLabels}
|
|
379
|
-
placeholder={labelsPlaceholders?.top}
|
|
380
|
-
graphHeight={finalHeight}
|
|
381
|
-
graphWidth={finalWidth}
|
|
382
|
-
onChange={(value) => this.onChangeLabel(value, 'top')}
|
|
383
|
-
mathMlOptions={mathMlOptions}
|
|
384
|
-
preventNewLines={true}
|
|
385
|
-
charactersLimit={labelsCharactersLimit}
|
|
386
|
-
/>
|
|
387
|
-
)}
|
|
388
|
-
<Wrapper>
|
|
389
|
-
{showLabels && (
|
|
390
|
-
<Label
|
|
391
|
-
side="left"
|
|
392
|
-
text={labels.left}
|
|
393
|
-
disabledLabel={disabledLabels}
|
|
394
|
-
placeholder={labelsPlaceholders?.left}
|
|
395
|
-
graphHeight={finalHeight}
|
|
396
|
-
graphWidth={finalWidth}
|
|
397
|
-
isChartLeftLabel={isChart && !defineChart}
|
|
398
|
-
isDefineChartLeftLabel={isChart && defineChart}
|
|
399
|
-
onChange={(value) => this.onChangeLabel(value, 'left')}
|
|
400
|
-
mathMlOptions={mathMlOptions}
|
|
401
|
-
preventNewLines={true}
|
|
402
|
-
charactersLimit={labelsCharactersLimit}
|
|
403
|
-
/>
|
|
404
|
-
)}
|
|
405
|
-
{defineChart ? (
|
|
406
|
-
<DefineChartSvg width={finalWidth} height={finalHeight}>
|
|
407
|
-
<GraphBox
|
|
408
|
-
ref={(r) => {
|
|
409
|
-
this.g = r;
|
|
410
|
-
if (rootRef) {
|
|
411
|
-
rootRef(r);
|
|
412
|
-
}
|
|
413
|
-
}}
|
|
414
|
-
transform={`translate(${leftPadding + (domain.padding || 0)}, ${topPadding + (range.padding || 0)})`}
|
|
415
|
-
>
|
|
416
|
-
{children}
|
|
417
|
-
</GraphBox>
|
|
418
|
-
</DefineChartSvg>
|
|
419
|
-
) : (
|
|
420
|
-
<ChartSvg width={finalWidth} height={finalHeight}>
|
|
421
|
-
<GraphBox
|
|
422
|
-
ref={(r) => {
|
|
423
|
-
this.g = r;
|
|
424
|
-
if (rootRef) {
|
|
425
|
-
rootRef(r);
|
|
426
|
-
}
|
|
427
|
-
}}
|
|
428
|
-
transform={`translate(${leftPadding + (domain.padding || 0)}, ${topPadding + (range.padding || 0)})`}
|
|
429
|
-
>
|
|
430
|
-
{children}
|
|
431
|
-
</GraphBox>
|
|
432
|
-
</ChartSvg>
|
|
433
|
-
)}
|
|
434
|
-
{showLabels && !isChart && (
|
|
435
|
-
<Label
|
|
436
|
-
side="right"
|
|
437
|
-
text={labels.right}
|
|
438
|
-
disabledLabel={disabledLabels}
|
|
439
|
-
placeholder={labelsPlaceholders?.right}
|
|
440
|
-
graphHeight={finalHeight}
|
|
441
|
-
graphWidth={finalWidth}
|
|
442
|
-
onChange={(value) => this.onChangeLabel(value, 'right')}
|
|
443
|
-
mathMlOptions={mathMlOptions}
|
|
444
|
-
preventNewLines={true}
|
|
445
|
-
charactersLimit={labelsCharactersLimit}
|
|
446
|
-
/>
|
|
447
|
-
)}
|
|
448
|
-
{showPixelGuides && (
|
|
449
|
-
<SidePixelGuides
|
|
450
|
-
style={{
|
|
451
|
-
paddingTop: sideGridlinesPadding,
|
|
452
|
-
marginTop: 31,
|
|
453
|
-
}}
|
|
454
|
-
>
|
|
455
|
-
{[...Array(nbOfHorizontalLines + 1).keys()].reverse().map((value) => (
|
|
456
|
-
<Readable false key={`top-guide-${value}`}>
|
|
457
|
-
<SidePixelIndicator>━ {value * 100}px</SidePixelIndicator>
|
|
458
|
-
</Readable>
|
|
459
|
-
))}
|
|
460
|
-
</SidePixelGuides>
|
|
461
|
-
)}
|
|
462
|
-
</Wrapper>
|
|
463
|
-
{showLabels && (
|
|
464
|
-
<Label
|
|
465
|
-
side="bottom"
|
|
466
|
-
text={labels.bottom}
|
|
467
|
-
disabledLabel={disabledLabels}
|
|
468
|
-
placeholder={labelsPlaceholders?.bottom}
|
|
469
|
-
graphHeight={finalHeight}
|
|
470
|
-
graphWidth={finalWidth}
|
|
471
|
-
titleHeight={titleHeight}
|
|
472
|
-
isChartBottomLabel={isChart && !defineChart}
|
|
473
|
-
isDefineChartBottomLabel={isChart && defineChart}
|
|
474
|
-
onChange={(value) => this.onChangeLabel(value, 'bottom')}
|
|
475
|
-
mathMlOptions={mathMlOptions}
|
|
476
|
-
preventNewLines={true}
|
|
477
|
-
charactersLimit={labelsCharactersLimit}
|
|
478
|
-
/>
|
|
479
|
-
)}
|
|
480
|
-
</StyledRoot>
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
export default Root;
|
package/src/trig.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { xy } from './utils';
|
|
2
|
-
import Point from '@mapbox/point-geometry';
|
|
3
|
-
import debug from 'debug';
|
|
4
|
-
|
|
5
|
-
const log = debug('pie-lib:plot:trig');
|
|
6
|
-
|
|
7
|
-
export const toDegrees = (radians) => radians * (180 / Math.PI);
|
|
8
|
-
export const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
9
|
-
/**
|
|
10
|
-
* return angle in radians between 2 points using counting degrees counter clockwise
|
|
11
|
-
*
|
|
12
|
-
* 0,0 + 1,1 = 45 in radians
|
|
13
|
-
* 1,1 + 0,0 = 45?
|
|
14
|
-
* @param {Point} a
|
|
15
|
-
* @param {Point} b
|
|
16
|
-
*/
|
|
17
|
-
export const angle = (a, b) => {
|
|
18
|
-
const vd = b.y - a.y;
|
|
19
|
-
const hd = b.x - a.x;
|
|
20
|
-
log(a, b, 'vd: ', vd, 'hd: ', hd);
|
|
21
|
-
const radians = Math.atan2(vd, hd);
|
|
22
|
-
return radians < 0 ? radians + Math.PI * 2 : radians;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const NINETY = Math.PI / 2;
|
|
26
|
-
const ONE_EIGHTY = Math.PI;
|
|
27
|
-
const TWO_SEVENTY = ONE_EIGHTY + NINETY;
|
|
28
|
-
|
|
29
|
-
export const acuteXAngle = (a) => {
|
|
30
|
-
log(toDegrees(a));
|
|
31
|
-
|
|
32
|
-
if (a < NINETY) {
|
|
33
|
-
return a;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (a < ONE_EIGHTY) {
|
|
37
|
-
return Math.abs(ONE_EIGHTY - a);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (a < TWO_SEVENTY) {
|
|
41
|
-
return Math.abs(ONE_EIGHTY - a);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return Math.abs(Math.PI * 2 - a);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const acuteYAngle = (a) => NINETY - acuteXAngle(a);
|
|
48
|
-
|
|
49
|
-
export const hypotenuse = (a, alpha) => {
|
|
50
|
-
const out = Math.abs(a / Math.sin(alpha));
|
|
51
|
-
|
|
52
|
-
return out;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* return 2 edge points for a,b within domain + range.
|
|
57
|
-
* - one edge is from following a -> b to the bounds
|
|
58
|
-
* - one edge is from following b -> a to the bounds
|
|
59
|
-
* @param {{min: number, max: number}} domain
|
|
60
|
-
* @param {{min: number, max: number}} range
|
|
61
|
-
* @param {{x: number, y: number}} a
|
|
62
|
-
* @param {{x: number, y: number}} b
|
|
63
|
-
* @returns [{x: number, y: number}, {x: number, y: number}]
|
|
64
|
-
*/
|
|
65
|
-
export const edges = (domain, range) => (a, b) => {
|
|
66
|
-
// const xDest =
|
|
67
|
-
const destX = a.x < b.x ? domain.max : domain.min;
|
|
68
|
-
const destY = a.y < b.y ? range.max : range.min;
|
|
69
|
-
const aToB = diffEdge(xy(destX, destY), a, b);
|
|
70
|
-
|
|
71
|
-
const dX = b.x < a.x ? domain.max : domain.min;
|
|
72
|
-
const dY = b.y < a.y ? range.max : range.min;
|
|
73
|
-
const bToA = diffEdge(xy(dX, dY), b, a);
|
|
74
|
-
return [aToB, bToA];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** get length of side A of a triangle from H and angle Alpha */
|
|
78
|
-
export const getOpposingSide = (hyp, angle) => {
|
|
79
|
-
log('[getOpposingSide] hyp: ', hyp, 'angle:', angle);
|
|
80
|
-
return Math.abs(hyp * Math.sin(angle));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getShortestSide = (xh, yh) => {
|
|
84
|
-
if (Number.isFinite(xh) && Number.isFinite(yh)) {
|
|
85
|
-
if (xh === 0 && yh > 0) {
|
|
86
|
-
return 'y';
|
|
87
|
-
}
|
|
88
|
-
if (yh === 0 && xh > 0) {
|
|
89
|
-
return 'x';
|
|
90
|
-
}
|
|
91
|
-
return xh < yh ? 'x' : 'y';
|
|
92
|
-
}
|
|
93
|
-
if (isNaN(xh) && !isNaN(yh)) {
|
|
94
|
-
return 'y';
|
|
95
|
-
}
|
|
96
|
-
if (!isNaN(xh) && isNaN(yh)) {
|
|
97
|
-
return 'x';
|
|
98
|
-
}
|
|
99
|
-
if (xh === Infinity) {
|
|
100
|
-
return 'y';
|
|
101
|
-
}
|
|
102
|
-
if (yh === Infinity) {
|
|
103
|
-
return 'x';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// eslint-disable-next-line no-console
|
|
107
|
-
console.warn('hypotenuse - which is shorter? x:', xh, 'y:', yh);
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* return the difference between bounds and a as a Point
|
|
111
|
-
* @param {*} bounds
|
|
112
|
-
*/
|
|
113
|
-
export const diffEdge = (bounds, a, b) => {
|
|
114
|
-
let l = log.enabled ? log.bind(log, `diffEdge: [${a.x},${a.y} -> ${b.x},${b.y}]`) : () => {};
|
|
115
|
-
const xRadians = angle(a, b);
|
|
116
|
-
l('x angle', toDegrees(xRadians));
|
|
117
|
-
const yRadians = Math.abs(xRadians - toRadians(90));
|
|
118
|
-
l('y angle', toDegrees(yRadians));
|
|
119
|
-
const xSide = Math.abs(a.x - bounds.x);
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Draw 2 triangles:
|
|
123
|
-
* 1 with a horizontal line from a to the graph x edge
|
|
124
|
-
* 1 with a vertical line from a to the graph y edge
|
|
125
|
-
* Calculate the hypotenuse for both, whichever is shorter
|
|
126
|
-
* indicates that we should use that triangle to get the edge point.
|
|
127
|
-
*/
|
|
128
|
-
const xH = hypotenuse(xSide, yRadians);
|
|
129
|
-
|
|
130
|
-
const ySide = Math.abs(a.y - bounds.y);
|
|
131
|
-
const yH = hypotenuse(ySide, xRadians);
|
|
132
|
-
|
|
133
|
-
l('x: side', xSide, 'h:', xH);
|
|
134
|
-
l('y: side', ySide, 'h:', yH);
|
|
135
|
-
const side = getShortestSide(xH, yH);
|
|
136
|
-
|
|
137
|
-
if (side !== 'x' && side !== 'y') {
|
|
138
|
-
throw new Error('Cant decide which hypotenuse to use');
|
|
139
|
-
}
|
|
140
|
-
const point =
|
|
141
|
-
side === 'x' ? new Point(xSide, getOpposingSide(xH, xRadians)) : new Point(getOpposingSide(yH, yRadians), ySide);
|
|
142
|
-
|
|
143
|
-
l('point:', point);
|
|
144
|
-
const multiplier = new Point(b.x < a.x ? -1 : 1, b.y < a.y ? -1 : 1);
|
|
145
|
-
l('multiplier:', multiplier);
|
|
146
|
-
const out = point.multByPoint(multiplier);
|
|
147
|
-
l('out:', out);
|
|
148
|
-
const normalized = out.add(new Point(a.x, a.y));
|
|
149
|
-
l('normalized:', normalized);
|
|
150
|
-
return normalized;
|
|
151
|
-
};
|
package/src/types.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
|
|
3
|
-
export const BaseDomainRangeType = {
|
|
4
|
-
min: PropTypes.number.isRequired,
|
|
5
|
-
max: PropTypes.number.isRequired,
|
|
6
|
-
step: PropTypes.number,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const DomainType = PropTypes.shape(BaseDomainRangeType);
|
|
10
|
-
|
|
11
|
-
export const RangeType = PropTypes.shape(BaseDomainRangeType);
|
|
12
|
-
|
|
13
|
-
export const SizeType = PropTypes.shape({
|
|
14
|
-
width: PropTypes.number.isRequired,
|
|
15
|
-
height: PropTypes.number.isRequired,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export const PointType = PropTypes.shape({
|
|
19
|
-
x: PropTypes.number.isRequired,
|
|
20
|
-
y: PropTypes.number.isRequired,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const ChildrenType = PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired;
|
|
24
|
-
|
|
25
|
-
export const ScaleType = PropTypes.shape({
|
|
26
|
-
x: PropTypes.func.isRequired,
|
|
27
|
-
y: PropTypes.func.isRequired,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export const SnapType = PropTypes.shape({
|
|
31
|
-
x: PropTypes.func.isRequired,
|
|
32
|
-
y: PropTypes.func.isRequired,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const GraphPropsType = PropTypes.shape({
|
|
36
|
-
scale: ScaleType.isRequired,
|
|
37
|
-
snap: SnapType.isRequired,
|
|
38
|
-
domain: DomainType.isRequired,
|
|
39
|
-
range: RangeType.isRequired,
|
|
40
|
-
size: SizeType.isRequired,
|
|
41
|
-
});
|