Skip to content

Commit

Permalink
fix #4422; prevent duplicate labels in y-axis
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Jul 11, 2024
1 parent 67f48e5 commit 1af289f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
10 changes: 6 additions & 4 deletions samples/react/mixed/duplicate-labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,19 @@
tooltip: {
shared: false,
intersect: true,
y: {
formatter: function(val) {
return val.toFixed(1)
}
}
},
legend: {
show: false
},
yaxis: {
labels: {
formatter: function(val) {
<!--Removal of duplicate labels can only be done within the formatter itself-->
let ref = val;
val = ref.toFixed(0);
return val == ref ? val : ''; <!--Don't use '===' here-->
return val.toFixed(0)
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions samples/source/mixed/duplicate-labels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ markers: {
tooltip: {
shared: false,
intersect: true,
y: {
formatter: function(val) {
return val.toFixed(1)
}
}
},
legend: {
show: false
},
yaxis: {
labels: {
formatter: function(val) {
<!--Removal of duplicate labels can only be done within the formatter itself-->
let ref = val;
val = ref.toFixed(0);
return val == ref ? val : ''; <!--Don't use '===' here-->
return val.toFixed(0)
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions samples/vanilla-js/mixed/duplicate-labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@
tooltip: {
shared: false,
intersect: true,
y: {
formatter: function(val) {
return val.toFixed(1)
}
}
},
legend: {
show: false
},
yaxis: {
labels: {
formatter: function(val) {
<!--Removal of duplicate labels can only be done within the formatter itself-->
let ref = val;
val = ref.toFixed(0);
return val == ref ? val : ''; <!--Don't use '===' here-->
return val.toFixed(0)
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions samples/vue/mixed/duplicate-labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,19 @@
tooltip: {
shared: false,
intersect: true,
y: {
formatter: function(val) {
return val.toFixed(1)
}
}
},
legend: {
show: false
},
yaxis: {
labels: {
formatter: function(val) {
<!--Removal of duplicate labels can only be done within the formatter itself-->
let ref = val;
val = ref.toFixed(0);
return val == ref ? val : ''; <!--Don't use '===' here-->
return val.toFixed(0)
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/modules/axes/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ export default class YAxis {
const getForeColor = () => {
return Array.isArray(yColors) ? yColors[i] : yColors
}

let existingYLabels = Utils.listToArray(
w.globals.dom.baseEl.querySelectorAll(
`.apexcharts-yaxis[rel='${realIndex}'] .apexcharts-yaxis-label tspan`
)
).map((_) => _.textContent)

let label = graphics.drawText({
x: xPad,
y: lY,
text: val,
text: existingYLabels.indexOf(val) >= 0 ? '' : val,
textAnchor,
fontSize: yaxisFontSize,
fontFamily: yaxisFontFamily,
Expand Down

0 comments on commit 1af289f

Please sign in to comment.