Skip to content

Commit

Permalink
cropped yaxis labels when multiple yaxis - fixes #98
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Oct 13, 2018
1 parent c1d88b1 commit 43236ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/modules/Dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ class Dimensions {
} else {
this.yAxisWidth = w.globals.yLabelsCoords[0].width + w.globals.yTitleCoords[0].width + 15
}
if (this.yAxisWidth < w.config.yaxis[0].labels.minWidth) {
this.yAxisWidth = w.config.yaxis[0].labels.maxWidth
}
if (this.yAxisWidth > w.config.yaxis[0].labels.maxWidth) {
this.yAxisWidth = w.config.yaxis[0].labels.maxWidth

if (!w.globals.isMultipleYAxis) {
if (this.yAxisWidth < w.config.yaxis[0].labels.minWidth) {
this.yAxisWidth = w.config.yaxis[0].labels.minWidth
}
if (this.yAxisWidth > w.config.yaxis[0].labels.maxWidth) {
this.yAxisWidth = w.config.yaxis[0].labels.maxWidth
}
}
}

Expand Down Expand Up @@ -293,7 +296,7 @@ class Dimensions {
if (yLabelCoord.width > 0 && !floating) {
yAxisWidth = yAxisWidth + yLabelCoord.width + padding
if (w.globals.ignoreYAxisIndexes.includes(index)) {
yAxisWidth = yAxisWidth - yLabelCoord.width
yAxisWidth = yAxisWidth - yLabelCoord.width - padding
}
} else {
yAxisWidth = yAxisWidth + (floating ? 0 : 5)
Expand All @@ -302,10 +305,11 @@ class Dimensions {

w.globals.yTitleCoords.map((yTitleCoord, index) => {
let floating = w.config.yaxis[index].floating
padding = (parseInt(w.config.yaxis[index].title.style.fontSize))
if (yTitleCoord.width > 0 && !floating) {
yAxisWidth = yAxisWidth + yTitleCoord.width + (parseInt(w.config.yaxis[index].title.style.fontSize))
yAxisWidth = yAxisWidth + yTitleCoord.width + padding
if (w.globals.ignoreYAxisIndexes.includes(index)) {
yAxisWidth = yAxisWidth - yTitleCoord.width
yAxisWidth = yAxisWidth - yTitleCoord.width - padding
}
} else {
yAxisWidth = yAxisWidth + (floating ? 0 : 5)
Expand Down Expand Up @@ -434,7 +438,7 @@ class Dimensions {
let labelPad = 10

w.config.yaxis.map((yaxe, index) => {
if (yaxe.labels.show && w.globals.yAxisScale[index].result.length) {
if (yaxe.show && yaxe.labels.show && w.globals.yAxisScale[index].result.length) {
let lbFormatter = w.globals.yLabelFormatters[index]
let val = lbFormatter(w.globals.yAxisScale[index].niceMax)

Expand Down Expand Up @@ -504,7 +508,7 @@ class Dimensions {
let ret = []

w.config.yaxis.map((yaxe, index) => {
if (yaxe.title.text !== undefined) {
if (yaxe.show && yaxe.title.text !== undefined) {
let graphics = new Graphics(this.ctx)
let rect = graphics.getTextRects(yaxe.title.text, yaxe.title.style.fontSize, yaxe.title.style.fontFamily, 'rotate(-90 0 0)', false)

Expand Down
4 changes: 4 additions & 0 deletions src/modules/axes/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class YAxis {
'translate(' + w.globals.translateYAxisX[realIndex] + ', 0)'
})

if (!w.config.yaxis[realIndex].show) {
return elYaxis
}

let elYaxisTexts = graphics.group({
'class': 'apexcharts-yaxis-texts-g'
})
Expand Down
1 change: 1 addition & 0 deletions src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class Options {
this.defaultFont = 'Helvetica, Arial, sans-serif'

this.yAxis = {
show: true,
opposite: false,
tickAmount: 6,
max: undefined,
Expand Down

0 comments on commit 43236ea

Please sign in to comment.