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

bugfix/20792-plotline-html-labels #20814

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
130 changes: 74 additions & 56 deletions samples/unit-tests/plotbandslines/plotbandslines/demo.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
QUnit.test('Plot band labels', function (assert) {
var chart,
options = {
chart: {
width: 600
},
xAxis: {
plotBands: [
{
from: 5,
to: 6,
color: Highcharts.getOptions().colors[0],
label: {
text: 'Before'
}
},
{
from: 12,
to: 13,
color: Highcharts.getOptions().colors[2],
label: {
text: 'Within'
}
},
{
from: 25,
to: 26,
color: Highcharts.getOptions().colors[3],
label: {
text: 'After'
}
let chart;
const options = {
chart: {
width: 600
},
xAxis: {
plotBands: [
{
from: 5,
to: 6,
color: Highcharts.getOptions().colors[0],
label: {
text: 'Before'
}
]
},

yAxis: {
plotLines: [{
value: 4,
},
{
from: 12,
to: 13,
color: Highcharts.getOptions().colors[2],
label: {
text: 'Big text',
useHTML: true,
style: {
fontSize: '2em'
},
align: 'right'
text: 'Within'
}
}, {
value: 5,
},
{
from: 25,
to: 26,
color: Highcharts.getOptions().colors[3],
label: {
text: 'Small text',
useHTML: true,
align: 'right'
text: 'After'
}
}]
},

series: [
},
{
data: [1, 2, 3, 4, 5, 6, 7],
pointStart: 10
value: 11,
label: {
text: 'Abcdef',
x: 0,
useHTML: true
}
}
]
};
},

yAxis: {
plotLines: [{
value: 4,
label: {
text: 'Big text',
useHTML: true,
style: {
fontSize: '2em'
},
align: 'right'
}
}, {
value: 5,
label: {
text: 'Small text',
useHTML: true,
align: 'right'
}
}]
},

series: [
{
data: [1, 2, 3, 4, 5, 6, 7],
pointStart: 10
}
]
};

// Create the Highcharts chart
chart = $('#container').highcharts(options).highcharts();
chart = Highcharts.chart('container', options);

assert.equal(
typeof chart.xAxis[0].plotLinesAndBands[0].label,
Expand All @@ -81,8 +89,18 @@ QUnit.test('Plot band labels', function (assert) {
'Highcharts - after'
);

const line = chart.xAxis[0].plotLinesAndBands[3].svgElem.getBBox(),
label = chart.xAxis[0].plotLinesAndBands[3].label;

assert.close(
line.x,
label.x,
1,
'HTML label should be placed (x-pos) near the plot line (#20792).'
);

// Create the Highcharts Stock chart
chart = $('#container').highcharts('StockChart', options).highcharts();
chart = Highcharts.stockChart('container', options);

assert.equal(
typeof chart.xAxis[0].plotLinesAndBands[0].label,
Expand Down
12 changes: 8 additions & 4 deletions ts/Core/Axis/PlotLineOrBand/PlotLineOrBand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ class PlotLineOrBand {
) {
// Apply defaults
optionsLabel = merge({
align: horiz && isBand && 'center',
align: horiz && isBand ? 'center' : void 0,
x: horiz ? !isBand && 4 : 10,
verticalAlign: !horiz && isBand && 'middle',
verticalAlign: !horiz && isBand ? 'middle' : void 0,
y: horiz ? isBand ? 16 : 10 : isBand ? 6 : -4,
rotation: horiz && !isBand && 90
rotation: horiz && !isBand ? 90 : 0
} as PlotLineLabelOptions, optionsLabel);

this.renderLabel(optionsLabel, path, isBand, zIndex);
Expand Down Expand Up @@ -325,7 +325,11 @@ class PlotLineOrBand {
align: optionsLabel.textAlign || optionsLabel.align,
rotation: optionsLabel.rotation,
'class': 'highcharts-plot-' + (isBand ? 'band' : 'line') +
'-label ' + (optionsLabel.className || ''),
'-label' + (
optionsLabel.className ?
'-' + optionsLabel.className :
hubertkozik marked this conversation as resolved.
Show resolved Hide resolved
''
),
zIndex
});

Expand Down