@pie-lib/charting 4.5.10 → 4.5.11-next.256
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.json +45 -0
- package/CHANGELOG.md +7 -41
- package/lib/axes.js +40 -36
- package/lib/axes.js.map +1 -1
- package/lib/bars/bar.js +17 -13
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/bars.js +27 -21
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/histogram.js +17 -13
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart.js +52 -35
- package/lib/chart.js.map +1 -1
- package/lib/common/drag-handle.js +24 -18
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/styles.js +1 -1
- package/lib/grid.js +17 -13
- package/lib/grid.js.map +1 -1
- package/lib/line/common/drag-handle.js +20 -14
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js +37 -29
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js +23 -17
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +21 -15
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +15 -7
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/common/plot.js +27 -21
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +18 -14
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +19 -15
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +19 -15
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js +77 -16
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/axes.jsx +1 -0
- package/src/chart.jsx +29 -4
- package/src/utils.js +73 -9
package/src/chart.jsx
CHANGED
|
@@ -48,7 +48,8 @@ export class Chart extends React.Component {
|
|
|
48
48
|
onDataChange: PropTypes.func,
|
|
49
49
|
addCategoryEnabled: PropTypes.bool,
|
|
50
50
|
editCategoryEnabled: PropTypes.bool,
|
|
51
|
-
categoryDefaultLabel: PropTypes.string
|
|
51
|
+
categoryDefaultLabel: PropTypes.string,
|
|
52
|
+
theme: PropTypes.object
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
static defaultProps = {
|
|
@@ -138,13 +139,31 @@ export class Chart extends React.Component {
|
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
render() {
|
|
141
|
-
const {
|
|
142
|
+
const {
|
|
143
|
+
classes,
|
|
144
|
+
className,
|
|
145
|
+
domain,
|
|
146
|
+
range,
|
|
147
|
+
size,
|
|
148
|
+
title,
|
|
149
|
+
addCategoryEnabled,
|
|
150
|
+
theme
|
|
151
|
+
} = this.props;
|
|
142
152
|
let { chartType } = this.props;
|
|
143
153
|
const { width, height } = size || {};
|
|
144
154
|
|
|
145
155
|
const { ChartComponent } = this.getChart();
|
|
146
156
|
const categories = this.getFilteredCategories();
|
|
147
|
-
|
|
157
|
+
|
|
158
|
+
const labelFontSize = (theme && theme.typography && theme.typography.fontSize) || 14;
|
|
159
|
+
const correctValues = getDomainAndRangeByChartType(
|
|
160
|
+
domain,
|
|
161
|
+
range,
|
|
162
|
+
size,
|
|
163
|
+
chartType,
|
|
164
|
+
labelFontSize
|
|
165
|
+
);
|
|
166
|
+
|
|
148
167
|
const { verticalLines, horizontalLines, leftAxis } = getGridLinesAndAxisByChartType(
|
|
149
168
|
correctValues.range,
|
|
150
169
|
chartType
|
|
@@ -234,9 +253,15 @@ const styles = theme => ({
|
|
|
234
253
|
borderLeft: `solid 1px ${color.primaryDark()}`,
|
|
235
254
|
borderRight: `solid 1px ${color.primaryDark()}`
|
|
236
255
|
},
|
|
256
|
+
root: {
|
|
257
|
+
overflow: 'hidden'
|
|
258
|
+
},
|
|
259
|
+
svg: {
|
|
260
|
+
overflow: 'visible'
|
|
261
|
+
},
|
|
237
262
|
toolMenu: {
|
|
238
263
|
minHeight: '36px'
|
|
239
264
|
}
|
|
240
265
|
});
|
|
241
266
|
|
|
242
|
-
export default withStyles(styles)(Chart);
|
|
267
|
+
export default withStyles(styles, { withTheme: true })(Chart);
|
package/src/utils.js
CHANGED
|
@@ -50,7 +50,53 @@ export const getTickValues = (prop = {}) => {
|
|
|
50
50
|
return tickValues;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
export const
|
|
53
|
+
export const customLabelStep = (rangeMax, size, labelFontSize) => {
|
|
54
|
+
const ceilMax = Math.ceil(rangeMax);
|
|
55
|
+
const segmentLength = size.height / ceilMax;
|
|
56
|
+
const ticksToFitInOneSegment = 2;
|
|
57
|
+
|
|
58
|
+
// how many ticksWidth fit in a segment
|
|
59
|
+
const tickWidthPerSegment = segmentLength / labelFontSize;
|
|
60
|
+
const rawLabelStep = ticksToFitInOneSegment / tickWidthPerSegment;
|
|
61
|
+
const roundedStep = Math.ceil((rawLabelStep * 10) / 10);
|
|
62
|
+
|
|
63
|
+
let labelStep;
|
|
64
|
+
|
|
65
|
+
if (rawLabelStep > 0.15) {
|
|
66
|
+
labelStep = roundedStep;
|
|
67
|
+
} else if (rawLabelStep < 0.05) {
|
|
68
|
+
labelStep = 0.1;
|
|
69
|
+
} else {
|
|
70
|
+
labelStep = 0.5;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return labelStep;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const crowdedTicks = (rangeMax, customLabelStep, size, labelFontSize) => {
|
|
77
|
+
const ceilMax = Math.ceil(rangeMax);
|
|
78
|
+
|
|
79
|
+
const numberOfSegments = ceilMax * customLabelStep;
|
|
80
|
+
|
|
81
|
+
return size.height / numberOfSegments < labelFontSize && size.height / numberOfSegments > 0.5;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// multiply values with 10^number_of_decimals if needed because modulo function(%) is only defined for integers
|
|
85
|
+
const modulo = (a, b) => {
|
|
86
|
+
if (Number.isInteger(b)) {
|
|
87
|
+
return a % b;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const decimals = b
|
|
91
|
+
.toString()
|
|
92
|
+
.split('.')
|
|
93
|
+
.pop().length;
|
|
94
|
+
const aux = Math.pow(10, decimals);
|
|
95
|
+
|
|
96
|
+
return (a * aux) % (b * aux);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const getDomainAndRangeByChartType = (domain, range, size, chartType, labelFontSize) => {
|
|
54
100
|
let { step, labelStep, min, max } = range || {};
|
|
55
101
|
|
|
56
102
|
if (!min) {
|
|
@@ -61,22 +107,40 @@ export const getDomainAndRangeByChartType = (domain, range, chartType) => {
|
|
|
61
107
|
max = range.min + 1;
|
|
62
108
|
}
|
|
63
109
|
|
|
64
|
-
|
|
110
|
+
if (labelStep && !step) {
|
|
111
|
+
step = labelStep;
|
|
112
|
+
}
|
|
113
|
+
if (!labelStep || (isNaN(labelStep) && step)) {
|
|
114
|
+
let customLabelStep = step;
|
|
115
|
+
let crowded = crowdedTicks(max, customLabelStep, size, labelFontSize);
|
|
116
|
+
|
|
117
|
+
if (crowded) {
|
|
118
|
+
customLabelStep = customLabelStep * 2;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
labelStep = customLabelStep;
|
|
122
|
+
}
|
|
65
123
|
|
|
66
|
-
if (!step) {
|
|
67
|
-
|
|
124
|
+
if (!step || (isNaN(step) && !labelStep) || isNaN(labelStep)) {
|
|
125
|
+
labelStep = customLabelStep(max, size, labelFontSize);
|
|
126
|
+
|
|
127
|
+
if (labelStep <= 1) {
|
|
128
|
+
step = labelStep;
|
|
129
|
+
} else if (labelStep <= 4) {
|
|
68
130
|
step = 1;
|
|
69
|
-
} else if (
|
|
70
|
-
step =
|
|
131
|
+
} else if (labelStep > 4 && labelStep < 10) {
|
|
132
|
+
step = labelStep / 2;
|
|
71
133
|
} else {
|
|
72
|
-
step =
|
|
134
|
+
step = labelStep / 3;
|
|
73
135
|
}
|
|
74
136
|
}
|
|
75
137
|
|
|
76
|
-
if (
|
|
77
|
-
|
|
138
|
+
if (modulo(max, step) !== 0) {
|
|
139
|
+
max = max + step;
|
|
78
140
|
}
|
|
79
141
|
|
|
142
|
+
range.max = max;
|
|
143
|
+
|
|
80
144
|
switch (chartType) {
|
|
81
145
|
// if chart is dot plot or line plot, we should ignore step and make sure that min & max are integer values
|
|
82
146
|
case 'dotPlot':
|