Skip to content

Commit

Permalink
updating categories doesn't work in line chart - fixes apexcharts/rea…
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Mar 11, 2019
1 parent becfaea commit 5c252b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
18 changes: 5 additions & 13 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Config from './modules/settings/Config'
import Core from './modules/Core'
import CoreUtils from './modules/CoreUtils'
import Crosshairs from './modules/Crosshairs'
import Defaults from './modules/settings/Defaults'
import Dimensions from './modules/Dimensions'
import Formatters from './modules/Formatters'
import Exports from './modules/Exports'
Expand Down Expand Up @@ -409,23 +410,14 @@ export default class ApexCharts {
if (options.xaxis.min || options.xaxis.max) {
this.forceXAxisUpdate(options)
}
/* fixes #369 */

/* fixes apexcharts.js#369 and react-apexcharts#46 */
if (
options.xaxis.categories &&
options.xaxis.categories.length &&
w.config.xaxis.tickPlacement === 'on'
w.config.xaxis.convertedCatToNumeric
) {
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 = []
}
options = Defaults.convertCatToNumeric(options)
}
}
if (w.globals.collapsedSeriesIndices.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/settings/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class Config {
opts.xaxis.type !== 'datetime' &&
opts.xaxis.tickPlacement !== 'between'
) {
defaults.convertCatToNumeric()
opts = Defaults.convertCatToNumeric(opts)
}
if (
(opts.chart.sparkline && opts.chart.sparkline.enabled) ||
Expand Down
8 changes: 5 additions & 3 deletions src/modules/settings/Defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default class Defaults {
this.opts.yaxis[index].max = 100
})

const isBar = !!(this.opts.chart.type === 'bar')
const isBar = this.opts.chart.type === 'bar'

if (isBar) {
this.opts.dataLabels.formatter =
Expand All @@ -272,8 +272,7 @@ export default class Defaults {
}

// This function removes the left and right spacing in chart for line/area/scatter if xaxis type = category for those charts by converting xaxis = numeric. Numeric/Datetime xaxis prevents the unnecessary spacing in the left/right of the chart area
convertCatToNumeric() {
const opts = this.opts
static convertCatToNumeric(opts) {
opts.xaxis.type = 'numeric'
opts.xaxis.convertedCatToNumeric = true
opts.xaxis.labels = opts.xaxis.labels || {}
Expand All @@ -282,6 +281,7 @@ export default class Defaults {
function(val) {
return val
}
opts.chart = opts.chart || {}
opts.chart.zoom =
opts.chart.zoom || (window.Apex.chart && window.Apex.chart.zoom) || {}
const defaultFormatter = opts.xaxis.labels.formatter
Expand All @@ -299,6 +299,8 @@ export default class Defaults {
opts.xaxis.categories = []
opts.labels = []
opts.chart.zoom.enabled = false

return opts
}

bubble() {
Expand Down

0 comments on commit 5c252b3

Please sign in to comment.