Skip to content

Commit

Permalink
fix heatmap yaxis offset apexcharts#2033
Browse files Browse the repository at this point in the history
  • Loading branch information
cart-before-horse committed Apr 24, 2024
1 parent 96d8342 commit 8df4c60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
18 changes: 7 additions & 11 deletions src/modules/axes/AxesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,17 @@ export default class AxesUtils {
let graphics = new Graphics(this.ctx)

// initial label position = 0;
let t = w.globals.translateY
let tY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY
if (w.globals.isBarHorizontal) {
tY = 0
} else if (w.config.chart.type === 'heatmap') {
tY += labelsDivider / 2
}

if (axisTicks.show && tickAmount > 0) {
if (w.config.yaxis[realIndex].opposite === true) x = x + axisTicks.width

for (let i = tickAmount; i >= 0; i--) {
let tY =
t + tickAmount / 10 + w.config.yaxis[realIndex].labels.offsetY - 1
if (w.globals.isBarHorizontal) {
tY = labelsDivider * i
}

if (w.config.chart.type === 'heatmap') {
tY = tY + labelsDivider / 2
}
let elTick = graphics.drawLine(
x + axisBorder.offsetX - axisTicks.width + axisTicks.offsetX,
tY + axisTicks.offsetY,
Expand All @@ -268,7 +264,7 @@ export default class AxesUtils {
axisTicks.color
)
elYaxis.add(elTick)
t = t + labelsDivider
tY += labelsDivider
}
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/modules/axes/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export default class YAxis {
// labelsDivider is simply svg height/number of ticks
let labelsDivider = w.globals.gridHeight / tickAmount

// initial label position = 0;
let l = w.globals.translateY
let lbFormatter = w.globals.yLabelFormatters[realIndex]

let labels = w.globals.yAxisScale[realIndex].result.slice()
Expand All @@ -70,6 +68,13 @@ export default class YAxis {

let firstLabel = ''
if (w.config.yaxis[realIndex].labels.show) {
// initial label position = 0;
let lY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY
if (w.globals.isBarHorizontal) {
lY = 0
} else if (w.config.chart.type === 'heatmap') {
lY -= labelsDivider / 2
}
for (let i = tickAmount; i >= 0; i--) {
let val = labels[i]

Expand Down Expand Up @@ -99,17 +104,9 @@ export default class YAxis {
const getForeColor = () => {
return Array.isArray(yColors) ? yColors[i] : yColors
}

let offsetY = w.config.yaxis[realIndex].labels.offsetY

if (w.config.chart.type === 'heatmap') {
const divisor = w.globals.gridHeight / w.globals.series.length - 1
offsetY = offsetY - divisor / 2
}

let label = graphics.drawText({
x: xPad,
y: l + tickAmount / 10 + offsetY + 1,
y: lY,
text: val,
textAnchor,
fontSize: yaxisFontSize,
Expand Down Expand Up @@ -139,7 +136,7 @@ export default class YAxis {
`rotate(${w.config.yaxis[realIndex].labels.rotate} ${firstabelRotatingCenter.x} ${labelRotatingCenter.y})`
)
}
l = l + labelsDivider
lY += labelsDivider
}
}

Expand Down

0 comments on commit 8df4c60

Please sign in to comment.