Skip to content

Commit 3f30fd3

Browse files
committed
bugfix in datetime xaxis (when formatter is specified)
1 parent d1fdb93 commit 3f30fd3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/modules/axes/XAxis.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,21 @@ export default class XAxis {
190190
let xPos = w.globals.padHorizontal
191191

192192
let labelsLen = labels.length
193-
let datapoints = w.globals.dataPoints
193+
194+
/**
195+
* labelsLen can be different (whether you are drawing x-axis labels or x-axis group labels)
196+
* hence, we introduce dataPoints to be consistent.
197+
* Also, in datetime/numeric xaxis, dataPoints can be misleading, so we resort to labelsLen for such xaxis type
198+
*/
199+
let dataPoints =
200+
w.config.xaxis.type === 'category' ? w.globals.dataPoints : labelsLen
194201

195202
if (isXNumeric) {
196-
let len = datapoints > 1 ? datapoints - 1 : datapoints
203+
let len = dataPoints > 1 ? dataPoints - 1 : dataPoints
197204
colWidth = w.globals.gridWidth / len
198205
xPos = xPos + colWidthCb(0, colWidth) / 2 + w.config.xaxis.labels.offsetX
199206
} else {
200-
colWidth = w.globals.gridWidth / datapoints
207+
colWidth = w.globals.gridWidth / dataPoints
201208
xPos = xPos + colWidthCb(0, colWidth) + w.config.xaxis.labels.offsetX
202209
}
203210

@@ -208,7 +215,7 @@ export default class XAxis {
208215
i === 0 &&
209216
labelsLen === 1 &&
210217
colWidth / 2 === xPos &&
211-
datapoints === 1
218+
dataPoints === 1
212219
) {
213220
// single datapoint
214221
x = w.globals.gridWidth / 2

0 commit comments

Comments
 (0)