Skip to content

Commit

Permalink
fix: reset title, subtitle and type when removing attribute (#7816) (#…
Browse files Browse the repository at this point in the history
…7819)

Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan committed Sep 18, 2024
1 parent f040195 commit 1dcf85e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,7 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
return;
}

if (title && title.length > 0) {
config.title.update({ text: title });
}
config.title.update({ text: title });
}

/** @private */
Expand All @@ -1575,11 +1573,9 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
return;
}

if (type && type.length > 0) {
config.update({
chart: { type },
});
}
config.update({
chart: { type: type || 'line' },
});
}

/** @private */
Expand All @@ -1588,12 +1584,10 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
return;
}

if (subtitle && subtitle.length > 0) {
if (!config.subtitle) {
config.setSubtitle({ text: subtitle });
} else {
config.subtitle.update({ text: subtitle });
}
if (!config.subtitle) {
config.setSubtitle({ text: subtitle });
} else {
config.subtitle.update({ text: subtitle });
}
}

Expand Down
48 changes: 48 additions & 0 deletions packages/charts/test/chart-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ import '../vaadin-chart.js';
import Highcharts from 'highcharts/es-modules/masters/highstock.src.js';

describe('vaadin-chart properties', () => {
describe('title', () => {
let chart, chartContainer;

beforeEach(async () => {
chart = fixtureSync(`
<vaadin-chart title="My title">
<vaadin-chart-series values="[10, 20, 30, 40, 50]"></vaadin-chart-series>
</vaadin-chart>
`);
await oneEvent(chart, 'chart-load');
chartContainer = chart.$.chart;
});

it('should have custom title', () => {
expect(chartContainer.querySelector('.highcharts-title').textContent).to.be.equal('My title');
});

it('should reset title when property is set to null', () => {
chart.title = null;
expect(chartContainer.querySelector('.highcharts-title').textContent).to.be.equal('');
});

it('should reset title when attribute is removed', () => {
chart.removeAttribute('title');
expect(chartContainer.querySelector('.highcharts-title').textContent).to.be.equal('');
});
});

describe('subtitle', () => {
let chart, chartContainer;

Expand All @@ -28,6 +56,16 @@ describe('vaadin-chart properties', () => {
expect(chartContainer.querySelector('.highcharts-title').textContent).to.equal('Awesome chart');
expect(chartContainer.querySelector('.highcharts-subtitle').textContent).to.equal('My subtitle');
});

it('should reset subtitle when property is set to null', () => {
chart.subtitle = null;
expect(chartContainer.querySelector('.highcharts-subtitle').textContent).to.be.equal('');
});

it('should reset subtitle when attribute is removed', () => {
chart.removeAttribute('subtitle');
expect(chartContainer.querySelector('.highcharts-subtitle').textContent).to.be.equal('');
});
});

describe('type', () => {
Expand All @@ -49,6 +87,16 @@ describe('vaadin-chart properties', () => {
const text = Array.from(series).map((node) => node.textContent);
expect(text).to.be.deep.equal(['80']);
});

it('should reset type to line when type property is set to null', () => {
chart.type = null;
expect(chart.configuration.types).to.eql(['line']);
});

it('should reset type to line when type attribute is removed', () => {
chart.removeAttribute('type');
expect(chart.configuration.types).to.eql(['line']);
});
});

describe('additionalOptions', () => {
Expand Down

0 comments on commit 1dcf85e

Please sign in to comment.