@pie-lib/charting 5.4.1-next.0 → 5.4.2-next.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 +8 -0
- package/lib/axes.js.map +1 -1
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart-setup.js.map +1 -1
- package/lib/chart-type.js.map +1 -1
- package/lib/chart.js.map +1 -1
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/styles.js.map +1 -1
- package/lib/grid.js.map +1 -1
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/axes.jsx +44 -60
- package/src/bars/bar.js +2 -2
- package/src/bars/common/bars.jsx +11 -26
- package/src/bars/histogram.js +2 -2
- package/src/chart-setup.jsx +31 -37
- package/src/chart-type.js +5 -10
- package/src/chart.jsx +35 -53
- package/src/common/drag-handle.jsx +16 -36
- package/src/common/styles.js +3 -3
- package/src/grid.jsx +3 -3
- package/src/line/common/drag-handle.jsx +10 -10
- package/src/line/common/line.jsx +17 -19
- package/src/line/line-cross.js +18 -15
- package/src/line/line-dot.js +4 -4
- package/src/mark-label.jsx +16 -21
- package/src/plot/common/plot.jsx +15 -25
- package/src/plot/dot.js +5 -13
- package/src/plot/line.js +16 -10
- package/src/tool-menu.jsx +13 -13
- package/src/utils.js +14 -14
package/src/axes.jsx
CHANGED
|
@@ -14,17 +14,17 @@ export class TickComponent extends React.Component {
|
|
|
14
14
|
super(props);
|
|
15
15
|
this.state = {
|
|
16
16
|
dialog: {
|
|
17
|
-
open: false
|
|
18
|
-
}
|
|
17
|
+
open: false,
|
|
18
|
+
},
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
handleAlertDialog = (open, callback) =>
|
|
23
23
|
this.setState(
|
|
24
24
|
{
|
|
25
|
-
dialog: { open }
|
|
25
|
+
dialog: { open },
|
|
26
26
|
},
|
|
27
|
-
callback
|
|
27
|
+
callback,
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
changeCategory = (index, newLabel) => {
|
|
@@ -34,7 +34,7 @@ export class TickComponent extends React.Component {
|
|
|
34
34
|
onChangeCategory(index, { ...category, label: newLabel });
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
deleteCategory = index => {
|
|
37
|
+
deleteCategory = (index) => {
|
|
38
38
|
const { categories, onChange } = this.props;
|
|
39
39
|
|
|
40
40
|
if (index >= 0 && categories[index]) {
|
|
@@ -51,15 +51,11 @@ export class TickComponent extends React.Component {
|
|
|
51
51
|
dialog: {
|
|
52
52
|
open: true,
|
|
53
53
|
title: 'Warning',
|
|
54
|
-
text:
|
|
55
|
-
'This will remove the correct answer value that has been defined for this category.',
|
|
54
|
+
text: 'This will remove the correct answer value that has been defined for this category.',
|
|
56
55
|
onConfirm: () =>
|
|
57
|
-
this.handleAlertDialog(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
),
|
|
61
|
-
onClose: () => this.handleAlertDialog(false)
|
|
62
|
-
}
|
|
56
|
+
this.handleAlertDialog(false, onChangeCategory(index, { ...category, interactive: !category.interactive })),
|
|
57
|
+
onClose: () => this.handleAlertDialog(false),
|
|
58
|
+
},
|
|
63
59
|
});
|
|
64
60
|
} else {
|
|
65
61
|
onChangeCategory(index, { ...category, interactive: !category.interactive });
|
|
@@ -75,15 +71,14 @@ export class TickComponent extends React.Component {
|
|
|
75
71
|
dialog: {
|
|
76
72
|
open: true,
|
|
77
73
|
title: 'Warning',
|
|
78
|
-
text:
|
|
79
|
-
'This will remove the correct answer category name that has been defined for this category.',
|
|
74
|
+
text: 'This will remove the correct answer category name that has been defined for this category.',
|
|
80
75
|
onConfirm: () =>
|
|
81
76
|
this.handleAlertDialog(
|
|
82
77
|
false,
|
|
83
|
-
onChangeCategory(index, { ...category, editable: !category.editable || false })
|
|
78
|
+
onChangeCategory(index, { ...category, editable: !category.editable || false }),
|
|
84
79
|
),
|
|
85
|
-
onClose: () => this.handleAlertDialog(false)
|
|
86
|
-
}
|
|
80
|
+
onClose: () => this.handleAlertDialog(false),
|
|
81
|
+
},
|
|
87
82
|
});
|
|
88
83
|
} else {
|
|
89
84
|
onChangeCategory(index, { ...category, editable: !category.editable || false });
|
|
@@ -104,7 +99,7 @@ export class TickComponent extends React.Component {
|
|
|
104
99
|
x,
|
|
105
100
|
y,
|
|
106
101
|
formattedValue,
|
|
107
|
-
error
|
|
102
|
+
error,
|
|
108
103
|
} = this.props;
|
|
109
104
|
|
|
110
105
|
if (!formattedValue) {
|
|
@@ -114,8 +109,7 @@ export class TickComponent extends React.Component {
|
|
|
114
109
|
const { dialog } = this.state;
|
|
115
110
|
const index = parseInt(formattedValue.split('-')[0], 10);
|
|
116
111
|
const category = categories[index];
|
|
117
|
-
const { deletable, editable, interactive, label, correctness, autoFocus, inDefineChart } =
|
|
118
|
-
category || {};
|
|
112
|
+
const { deletable, editable, interactive, label, correctness, autoFocus, inDefineChart } = category || {};
|
|
119
113
|
const barX = xBand(bandKey({ label }, index));
|
|
120
114
|
const longestCategory = (categories || []).reduce((a, b) => {
|
|
121
115
|
const lengthA = a && a.label ? a.label.length : 0;
|
|
@@ -144,7 +138,7 @@ export class TickComponent extends React.Component {
|
|
|
144
138
|
wordBreak: 'break-word',
|
|
145
139
|
overflow: 'visible',
|
|
146
140
|
maxWidth: barWidth,
|
|
147
|
-
display: 'block'
|
|
141
|
+
display: 'block',
|
|
148
142
|
}}
|
|
149
143
|
>
|
|
150
144
|
{longestLabel}
|
|
@@ -152,11 +146,11 @@ export class TickComponent extends React.Component {
|
|
|
152
146
|
)}
|
|
153
147
|
<MarkLabel
|
|
154
148
|
autoFocus={inDefineChart ? defineChart && autoFocus : autoFocus}
|
|
155
|
-
inputRef={r => (this.input = r)}
|
|
149
|
+
inputRef={(r) => (this.input = r)}
|
|
156
150
|
disabled={!defineChart && !editable}
|
|
157
151
|
mark={category}
|
|
158
152
|
graphProps={graphProps}
|
|
159
|
-
onChange={newLabel => this.changeCategory(index, newLabel)}
|
|
153
|
+
onChange={(newLabel) => this.changeCategory(index, newLabel)}
|
|
160
154
|
barWidth={barWidth}
|
|
161
155
|
rotate={rotate}
|
|
162
156
|
correctness={correctness}
|
|
@@ -169,14 +163,7 @@ export class TickComponent extends React.Component {
|
|
|
169
163
|
</text>
|
|
170
164
|
)}
|
|
171
165
|
{deletable && !correctness && (
|
|
172
|
-
<line
|
|
173
|
-
x1={x}
|
|
174
|
-
y1={0}
|
|
175
|
-
x2={x}
|
|
176
|
-
y2={y + 4 + top}
|
|
177
|
-
className={classes.dottedLine}
|
|
178
|
-
strokeDasharray="4 2"
|
|
179
|
-
/>
|
|
166
|
+
<line x1={x} y1={0} x2={x} y2={y + 4 + top} className={classes.dottedLine} strokeDasharray="4 2" />
|
|
180
167
|
)}
|
|
181
168
|
{deletable && !correctness && (
|
|
182
169
|
<svg
|
|
@@ -195,7 +182,7 @@ export class TickComponent extends React.Component {
|
|
|
195
182
|
<svg
|
|
196
183
|
x={-55}
|
|
197
184
|
style={{
|
|
198
|
-
overflow: 'visible'
|
|
185
|
+
overflow: 'visible',
|
|
199
186
|
}}
|
|
200
187
|
>
|
|
201
188
|
<text
|
|
@@ -207,7 +194,7 @@ export class TickComponent extends React.Component {
|
|
|
207
194
|
pointerEvents: 'none',
|
|
208
195
|
wordBreak: 'break-word',
|
|
209
196
|
maxWidth: barWidth,
|
|
210
|
-
display: 'inline-block'
|
|
197
|
+
display: 'inline-block',
|
|
211
198
|
}}
|
|
212
199
|
>
|
|
213
200
|
<tspan x="0" dy=".6em">
|
|
@@ -228,7 +215,7 @@ export class TickComponent extends React.Component {
|
|
|
228
215
|
pointerEvents: 'none',
|
|
229
216
|
wordBreak: 'break-word',
|
|
230
217
|
maxWidth: barWidth,
|
|
231
|
-
display: 'inline-block'
|
|
218
|
+
display: 'inline-block',
|
|
232
219
|
}}
|
|
233
220
|
>
|
|
234
221
|
<tspan x="0" dy=".6em">
|
|
@@ -253,7 +240,7 @@ export class TickComponent extends React.Component {
|
|
|
253
240
|
<Checkbox
|
|
254
241
|
style={{ position: 'fixed' }}
|
|
255
242
|
checked={interactive}
|
|
256
|
-
onChange={e => this.changeInteractive(index, e.target.checked)}
|
|
243
|
+
onChange={(e) => this.changeInteractive(index, e.target.checked)}
|
|
257
244
|
/>
|
|
258
245
|
</foreignObject>
|
|
259
246
|
)}
|
|
@@ -268,7 +255,7 @@ export class TickComponent extends React.Component {
|
|
|
268
255
|
<Checkbox
|
|
269
256
|
style={{ position: 'fixed' }}
|
|
270
257
|
checked={editable}
|
|
271
|
-
onChange={e => this.changeEditable(index, e.target.checked)}
|
|
258
|
+
onChange={(e) => this.changeEditable(index, e.target.checked)}
|
|
272
259
|
/>
|
|
273
260
|
</foreignObject>
|
|
274
261
|
)}
|
|
@@ -305,7 +292,7 @@ TickComponent.propTypes = {
|
|
|
305
292
|
formattedValue: PropTypes.string,
|
|
306
293
|
onChangeCategory: PropTypes.func,
|
|
307
294
|
onChange: PropTypes.func,
|
|
308
|
-
classes: PropTypes.object
|
|
295
|
+
classes: PropTypes.object,
|
|
309
296
|
};
|
|
310
297
|
|
|
311
298
|
export class RawChartAxes extends React.Component {
|
|
@@ -319,15 +306,13 @@ export class RawChartAxes extends React.Component {
|
|
|
319
306
|
onChange: PropTypes.func,
|
|
320
307
|
onChangeCategory: PropTypes.func,
|
|
321
308
|
top: PropTypes.number,
|
|
322
|
-
theme: PropTypes.object
|
|
309
|
+
theme: PropTypes.object,
|
|
323
310
|
};
|
|
324
311
|
|
|
325
312
|
state = { height: 0 };
|
|
326
313
|
|
|
327
314
|
componentDidMount() {
|
|
328
|
-
const height = document.getElementById('hiddenLabel')
|
|
329
|
-
? document.getElementById('hiddenLabel').offsetHeight
|
|
330
|
-
: 0;
|
|
315
|
+
const height = document.getElementById('hiddenLabel') ? document.getElementById('hiddenLabel').offsetHeight : 0;
|
|
331
316
|
|
|
332
317
|
this.setState({ height });
|
|
333
318
|
}
|
|
@@ -344,15 +329,14 @@ export class RawChartAxes extends React.Component {
|
|
|
344
329
|
top,
|
|
345
330
|
defineChart,
|
|
346
331
|
theme,
|
|
347
|
-
error
|
|
332
|
+
error,
|
|
348
333
|
} = this.props;
|
|
349
334
|
|
|
350
335
|
const { axis, axisLine, tick } = classes;
|
|
351
336
|
const { scale = {}, range = {}, domain = {}, size = {} } = graphProps || {};
|
|
352
337
|
const { height } = this.state;
|
|
353
338
|
|
|
354
|
-
const bottomScale =
|
|
355
|
-
xBand && typeof xBand.rangeRound === 'function' && xBand.rangeRound([0, size.width]);
|
|
339
|
+
const bottomScale = xBand && typeof xBand.rangeRound === 'function' && xBand.rangeRound([0, size.width]);
|
|
356
340
|
|
|
357
341
|
const bandWidth = xBand && typeof xBand.bandwidth === 'function' && xBand.bandwidth();
|
|
358
342
|
// for chartType "line", bandWidth will be 0, so we have to calculate it
|
|
@@ -362,12 +346,12 @@ export class RawChartAxes extends React.Component {
|
|
|
362
346
|
const fontSize = theme && theme.typography ? theme.typography.fontSize : 14;
|
|
363
347
|
const rotate = getRotateAngle(fontSize, height);
|
|
364
348
|
|
|
365
|
-
const getTickLabelProps = value => ({
|
|
349
|
+
const getTickLabelProps = (value) => ({
|
|
366
350
|
dy: 4,
|
|
367
|
-
dx: -10 - (value.toLocaleString().length || 1) * 5
|
|
351
|
+
dx: -10 - (value.toLocaleString().length || 1) * 5,
|
|
368
352
|
});
|
|
369
353
|
|
|
370
|
-
const getTickComponent = props => {
|
|
354
|
+
const getTickComponent = (props) => {
|
|
371
355
|
const properties = {
|
|
372
356
|
classes,
|
|
373
357
|
categories,
|
|
@@ -383,7 +367,7 @@ export class RawChartAxes extends React.Component {
|
|
|
383
367
|
graphProps,
|
|
384
368
|
x: props.x,
|
|
385
369
|
y: props.y,
|
|
386
|
-
formattedValue: props.formattedValue
|
|
370
|
+
formattedValue: props.formattedValue,
|
|
387
371
|
};
|
|
388
372
|
|
|
389
373
|
return <TickComponent {...properties} />;
|
|
@@ -398,7 +382,7 @@ export class RawChartAxes extends React.Component {
|
|
|
398
382
|
axisLineClassName={axisLine}
|
|
399
383
|
tickLength={10}
|
|
400
384
|
tickClassName={tick}
|
|
401
|
-
tickFormat={value => value}
|
|
385
|
+
tickFormat={(value) => value}
|
|
402
386
|
tickValues={rowTickValues}
|
|
403
387
|
tickLabelProps={getTickLabelProps}
|
|
404
388
|
/>
|
|
@@ -410,7 +394,7 @@ export class RawChartAxes extends React.Component {
|
|
|
410
394
|
labelProps={{ y: 60 + top }}
|
|
411
395
|
top={scale.y && scale.y(range.min)}
|
|
412
396
|
textLabelProps={() => ({ textAnchor: 'middle' })}
|
|
413
|
-
tickFormat={count => count}
|
|
397
|
+
tickFormat={(count) => count}
|
|
414
398
|
tickComponent={getTickComponent}
|
|
415
399
|
/>
|
|
416
400
|
</React.Fragment>
|
|
@@ -419,35 +403,35 @@ export class RawChartAxes extends React.Component {
|
|
|
419
403
|
}
|
|
420
404
|
|
|
421
405
|
const ChartAxes = withStyles(
|
|
422
|
-
theme => ({
|
|
406
|
+
(theme) => ({
|
|
423
407
|
axis: {
|
|
424
408
|
stroke: color.primaryDark(),
|
|
425
|
-
strokeWidth: 2
|
|
409
|
+
strokeWidth: 2,
|
|
426
410
|
},
|
|
427
411
|
axisLine: {
|
|
428
412
|
stroke: color.primaryDark(),
|
|
429
|
-
strokeWidth: 2
|
|
413
|
+
strokeWidth: 2,
|
|
430
414
|
},
|
|
431
415
|
tick: {
|
|
432
416
|
'& > line': {
|
|
433
417
|
stroke: color.primaryDark(),
|
|
434
|
-
strokeWidth: 2
|
|
418
|
+
strokeWidth: 2,
|
|
435
419
|
},
|
|
436
420
|
fill: color.primaryDark(),
|
|
437
421
|
fontFamily: theme.typography.body1.fontFamily,
|
|
438
422
|
fontSize: theme.typography.fontSize,
|
|
439
|
-
textAnchor: 'middle'
|
|
423
|
+
textAnchor: 'middle',
|
|
440
424
|
},
|
|
441
425
|
dottedLine: {
|
|
442
426
|
stroke: color.primaryLight(),
|
|
443
|
-
opacity: 0.2
|
|
427
|
+
opacity: 0.2,
|
|
444
428
|
},
|
|
445
429
|
error: {
|
|
446
430
|
fontSize: '12px',
|
|
447
|
-
fill: 'red'
|
|
448
|
-
}
|
|
431
|
+
fill: 'red',
|
|
432
|
+
},
|
|
449
433
|
}),
|
|
450
|
-
{ withTheme: true }
|
|
434
|
+
{ withTheme: true },
|
|
451
435
|
)(RawChartAxes);
|
|
452
436
|
|
|
453
437
|
export default ChartAxes;
|
package/src/bars/bar.js
CHANGED
|
@@ -8,7 +8,7 @@ export class Bar extends React.Component {
|
|
|
8
8
|
static propTypes = {
|
|
9
9
|
data: PropTypes.array,
|
|
10
10
|
onChange: PropTypes.func,
|
|
11
|
-
graphProps: types.GraphPropsType.isRequired
|
|
11
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
render() {
|
|
@@ -24,5 +24,5 @@ export class Bar extends React.Component {
|
|
|
24
24
|
export default () => ({
|
|
25
25
|
type: 'bar',
|
|
26
26
|
Component: Bar,
|
|
27
|
-
name: 'Bar'
|
|
27
|
+
name: 'Bar',
|
|
28
28
|
});
|
package/src/bars/common/bars.jsx
CHANGED
|
@@ -23,18 +23,18 @@ export class RawBar extends React.Component {
|
|
|
23
23
|
interactive: PropTypes.bool,
|
|
24
24
|
correctness: PropTypes.shape({
|
|
25
25
|
value: PropTypes.string,
|
|
26
|
-
label: PropTypes.string
|
|
27
|
-
})
|
|
26
|
+
label: PropTypes.string,
|
|
27
|
+
}),
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
constructor(props) {
|
|
31
31
|
super(props);
|
|
32
32
|
this.state = {
|
|
33
|
-
dragValue: undefined
|
|
33
|
+
dragValue: undefined,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
setDragValue = dragValue => this.setState({ dragValue });
|
|
37
|
+
setDragValue = (dragValue) => this.setState({ dragValue });
|
|
38
38
|
|
|
39
39
|
dragStop = () => {
|
|
40
40
|
const { label, onChangeCategory } = this.props;
|
|
@@ -55,16 +55,7 @@ export class RawBar extends React.Component {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
render() {
|
|
58
|
-
const {
|
|
59
|
-
graphProps,
|
|
60
|
-
value,
|
|
61
|
-
label,
|
|
62
|
-
classes,
|
|
63
|
-
xBand,
|
|
64
|
-
index,
|
|
65
|
-
interactive,
|
|
66
|
-
correctness
|
|
67
|
-
} = this.props;
|
|
58
|
+
const { graphProps, value, label, classes, xBand, index, interactive, correctness } = this.props;
|
|
68
59
|
|
|
69
60
|
const { scale, range } = graphProps;
|
|
70
61
|
const { dragValue } = this.state;
|
|
@@ -81,19 +72,13 @@ export class RawBar extends React.Component {
|
|
|
81
72
|
|
|
82
73
|
return (
|
|
83
74
|
<React.Fragment>
|
|
84
|
-
<VxBar
|
|
85
|
-
x={barX}
|
|
86
|
-
y={scale.y(yy)}
|
|
87
|
-
width={barWidth}
|
|
88
|
-
height={barHeight}
|
|
89
|
-
className={classes.bar}
|
|
90
|
-
/>
|
|
75
|
+
<VxBar x={barX} y={scale.y(yy)} width={barWidth} height={barHeight} className={classes.bar} />
|
|
91
76
|
<Component
|
|
92
77
|
x={barX}
|
|
93
78
|
y={v}
|
|
94
79
|
interactive={interactive}
|
|
95
80
|
width={barWidth}
|
|
96
|
-
onDrag={v => this.dragValue(value, v)}
|
|
81
|
+
onDrag={(v) => this.dragValue(value, v)}
|
|
97
82
|
onDragStop={this.dragStop}
|
|
98
83
|
graphProps={graphProps}
|
|
99
84
|
correctness={correctness}
|
|
@@ -105,8 +90,8 @@ export class RawBar extends React.Component {
|
|
|
105
90
|
|
|
106
91
|
const Bar = withStyles(() => ({
|
|
107
92
|
bar: {
|
|
108
|
-
fill: color.primaryLight()
|
|
109
|
-
}
|
|
93
|
+
fill: color.primaryLight(),
|
|
94
|
+
},
|
|
110
95
|
}))(RawBar);
|
|
111
96
|
|
|
112
97
|
export class Bars extends React.Component {
|
|
@@ -115,7 +100,7 @@ export class Bars extends React.Component {
|
|
|
115
100
|
onChangeCategory: PropTypes.func,
|
|
116
101
|
defineChart: PropTypes.bool,
|
|
117
102
|
xBand: PropTypes.func,
|
|
118
|
-
graphProps: types.GraphPropsType.isRequired
|
|
103
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
119
104
|
};
|
|
120
105
|
|
|
121
106
|
render() {
|
|
@@ -131,7 +116,7 @@ export class Bars extends React.Component {
|
|
|
131
116
|
xBand={xBand}
|
|
132
117
|
index={index}
|
|
133
118
|
key={`bar-${d.label}-${d.value}-${index}`}
|
|
134
|
-
onChangeCategory={category => onChangeCategory(index, category)}
|
|
119
|
+
onChangeCategory={(category) => onChangeCategory(index, category)}
|
|
135
120
|
graphProps={graphProps}
|
|
136
121
|
correctness={d.correctness}
|
|
137
122
|
/>
|
package/src/bars/histogram.js
CHANGED
|
@@ -8,7 +8,7 @@ export class Histogram extends React.Component {
|
|
|
8
8
|
static propTypes = {
|
|
9
9
|
data: PropTypes.array,
|
|
10
10
|
onChange: PropTypes.func,
|
|
11
|
-
graphProps: types.GraphPropsType.isRequired
|
|
11
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
render() {
|
|
@@ -24,5 +24,5 @@ export class Histogram extends React.Component {
|
|
|
24
24
|
export default () => ({
|
|
25
25
|
type: 'histogram',
|
|
26
26
|
Component: Histogram,
|
|
27
|
-
name: 'Histogram'
|
|
27
|
+
name: 'Histogram',
|
|
28
28
|
});
|
package/src/chart-setup.jsx
CHANGED
|
@@ -7,7 +7,7 @@ import ChartType from './chart-type';
|
|
|
7
7
|
import { NumberTextFieldCustom } from '@pie-lib/config-ui';
|
|
8
8
|
import { AlertDialog } from '@pie-lib/config-ui';
|
|
9
9
|
|
|
10
|
-
const ConfigureChartPanel = props => {
|
|
10
|
+
const ConfigureChartPanel = (props) => {
|
|
11
11
|
const { classes, model, onChange, chartDimensions, gridValues = {}, labelValues = {} } = props;
|
|
12
12
|
const [alertDialog, setAlertDialog] = useState(false);
|
|
13
13
|
const [open, setOpen] = useState(false);
|
|
@@ -22,18 +22,16 @@ const ConfigureChartPanel = props => {
|
|
|
22
22
|
const widthConstraints = {
|
|
23
23
|
min: width?.min ? Math.max(50, width.min) : 50,
|
|
24
24
|
max: width?.max ? Math.min(700, width.max) : 700,
|
|
25
|
-
step: width?.step >= 1 ? Math.min(200, width.step) : 20
|
|
25
|
+
step: width?.step >= 1 ? Math.min(200, width.step) : 20,
|
|
26
26
|
};
|
|
27
27
|
const heightConstraints = {
|
|
28
28
|
min: height?.min ? Math.max(400, height.min) : 400,
|
|
29
29
|
max: height?.max ? Math.min(700, height.max) : 700,
|
|
30
|
-
step: height?.step >= 1 ? Math.min(200, height.step) : 20
|
|
30
|
+
step: height?.step >= 1 ? Math.min(200, height.step) : 20,
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const gridOptions =
|
|
34
|
-
|
|
35
|
-
const labelOptions =
|
|
36
|
-
labelValues && labelValues.range ? { customValues: labelValues.range } : { min: 0, max: 10000 };
|
|
33
|
+
const gridOptions = gridValues && gridValues.range ? { customValues: gridValues.range } : { min: 0, max: 10000 };
|
|
34
|
+
const labelOptions = labelValues && labelValues.range ? { customValues: labelValues.range } : { min: 0, max: 10000 };
|
|
37
35
|
|
|
38
36
|
const stepConfig = (
|
|
39
37
|
<div className={classes.rowView}>
|
|
@@ -59,15 +57,15 @@ const ConfigureChartPanel = props => {
|
|
|
59
57
|
const handleAlertDialog = (open, callback) => {
|
|
60
58
|
setAlertDialog(
|
|
61
59
|
{
|
|
62
|
-
alertDialog: open
|
|
60
|
+
alertDialog: open,
|
|
63
61
|
},
|
|
64
|
-
callback
|
|
62
|
+
callback,
|
|
65
63
|
);
|
|
66
64
|
setOpen(open);
|
|
67
65
|
};
|
|
68
66
|
|
|
69
|
-
const resetValues = data =>
|
|
70
|
-
data.forEach(d => {
|
|
67
|
+
const resetValues = (data) =>
|
|
68
|
+
data.forEach((d) => {
|
|
71
69
|
const remainder = d.value - range.step * Math.floor(d.value / range.step);
|
|
72
70
|
|
|
73
71
|
if (d.value > range.max || remainder !== 0) {
|
|
@@ -82,7 +80,7 @@ const ConfigureChartPanel = props => {
|
|
|
82
80
|
resetValues(correctAnswer.data);
|
|
83
81
|
};
|
|
84
82
|
|
|
85
|
-
const rangeProps = chartType => {
|
|
83
|
+
const rangeProps = (chartType) => {
|
|
86
84
|
return chartType.includes('Plot') ? { min: 3, max: 10 } : { min: 0.05, max: 10000 };
|
|
87
85
|
};
|
|
88
86
|
|
|
@@ -102,11 +100,9 @@ const ConfigureChartPanel = props => {
|
|
|
102
100
|
if (key === 'max' || key === 'step') {
|
|
103
101
|
// check if current chart values are invalid for given range step/max
|
|
104
102
|
const outOfRange =
|
|
105
|
-
model.data.find(
|
|
106
|
-
d => d.value > range.max || d.value - range.step * Math.floor(d.value / range.step) !== 0
|
|
107
|
-
) ||
|
|
103
|
+
model.data.find((d) => d.value > range.max || d.value - range.step * Math.floor(d.value / range.step) !== 0) ||
|
|
108
104
|
model.correctAnswer.data.find(
|
|
109
|
-
d => d.value > range.max || d.value - range.step * Math.floor(d.value / range.step) !== 0
|
|
105
|
+
(d) => d.value > range.max || d.value - range.step * Math.floor(d.value / range.step) !== 0,
|
|
110
106
|
);
|
|
111
107
|
|
|
112
108
|
if (outOfRange) {
|
|
@@ -132,13 +128,12 @@ const ConfigureChartPanel = props => {
|
|
|
132
128
|
onClose: () => {
|
|
133
129
|
range[rangeKey] = resetValue;
|
|
134
130
|
handleAlertDialog(false);
|
|
135
|
-
}
|
|
131
|
+
},
|
|
136
132
|
});
|
|
137
133
|
}
|
|
138
134
|
}, [open]);
|
|
139
135
|
|
|
140
|
-
const isValidPlot =
|
|
141
|
-
range.step === 1 && range.labelStep === 1 && 3 <= range.max && range.max <= 10;
|
|
136
|
+
const isValidPlot = range.step === 1 && range.labelStep === 1 && 3 <= range.max && range.max <= 10;
|
|
142
137
|
|
|
143
138
|
const getPlotConfiguration = () => {
|
|
144
139
|
rangeProps.min = 3;
|
|
@@ -151,15 +146,14 @@ const ConfigureChartPanel = props => {
|
|
|
151
146
|
onChange({ ...model, range });
|
|
152
147
|
};
|
|
153
148
|
|
|
154
|
-
const onChartTypeChange = chartType => {
|
|
149
|
+
const onChartTypeChange = (chartType) => {
|
|
155
150
|
if (chartType.includes('Plot')) {
|
|
156
151
|
// The selected chart type does not support the current chart configuration
|
|
157
152
|
if (!isValidPlot) {
|
|
158
153
|
setAlertDialog({
|
|
159
154
|
open: true,
|
|
160
155
|
title: 'Warning',
|
|
161
|
-
text:
|
|
162
|
-
'The selected chart type does not support the current chart configuration. Reset chart configuration?',
|
|
156
|
+
text: 'The selected chart type does not support the current chart configuration. Reset chart configuration?',
|
|
163
157
|
onConfirm: () => {
|
|
164
158
|
getPlotConfiguration();
|
|
165
159
|
removeOutOfRangeValues();
|
|
@@ -167,7 +161,7 @@ const ConfigureChartPanel = props => {
|
|
|
167
161
|
},
|
|
168
162
|
onClose: () => {
|
|
169
163
|
handleAlertDialog(false);
|
|
170
|
-
}
|
|
164
|
+
},
|
|
171
165
|
});
|
|
172
166
|
|
|
173
167
|
return;
|
|
@@ -189,7 +183,7 @@ const ConfigureChartPanel = props => {
|
|
|
189
183
|
<Typography variant={'subtitle1'}>Configure Chart</Typography>
|
|
190
184
|
<div className={classes.content}>
|
|
191
185
|
<div className={classes.rowView}>
|
|
192
|
-
<ChartType value={model.chartType} onChange={e => onChartTypeChange(e.target.value)} />
|
|
186
|
+
<ChartType value={model.chartType} onChange={(e) => onChartTypeChange(e.target.value)} />
|
|
193
187
|
<NumberTextFieldCustom
|
|
194
188
|
className={classes.mediumTextField}
|
|
195
189
|
label="Max Value"
|
|
@@ -252,54 +246,54 @@ ConfigureChartPanel.propTypes = {
|
|
|
252
246
|
onChange: PropTypes.func,
|
|
253
247
|
range: PropTypes.object,
|
|
254
248
|
chartDimension: PropTypes.object,
|
|
255
|
-
size: PropTypes.object
|
|
249
|
+
size: PropTypes.object,
|
|
256
250
|
};
|
|
257
251
|
|
|
258
|
-
const styles = theme => ({
|
|
252
|
+
const styles = (theme) => ({
|
|
259
253
|
wrapper: {
|
|
260
|
-
width: '450px'
|
|
254
|
+
width: '450px',
|
|
261
255
|
},
|
|
262
256
|
content: {
|
|
263
257
|
display: 'flex',
|
|
264
258
|
flexDirection: 'column',
|
|
265
259
|
width: '100%',
|
|
266
|
-
marginTop: '24px'
|
|
260
|
+
marginTop: '24px',
|
|
267
261
|
},
|
|
268
262
|
columnView: {
|
|
269
263
|
display: 'flex',
|
|
270
264
|
flexDirection: 'column',
|
|
271
|
-
alignItems: 'center'
|
|
265
|
+
alignItems: 'center',
|
|
272
266
|
},
|
|
273
267
|
rowView: {
|
|
274
268
|
display: 'flex',
|
|
275
269
|
justifyContent: 'space-around',
|
|
276
|
-
alignItems: 'center'
|
|
270
|
+
alignItems: 'center',
|
|
277
271
|
},
|
|
278
272
|
textField: {
|
|
279
273
|
width: '130px',
|
|
280
|
-
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px
|
|
274
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`,
|
|
281
275
|
},
|
|
282
276
|
mediumTextField: {
|
|
283
277
|
width: '160px',
|
|
284
|
-
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px
|
|
278
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`,
|
|
285
279
|
},
|
|
286
280
|
largeTextField: {
|
|
287
281
|
width: '230px',
|
|
288
|
-
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px
|
|
282
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`,
|
|
289
283
|
},
|
|
290
284
|
text: {
|
|
291
285
|
fontStyle: 'italic',
|
|
292
|
-
margin: `${theme.spacing.unit}px 0
|
|
286
|
+
margin: `${theme.spacing.unit}px 0`,
|
|
293
287
|
},
|
|
294
288
|
dimensions: {
|
|
295
289
|
display: 'flex',
|
|
296
290
|
justifyContent: 'space-between',
|
|
297
291
|
alignItems: 'center',
|
|
298
|
-
margin: '24px 0px'
|
|
292
|
+
margin: '24px 0px',
|
|
299
293
|
},
|
|
300
294
|
disabled: {
|
|
301
|
-
color: color.disabled()
|
|
302
|
-
}
|
|
295
|
+
color: color.disabled(),
|
|
296
|
+
},
|
|
303
297
|
});
|
|
304
298
|
|
|
305
299
|
export default withStyles(styles)(ConfigureChartPanel);
|
package/src/chart-type.js
CHANGED
|
@@ -6,13 +6,13 @@ import InputLabel from '@material-ui/core/InputLabel';
|
|
|
6
6
|
import Select from '@material-ui/core/Select';
|
|
7
7
|
import OutlinedInput from '@material-ui/core/OutlinedInput';
|
|
8
8
|
|
|
9
|
-
const ChartType = withStyles(theme => ({
|
|
9
|
+
const ChartType = withStyles((theme) => ({
|
|
10
10
|
chartType: {
|
|
11
|
-
width: '160px'
|
|
11
|
+
width: '160px',
|
|
12
12
|
},
|
|
13
13
|
chartTypeLabel: {
|
|
14
|
-
backgroundColor: 'transparent'
|
|
15
|
-
}
|
|
14
|
+
backgroundColor: 'transparent',
|
|
15
|
+
},
|
|
16
16
|
}))(({ onChange, value, classes }) => (
|
|
17
17
|
<div className={classes.chartType}>
|
|
18
18
|
<FormControl variant={'outlined'} className={classes.chartType}>
|
|
@@ -20,12 +20,7 @@ const ChartType = withStyles(theme => ({
|
|
|
20
20
|
ChartType
|
|
21
21
|
</InputLabel>
|
|
22
22
|
|
|
23
|
-
<Select
|
|
24
|
-
value={value}
|
|
25
|
-
onChange={onChange}
|
|
26
|
-
labelWidth={0}
|
|
27
|
-
input={<OutlinedInput name="type" id="type-helper" />}
|
|
28
|
-
>
|
|
23
|
+
<Select value={value} onChange={onChange} labelWidth={0} input={<OutlinedInput name="type" id="type-helper" />}>
|
|
29
24
|
<MenuItem value={'histogram'}>Histogram</MenuItem>
|
|
30
25
|
<MenuItem value={'bar'}>Bar Chart</MenuItem>
|
|
31
26
|
<MenuItem value={'lineDot'}>Line Chart ●</MenuItem>
|