Skip to content

Commit

Permalink
Labels are now rendered independently of symbols, ensuring consistent…
Browse files Browse the repository at this point in the history
… display even when symbol: 'none'.
  • Loading branch information
Shashwati committed Feb 8, 2025
1 parent d54443d commit 5cbef33
Showing 1 changed file with 50 additions and 19 deletions.
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

0 comments on commit 5cbef33

Please sign in to comment.