Skip to content

Commit

Permalink
category xaxis annotation fix - fixes #387
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Mar 10, 2019
1 parent 3504f01 commit 96ea9e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,23 @@ export default class ApexCharts {
options.xaxis.categories.length &&
w.config.xaxis.tickPlacement === 'on'
) {
options.xaxis.categories = []
options.labels = []
const combo = CoreUtils.checkComboSeries(w.config.series)

if (
(w.config.chart.type === 'line' ||
w.config.chart.type === 'area' ||
w.config.chart.type === 'scatter') &&
!combo.comboChartsHasBars
) {
options.xaxis.categories = []
options.labels = []
}
}
}
if (w.globals.collapsedSeriesIndices.length > 0) {
this.clearPreviousPaths()
}

return this._updateOptions(options, redraw, animate, overwriteInitialConfig)
}

Expand Down
16 changes: 14 additions & 2 deletions src/modules/Annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,22 @@ export default class Annotations {
const min = this.invertAxis ? w.globals.minY : w.globals.minX
const range = this.invertAxis ? w.globals.yRange[0] : w.globals.xRange

let strokeDashArray = anno.strokeDashArray

let x1 = (anno.x - min) / (range / w.globals.gridWidth)

if (
w.config.xaxis.type === 'category' ||
w.config.xaxis.convertedCatToNumeric
) {
let catIndex = w.globals.labels.indexOf(anno.x)
const xLabel = w.globals.dom.baseEl.querySelector(
'.apexcharts-xaxis-texts-g text:nth-child(' + (catIndex + 1) + ')'
)

x1 = parseFloat(xLabel.getAttribute('x'))
}

let strokeDashArray = anno.strokeDashArray

if (x1 < 0 || x1 > w.globals.gridWidth) return

if (anno.x2 === null) {
Expand Down
1 change: 0 additions & 1 deletion src/modules/axes/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class YAxis {
labels.reverse()
}

//console.log(labels)
if (w.config.yaxis[realIndex].labels.show) {
for (let i = tickAmount; i >= 0; i--) {
let val = labels[i]
Expand Down
1 change: 1 addition & 0 deletions src/modules/settings/Defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export default class Defaults {
convertCatToNumeric() {
const opts = this.opts
opts.xaxis.type = 'numeric'
opts.xaxis.convertedCatToNumeric = true
opts.xaxis.labels = opts.xaxis.labels || {}
opts.xaxis.labels.formatter =
opts.xaxis.labels.formatter ||
Expand Down

0 comments on commit 96ea9e7

Please sign in to comment.