frappe-charts 2.1.2 → 2.2.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/dist/frappe-charts.cjs.js +1 -1
- package/dist/frappe-charts.cjs.js.map +1 -1
- package/dist/frappe-charts.esm.js +1 -1
- package/dist/frappe-charts.esm.js.map +1 -1
- package/dist/frappe-charts.umd.js +1 -1
- package/dist/frappe-charts.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/js/charts/AxisChart.js +30 -4
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import { makeOverlay, updateOverlay, legendDot, makeHoverBand, FONT_SIZE, AXIS_T
|
|
|
8
8
|
import {
|
|
9
9
|
BASE_MEASURES, getExtraHeight, getTopOffset, getLeftOffset, MIN_BAR_PERCENT_HEIGHT, BAR_CHART_SPACE_RATIO,
|
|
10
10
|
BAR_CHART_RADIUS, BAR_CHART_GAP, BAR_CHART_MAX_WIDTH, LINE_CHART_DOT_SIZE, LEGEND_DOT_SIZE, LEGEND_FONT_SIZE,
|
|
11
|
-
LEGEND_CHAR_WIDTH, TOOLTIP_SIDE_GAP
|
|
11
|
+
LEGEND_CHAR_WIDTH, TOOLTIP_SIDE_GAP, DEFAULT_CHAR_WIDTH
|
|
12
12
|
} from '../utils/constants';
|
|
13
13
|
import { shortenLargeNumber } from '../utils/draw-utils';
|
|
14
14
|
import { getColor } from '../utils/colors';
|
|
@@ -70,6 +70,7 @@ export default class AxisChart extends BaseChart {
|
|
|
70
70
|
|
|
71
71
|
this.config.xAxisMode = options.axisOptions.xAxisMode || 'span';
|
|
72
72
|
this.config.xOffset = options.axisOptions.xOffset;
|
|
73
|
+
this.config.xAxisType = options.axisOptions.xAxisType;
|
|
73
74
|
this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
|
|
74
75
|
this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
|
|
75
76
|
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
|
|
@@ -147,14 +148,37 @@ export default class AxisChart extends BaseChart {
|
|
|
147
148
|
s.unitWidth = this.width / (edgeToEdge ? s.datasetLength - 1 : s.datasetLength);
|
|
148
149
|
s.xOffset = edgeToEdge ? 0 : s.unitWidth / 2;
|
|
149
150
|
|
|
151
|
+
let times = !hasBars && this.config.xAxisType === 'time' ? this.getLabelTimes() : null;
|
|
152
|
+
let span = this.width - 2 * s.xOffset;
|
|
153
|
+
|
|
150
154
|
s.xAxis = {
|
|
151
155
|
labels: labels,
|
|
156
|
+
isTime: !!times,
|
|
152
157
|
positions: labels.map((d, i) =>
|
|
153
|
-
floatTwo(s.xOffset +
|
|
158
|
+
floatTwo(s.xOffset + (times
|
|
159
|
+
? (times[i] - times[0]) / (times[times.length - 1] - times[0]) * span
|
|
160
|
+
: i * s.unitWidth))
|
|
154
161
|
)
|
|
155
162
|
};
|
|
156
163
|
}
|
|
157
164
|
|
|
165
|
+
getSpacedLabels() {
|
|
166
|
+
let { labels, positions } = this.state.xAxis;
|
|
167
|
+
let lastEnd = -Infinity;
|
|
168
|
+
return labels.map((label, i) => {
|
|
169
|
+
let half = getStringWidth(label, DEFAULT_CHAR_WIDTH) / 2;
|
|
170
|
+
if (positions[i] - half < lastEnd) return '';
|
|
171
|
+
lastEnd = positions[i] + half + DEFAULT_CHAR_WIDTH;
|
|
172
|
+
return label + '';
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
getLabelTimes() {
|
|
177
|
+
let times = this.data.labels.map(d => new Date(d).getTime());
|
|
178
|
+
let valid = times.length > 1 && times.every((t, i) => !isNaN(t) && (i === 0 || t >= times[i - 1]));
|
|
179
|
+
return valid && times[times.length - 1] > times[0] ? times : null;
|
|
180
|
+
}
|
|
181
|
+
|
|
158
182
|
// always a list, even when empty, so the marker layer exists for markers added by a later update
|
|
159
183
|
calcXMarkers() {
|
|
160
184
|
let s = this.state;
|
|
@@ -302,8 +326,10 @@ export default class AxisChart extends BaseChart {
|
|
|
302
326
|
},
|
|
303
327
|
function () {
|
|
304
328
|
let s = this.state;
|
|
305
|
-
s.xAxis.calcLabels =
|
|
306
|
-
|
|
329
|
+
s.xAxis.calcLabels = s.xAxis.isTime
|
|
330
|
+
? this.getSpacedLabels()
|
|
331
|
+
: getShortenedLabels(this.width,
|
|
332
|
+
s.xAxis.labels, this.config.xIsSeries,this.config.seriesLabelSpaceRatio);
|
|
307
333
|
|
|
308
334
|
return s.xAxis;
|
|
309
335
|
}.bind(this)
|