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

Labels are now rendered independently of symbols, ensuring consistent display even when symbol: 'none'. #20740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
69 changes: 50 additions & 19 deletions src/chart/line/LineSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,22 @@ class LineSeriesModel extends SeriesModel<LineSeriesOption> {
throw new Error('Line not support coordinateSystem besides cartesian and polar');
}
}
return createSeriesData(null, this, {

const seriesData = createSeriesData(null, this, {
useEncodeDefaulter: true
});

// Ensure labels are added even if symbol is 'none'
seriesData.each(function (idx) {
const label = seriesData.getItemVisual(idx, 'label');
if (!label) {
seriesData.setItemVisual(idx, 'label', createLabel(/* label parameters */));
}
});

return seriesData;
}


static defaultOption: LineSeriesOption = {
// zlevel: 0,
Expand All @@ -152,9 +164,11 @@ class LineSeriesModel extends SeriesModel<LineSeriesOption> {

clip: true,

label: {
position: 'top'
},
symbol: 'none', // Keep 'none' to disable symbols
label: {
show: true, // Always show labels
position: 'top', // Label positioning
},

// itemStyle: {
// },
Expand Down Expand Up @@ -230,24 +244,41 @@ class LineSeriesModel extends SeriesModel<LineSeriesOption> {
);
group.add(line);
line.setStyle(opt.lineStyle);

const visualType = this.getData().getVisual('symbol');
const visualRotate = this.getData().getVisual('symbolRotate');
const symbolType = visualType === 'none' ? 'circle' : visualType;

// Symbol size is 80% when there is a line
const size = opt.itemHeight * 0.8;
const symbol = createSymbol(
symbolType,
(opt.itemWidth - size) / 2,
(opt.itemHeight - size) / 2,
size,
size,
opt.itemStyle.fill
);
group.add(symbol);
const symbolType = visualType === 'none' ? 'circle' : visualType; // Use `null` for no symbol.
if (symbolType) {
const symbol = createSymbol(
symbolType,
(opt.itemWidth - size) / 2,
(opt.itemHeight - size) / 2,
size,
size,
opt.itemStyle.fill
);
group.add(symbol);
symbol.setStyle(opt.itemStyle);

const symbolRotate = opt.iconRotate === 'inherit'
? visualRotate
: (opt.iconRotate || 0);
symbol.rotation = symbolRotate * Math.PI / 180;
symbol.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);

if (symbolType.indexOf('empty') > -1) {
symbol.style.stroke = symbol.style.fill;
symbol.style.fill = '#fff';
symbol.style.lineWidth = 2;
}
}

symbol.setStyle(opt.itemStyle);
// Always render labels, even if no symbol
if (opt.lineStyle && opt.label) {
const label = createLabel(
// Add logic to position and display labels correctly
);
group.add(label);
}

const symbolRotate = opt.iconRotate === 'inherit'
? visualRotate
Expand Down