Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix heatmap yaxis offset #4429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 10 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,14 @@ 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
}
lY += parseInt(w.config.yaxis[realIndex].labels.style.fontSize, 10) / 3
for (let i = tickAmount; i >= 0; i--) {
let val = labels[i]

Expand Down Expand Up @@ -99,17 +105,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 +137,7 @@ export default class YAxis {
`rotate(${w.config.yaxis[realIndex].labels.rotate} ${firstabelRotatingCenter.x} ${labelRotatingCenter.y})`
)
}
l = l + labelsDivider
lY += labelsDivider
}
}

Expand Down