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: reset title, subtitle and type when removing attribute #7816

Merged
merged 1 commit into from
Sep 18, 2024
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
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
Loading