@pie-lib/charting 4.5.18 → 5.1.1
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 +43 -0
- package/lib/axes.js +100 -97
- package/lib/axes.js.map +1 -1
- package/lib/bars/bar.js +19 -30
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/bars.js +33 -47
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/histogram.js +19 -30
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart-setup.js +206 -0
- package/lib/chart-setup.js.map +1 -0
- package/lib/chart-type.js +68 -0
- package/lib/chart-type.js.map +1 -0
- package/lib/chart-types.js +2 -2
- package/lib/chart-types.js.map +1 -1
- package/lib/chart.js +44 -71
- package/lib/chart.js.map +1 -1
- package/lib/common/drag-handle.js +26 -41
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/styles.js +7 -5
- package/lib/common/styles.js.map +1 -1
- package/lib/grid.js +19 -31
- package/lib/grid.js.map +1 -1
- package/lib/index.js +17 -1
- package/lib/index.js.map +1 -1
- package/lib/line/common/drag-handle.js +25 -39
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js +45 -73
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js +25 -39
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +24 -38
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +10 -20
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/common/plot.js +33 -47
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +20 -31
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +21 -32
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +19 -32
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js +5 -3
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/axes.jsx +47 -11
- package/src/bars/common/bars.jsx +5 -2
- package/src/chart-setup.jsx +160 -0
- package/src/chart-type.js +39 -0
- package/src/chart.jsx +8 -6
- package/src/index.js +4 -1
- package/src/line/common/drag-handle.jsx +2 -1
- package/src/line/common/line.jsx +5 -3
- package/src/plot/common/plot.jsx +4 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { color } from '@pie-lib/render-ui';
|
|
4
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
5
|
+
import Typography from '@material-ui/core/Typography';
|
|
6
|
+
import ChartType from './chart-type';
|
|
7
|
+
import { NumberTextFieldCustom } from '@pie-lib/config-ui';
|
|
8
|
+
|
|
9
|
+
const ConfigureChartPanel = props => {
|
|
10
|
+
const { classes, model, onChange } = props;
|
|
11
|
+
const { range } = model;
|
|
12
|
+
const size = model.graph;
|
|
13
|
+
|
|
14
|
+
const rangeProps = chartType =>
|
|
15
|
+
chartType.includes('Plot') ? { min: 3, max: 10 } : { min: 0.05, max: 10000 };
|
|
16
|
+
|
|
17
|
+
const onSizeChanged = (key, value) => {
|
|
18
|
+
const graph = { ...size, [key]: value };
|
|
19
|
+
|
|
20
|
+
onChange({ ...model, graph });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const onRangeChanged = (key, value) => {
|
|
24
|
+
const parsedValue = parseInt(value);
|
|
25
|
+
|
|
26
|
+
range[key] = parsedValue;
|
|
27
|
+
|
|
28
|
+
onChange({ ...model, range });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onChartTypeChange = chartType => {
|
|
32
|
+
if (chartType.includes('Plot')) {
|
|
33
|
+
rangeProps.min = 3;
|
|
34
|
+
rangeProps.max = 10;
|
|
35
|
+
|
|
36
|
+
if (range.max > 10 || range.max < 3) {
|
|
37
|
+
range.max = 10;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
range.step = 1;
|
|
41
|
+
range.labelStep = 1;
|
|
42
|
+
onChange({ ...model, range, chartType });
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onChange({ ...model, chartType });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className={classes.wrapper}>
|
|
52
|
+
<Typography variant={'subtitle1'}>Configure Chart</Typography>
|
|
53
|
+
<div className={classes.content}>
|
|
54
|
+
<div className={classes.rowView}>
|
|
55
|
+
<ChartType value={model.chartType} onChange={e => onChartTypeChange(e.target.value)} />
|
|
56
|
+
<NumberTextFieldCustom
|
|
57
|
+
className={classes.mediumTextField}
|
|
58
|
+
label="Max Value"
|
|
59
|
+
value={range.max}
|
|
60
|
+
min={rangeProps(model.chartType).min}
|
|
61
|
+
max={rangeProps(model.chartType).max}
|
|
62
|
+
variant="outlined"
|
|
63
|
+
onChange={(e, v) => onRangeChanged('max', v)}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
{!model.chartType.includes('Plot') && stepConfig}
|
|
67
|
+
<div className={classes.dimensions}>
|
|
68
|
+
<div>
|
|
69
|
+
<Typography>Dimensions(px)</Typography>
|
|
70
|
+
</div>
|
|
71
|
+
<div className={classes.columnView}>
|
|
72
|
+
<NumberTextFieldCustom
|
|
73
|
+
className={classes.textField}
|
|
74
|
+
label={'Width'}
|
|
75
|
+
value={size.width}
|
|
76
|
+
min={50}
|
|
77
|
+
max={700}
|
|
78
|
+
variant={'outlined'}
|
|
79
|
+
onChange={(e, v) => onSizeChanged('width', v)}
|
|
80
|
+
/>
|
|
81
|
+
<Typography className={classes.disabled}>Min 50, Max 700</Typography>
|
|
82
|
+
</div>
|
|
83
|
+
<div className={classes.columnView}>
|
|
84
|
+
<NumberTextFieldCustom
|
|
85
|
+
className={classes.textField}
|
|
86
|
+
label={'Height'}
|
|
87
|
+
value={size.height}
|
|
88
|
+
min={400}
|
|
89
|
+
max={700}
|
|
90
|
+
variant={'outlined'}
|
|
91
|
+
onChange={(e, v) => onSizeChanged('height', v)}
|
|
92
|
+
/>
|
|
93
|
+
<Typography className={classes.disabled}>Min 400, Max 700</Typography>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
ConfigureChartPanel.propTypes = {
|
|
102
|
+
classes: PropTypes.object,
|
|
103
|
+
sizeConstraints: PropTypes.object,
|
|
104
|
+
domain: PropTypes.object,
|
|
105
|
+
gridIntervalValues: PropTypes.object,
|
|
106
|
+
includeAxes: PropTypes.bool,
|
|
107
|
+
labelIntervalValues: PropTypes.object,
|
|
108
|
+
onChange: PropTypes.function,
|
|
109
|
+
range: PropTypes.object,
|
|
110
|
+
size: PropTypes.object
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const styles = theme => ({
|
|
114
|
+
wrapper: {
|
|
115
|
+
width: '450px'
|
|
116
|
+
},
|
|
117
|
+
content: {
|
|
118
|
+
display: 'flex',
|
|
119
|
+
flexDirection: 'column',
|
|
120
|
+
width: '100%',
|
|
121
|
+
marginTop: '24px'
|
|
122
|
+
},
|
|
123
|
+
columnView: {
|
|
124
|
+
display: 'flex',
|
|
125
|
+
flexDirection: 'column',
|
|
126
|
+
alignItems: 'center'
|
|
127
|
+
},
|
|
128
|
+
rowView: {
|
|
129
|
+
display: 'flex',
|
|
130
|
+
justifyContent: 'space-around',
|
|
131
|
+
alignItems: 'center'
|
|
132
|
+
},
|
|
133
|
+
textField: {
|
|
134
|
+
width: '130px',
|
|
135
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`
|
|
136
|
+
},
|
|
137
|
+
mediumTextField: {
|
|
138
|
+
width: '160px',
|
|
139
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`
|
|
140
|
+
},
|
|
141
|
+
largeTextField: {
|
|
142
|
+
width: '230px',
|
|
143
|
+
margin: `${theme.spacing.unit}px ${theme.spacing.unit / 2}px`
|
|
144
|
+
},
|
|
145
|
+
text: {
|
|
146
|
+
fontStyle: 'italic',
|
|
147
|
+
margin: `${theme.spacing.unit}px 0`
|
|
148
|
+
},
|
|
149
|
+
dimensions: {
|
|
150
|
+
display: 'flex',
|
|
151
|
+
justifyContent: 'space-between',
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
margin: '24px 0px'
|
|
154
|
+
},
|
|
155
|
+
disabled: {
|
|
156
|
+
color: color.disabled()
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export default withStyles(styles)(ConfigureChartPanel);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
3
|
+
import MenuItem from '@material-ui/core/MenuItem';
|
|
4
|
+
import FormControl from '@material-ui/core/FormControl';
|
|
5
|
+
import InputLabel from '@material-ui/core/InputLabel';
|
|
6
|
+
import Select from '@material-ui/core/Select';
|
|
7
|
+
import OutlinedInput from '@material-ui/core/OutlinedInput';
|
|
8
|
+
|
|
9
|
+
const ChartType = withStyles(theme => ({
|
|
10
|
+
chartType: {
|
|
11
|
+
width: '160px'
|
|
12
|
+
},
|
|
13
|
+
chartTypeLabel: {
|
|
14
|
+
backgroundColor: 'transparent'
|
|
15
|
+
}
|
|
16
|
+
}))(({ onChange, value, classes }) => (
|
|
17
|
+
<div className={classes.chartType}>
|
|
18
|
+
<FormControl variant={'outlined'} className={classes.chartType}>
|
|
19
|
+
<InputLabel htmlFor="type-helper" className={classes.chartTypeLabel}>
|
|
20
|
+
ChartType
|
|
21
|
+
</InputLabel>
|
|
22
|
+
|
|
23
|
+
<Select
|
|
24
|
+
value={value}
|
|
25
|
+
onChange={onChange}
|
|
26
|
+
input={<OutlinedInput name="type" id="type-helper" />}
|
|
27
|
+
>
|
|
28
|
+
<MenuItem value={'histogram'}>Histogram</MenuItem>
|
|
29
|
+
<MenuItem value={'bar'}>Bar</MenuItem>
|
|
30
|
+
<MenuItem value={'lineDot'}>Line Dot</MenuItem>
|
|
31
|
+
<MenuItem value={'lineCross'}>Line Cross</MenuItem>
|
|
32
|
+
<MenuItem value={'dotPlot'}>Dot Plot</MenuItem>
|
|
33
|
+
<MenuItem value={'linePlot'}>Line Plot</MenuItem>
|
|
34
|
+
</Select>
|
|
35
|
+
</FormControl>
|
|
36
|
+
</div>
|
|
37
|
+
));
|
|
38
|
+
|
|
39
|
+
export default ChartType;
|
package/src/chart.jsx
CHANGED
|
@@ -47,8 +47,8 @@ export class Chart extends React.Component {
|
|
|
47
47
|
title: PropTypes.string,
|
|
48
48
|
onDataChange: PropTypes.func,
|
|
49
49
|
addCategoryEnabled: PropTypes.bool,
|
|
50
|
-
editCategoryEnabled: PropTypes.bool,
|
|
51
50
|
categoryDefaultLabel: PropTypes.string,
|
|
51
|
+
defineChart: PropTypes.bool,
|
|
52
52
|
theme: PropTypes.object
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -127,13 +127,12 @@ export class Chart extends React.Component {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
getFilteredCategories = () => {
|
|
130
|
-
const { data,
|
|
130
|
+
const { data, defineChart } = this.props;
|
|
131
131
|
|
|
132
132
|
return data
|
|
133
133
|
? data.map(d => ({
|
|
134
134
|
...d,
|
|
135
|
-
|
|
136
|
-
deletable: !d.initial || (d.initial && addCategoryEnabled)
|
|
135
|
+
deletable: defineChart || d.deletable
|
|
137
136
|
}))
|
|
138
137
|
: [];
|
|
139
138
|
};
|
|
@@ -150,6 +149,7 @@ export class Chart extends React.Component {
|
|
|
150
149
|
theme
|
|
151
150
|
} = this.props;
|
|
152
151
|
let { chartType } = this.props;
|
|
152
|
+
|
|
153
153
|
const defineChart = this.props.defineChart || false;
|
|
154
154
|
const { width, height } = size || {};
|
|
155
155
|
|
|
@@ -177,9 +177,10 @@ export class Chart extends React.Component {
|
|
|
177
177
|
() => this.rootNode
|
|
178
178
|
)
|
|
179
179
|
};
|
|
180
|
+
|
|
180
181
|
log('[render] common:', common);
|
|
181
182
|
|
|
182
|
-
const maskSize = { x: -10, y: -10, width: width + 20, height: height +
|
|
183
|
+
const maskSize = { x: -10, y: -10, width: width + 20, height: height + 80 };
|
|
183
184
|
const { scale } = common.graphProps;
|
|
184
185
|
const xBand = dataToXBand(scale.x, categories, width, chartType);
|
|
185
186
|
|
|
@@ -190,7 +191,7 @@ export class Chart extends React.Component {
|
|
|
190
191
|
const bandWidth = xBand.bandwidth();
|
|
191
192
|
// for chartType "line", bandWidth will be 0, so we have to calculate it
|
|
192
193
|
const barWidth = bandWidth || scale.x(correctValues.domain.max) / categories.length;
|
|
193
|
-
const increaseHeight = defineChart ?
|
|
194
|
+
const increaseHeight = defineChart ? 80 : 0;
|
|
194
195
|
|
|
195
196
|
// if there are many categories, we have to rotate their names in order to fit
|
|
196
197
|
// and we have to add extra value on top of some items
|
|
@@ -231,6 +232,7 @@ export class Chart extends React.Component {
|
|
|
231
232
|
<ChartComponent
|
|
232
233
|
{...common}
|
|
233
234
|
data={categories}
|
|
235
|
+
defineChart={defineChart}
|
|
234
236
|
onChange={this.changeData}
|
|
235
237
|
onChangeCategory={this.changeCategory}
|
|
236
238
|
/>
|
package/src/index.js
CHANGED
|
@@ -34,6 +34,7 @@ class RawDragHandle extends React.Component {
|
|
|
34
34
|
correctness,
|
|
35
35
|
...rest
|
|
36
36
|
} = this.props;
|
|
37
|
+
|
|
37
38
|
const { scale } = graphProps;
|
|
38
39
|
return (
|
|
39
40
|
<CustomDraggableComponent
|
|
@@ -42,7 +43,7 @@ class RawDragHandle extends React.Component {
|
|
|
42
43
|
y={y}
|
|
43
44
|
classes={classes}
|
|
44
45
|
className={classNames(className, !interactive && 'non-interactive')}
|
|
45
|
-
correctness={
|
|
46
|
+
correctness={correctness}
|
|
46
47
|
{...rest}
|
|
47
48
|
/>
|
|
48
49
|
);
|
package/src/line/common/line.jsx
CHANGED
|
@@ -32,6 +32,7 @@ export class RawLine extends React.Component {
|
|
|
32
32
|
xBand: PropTypes.func,
|
|
33
33
|
index: PropTypes.number.isRequired,
|
|
34
34
|
graphProps: types.GraphPropsType.isRequired,
|
|
35
|
+
defineChart: PropTypes.bool,
|
|
35
36
|
data: PropTypes.arrayOf(
|
|
36
37
|
PropTypes.shape({
|
|
37
38
|
label: PropTypes.string,
|
|
@@ -77,7 +78,7 @@ export class RawLine extends React.Component {
|
|
|
77
78
|
};
|
|
78
79
|
|
|
79
80
|
render() {
|
|
80
|
-
const { graphProps, data, classes, CustomDraggableComponent } = this.props;
|
|
81
|
+
const { graphProps, data, classes, CustomDraggableComponent, defineChart } = this.props;
|
|
81
82
|
const { line: lineState, dragging } = this.state;
|
|
82
83
|
const { scale } = graphProps;
|
|
83
84
|
const lineToUse = dragging ? lineState : getData(data, graphProps.domain);
|
|
@@ -93,14 +94,15 @@ export class RawLine extends React.Component {
|
|
|
93
94
|
{lineToUse &&
|
|
94
95
|
lineToUse.map((point, i) => {
|
|
95
96
|
const r = 6;
|
|
96
|
-
const
|
|
97
|
+
const enableDraggable = defineChart || point.interactive;
|
|
98
|
+
const Component = enableDraggable ? DraggableHandle : DragHandle;
|
|
97
99
|
|
|
98
100
|
return (
|
|
99
101
|
<Component
|
|
100
102
|
key={`point-${point.x}-${i}`}
|
|
101
103
|
x={point.x}
|
|
102
104
|
y={point.dragValue !== undefined ? point.dragValue : point.y}
|
|
103
|
-
interactive={
|
|
105
|
+
interactive={enableDraggable}
|
|
104
106
|
r={r}
|
|
105
107
|
onDragStart={() => this.setState({ dragging: true })}
|
|
106
108
|
onDrag={v =>
|
package/src/plot/common/plot.jsx
CHANGED
|
@@ -67,6 +67,7 @@ export class RawPlot extends React.Component {
|
|
|
67
67
|
interactive,
|
|
68
68
|
correctness
|
|
69
69
|
} = this.props;
|
|
70
|
+
|
|
70
71
|
const { scale, range, size } = graphProps;
|
|
71
72
|
const { max } = range || {};
|
|
72
73
|
const { dragValue } = this.state;
|
|
@@ -137,11 +138,12 @@ export class Plot extends React.Component {
|
|
|
137
138
|
onChangeCategory: PropTypes.func,
|
|
138
139
|
xBand: PropTypes.func,
|
|
139
140
|
graphProps: types.GraphPropsType.isRequired,
|
|
141
|
+
defineChart: PropTypes.bool,
|
|
140
142
|
CustomBarElement: PropTypes.func
|
|
141
143
|
};
|
|
142
144
|
|
|
143
145
|
render() {
|
|
144
|
-
const { data, graphProps, xBand, CustomBarElement, onChangeCategory } = this.props;
|
|
146
|
+
const { data, graphProps, xBand, CustomBarElement, onChangeCategory, defineChart } = this.props;
|
|
145
147
|
|
|
146
148
|
return (
|
|
147
149
|
<Group>
|
|
@@ -149,7 +151,7 @@ export class Plot extends React.Component {
|
|
|
149
151
|
<Bar
|
|
150
152
|
value={d.value}
|
|
151
153
|
label={d.label}
|
|
152
|
-
interactive={d.interactive}
|
|
154
|
+
interactive={defineChart || d.interactive}
|
|
153
155
|
xBand={xBand}
|
|
154
156
|
index={index}
|
|
155
157
|
key={`bar-${d.label}-${d.value}-${index}`}
|