Skip to content

Commit

Permalink
bring back xaxis gridlines - fixes #3580
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Feb 4, 2023
1 parent 5b80915 commit 0e598a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
61 changes: 16 additions & 45 deletions src/modules/axes/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,49 +283,24 @@ class Grid {
}

const categoryLines = ({ xC, x1, y1, x2, y2 }) => {
if (
typeof w.config.xaxis.tickAmount !== 'undefined' &&
w.config.xaxis.tickAmount !== 'dataPoints' &&
w.config.xaxis.tickPlacement === 'on'
) {
// user has specified tickamount in a category x-axis chart
const visibleLabels = w.globals.dom.baseEl.querySelectorAll(
'.apexcharts-text.apexcharts-xaxis-label tspan:not(:empty)'
)

visibleLabels.forEach((d, i) => {
const textRect = d.getBBox()

this._drawGridLines({
i,
x1: textRect.x + textRect.width / 2,
y1,
x2: textRect.x + textRect.width / 2,
y2,
xCount,
parent: this.elgridLinesV
})
})
} else {
for (let i = 0; i < xC + (w.globals.isXNumeric ? 0 : 1); i++) {
if (i === 0 && xC === 1 && w.globals.dataPoints === 1) {
// single datapoint
x1 = w.globals.gridWidth / 2
x2 = x1
}
this._drawGridLines({
i,
x1,
y1,
x2,
y2,
xCount,
parent: this.elgridLinesV
})

x1 = x1 + w.globals.gridWidth / (w.globals.isXNumeric ? xC - 1 : xC)
for (let i = 0; i < xC + (w.globals.isXNumeric ? 0 : 1); i++) {
if (i === 0 && xC === 1 && w.globals.dataPoints === 1) {
// single datapoint
x1 = w.globals.gridWidth / 2
x2 = x1
}
this._drawGridLines({
i,
x1,
y1,
x2,
y2,
xCount,
parent: this.elgridLinesV
})

x1 = x1 + w.globals.gridWidth / (w.globals.isXNumeric ? xC - 1 : xC)
x2 = x1
}
}

Expand All @@ -342,10 +317,6 @@ class Grid {
if (w.globals.isXNumeric) {
xCount = w.globals.xAxisScale.result.length
}
if (w.config.xaxis.convertedCatToNumeric) {
// in case of a convertedCatToNumeric, some labels might be skipped due to hideOverLapping labels, hence use this var to get the visible ticks
xCount = w.globals.xaxisLabelsCount
}
categoryLines({ xC: xCount, x1, y1, x2, y2 })
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/modules/axes/XAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ export default class XAxis {
: xaxisForeColors[i]
}

if (isLeafGroup && label.text) {
w.globals.xaxisLabelsCount++
}

if (w.config.xaxis.labels.show) {
let elText = graphics.drawText({
x: label.x,
Expand Down
1 change: 0 additions & 1 deletion src/modules/settings/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default class Globals {
gl.pointsArray = []
gl.dataLabelsRects = []
gl.isXNumeric = false
gl.xaxisLabelsCount = 0
gl.skipLastTimelinelabel = false
gl.skipFirstTimelinelabel = false
gl.isDataXYZ = false
Expand Down
2 changes: 1 addition & 1 deletion src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export default class Options {
position: 'back',
xaxis: {
lines: {
show: false
show: true
}
},
yaxis: {
Expand Down

0 comments on commit 0e598a7

Please sign in to comment.