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(interactive-chart): legend not update when add new seriesList #959

Merged
merged 13 commits into from
Sep 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,40 @@ describe('interactive-chart/InteractiveChart', function () {
expect(legendLeftPosition).to.equal(InteractiveChart.DEFAULT_LEGEND_LEFT_POSITION);
});

it('Should render new Legend when add new seriesList.', async function () {
const data = [
{
time: 1678147200,
open: 5679,
high: 5694,
low: 5544,
close: 5547,
value: 5547
}
];
el.config = {
series: [
{
symbol: 'Price',
type: 'candlestick'
}
]
};
await elementUpdated(el);
await nextFrame(3); // wait for resize observer & rendering completion
expect(el.hasDataPoint).to.be.false;

el.config.series[0].data = data;
el.seriesList[0].setData(data);
await elementUpdated(el);
await nextFrame(3); // wait for resize observer & rendering completion
const legendText = el.rowLegend[0].textContent;
const { open, high, low, close } = data[0];
const isIncludedPrices = [open, high, low, close].every((price) => legendText.includes(price));
expect(el.hasDataPoint).to.be.true;
expect(isIncludedPrices).to.be.true;
});

describe('Test deprecated attribute', function () {
it('Switch attribute legendstyle horizontal to vertical, it should display vertical style', async function () {
el = await fixture('<ef-interactive-chart legendstyle="horizontal"></ef-interactive-chart>');
Expand Down
1 change: 1 addition & 0 deletions packages/elements/src/interactive-chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ export class InteractiveChart extends ResponsiveElement {
const dataSet = series.data || [];
const latestData = dataSet[dataSet.length - 1];
if (latestData) {
this.hasDataPoint = dataSet.length > 0;
const value =
chartType === 'bar' || chartType === 'candlestick' ? latestData : (latestData as LineData).value; // latestData
const priceColor = this.getColorInSeries(latestData, chartType, idx);
Expand Down
Loading