-
Notifications
You must be signed in to change notification settings - Fork 21
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
Draft: add bar and column charts #3512
Draft
helenb
wants to merge
21
commits into
feature/set-up-highchart
Choose a base branch
from
feature/bar-and-column-charts
base: feature/set-up-highchart
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
40bb177
Disable hover effects on series, tooltips, and click events on the le…
helenb c5fbe27
update chart
precious-onyenaucheya-ons 9f68d79
add macro test and fix bug with legend
precious-onyenaucheya-ons b025fef
remove data labels options
precious-onyenaucheya-ons 0304e20
remove animation params
precious-onyenaucheya-ons d11043c
turn off animation in chart
precious-onyenaucheya-ons 081cbaa
add prettier ignore
precious-onyenaucheya-ons c208584
approve visual test
precious-onyenaucheya-ons cb73a21
update fonts to use data viz guide
precious-onyenaucheya-ons 0f700a0
Remove Google analytics not connected logging message (#3510)
SriHV 6178cc0
approve failed visual tests
precious-onyenaucheya-ons ac3438f
Create bar chart and clustered bar chart examples
helenb dee87b2
Add a common chart-constants file, and set a different colour for cat…
helenb c211369
Fix zero line colour, and move y axis label for bar charts
helenb 396242a
Remove category tick marks for bar charts
helenb 0a025d3
update docs to add useStackedLayout params
precious-onyenaucheya-ons c1fe821
Refactor to move functions that relate to specfic chart types to the …
helenb 4d51e4c
Ensure the data labels are updated when the window is resized
helenb 74f1254
Add the column chart example and tweak the xAxis label style
helenb c15aa62
Update the merge function to recursively merge the configuration obje…
helenb db95d53
Add clustered column chart example
helenb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...erence/ds-vr-test__components_chart_example-line-chart_0_document_0_desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/ds-vr-test__components_chart_example-line-chart_0_document_1_tablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/ds-vr-test__components_chart_example-line-chart_0_document_2_mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** @jest-environment jsdom */ | ||
|
||
import * as cheerio from 'cheerio'; | ||
|
||
import axe from '../../tests/helpers/axe'; | ||
import { renderComponent } from '../../tests/helpers/rendering'; | ||
import { EXAMPLE_CHART_REQUIRED_PARAMS, EXAMPLE_CHART_WITH_CONFIG_PARAMS } from './_test-examples'; | ||
|
||
describe('FOR: Macro: Chart', () => { | ||
describe('GIVEN: Params: required', () => { | ||
describe('WHEN: required params are provided', () => { | ||
const $ = cheerio.load(renderComponent('chart', EXAMPLE_CHART_REQUIRED_PARAMS)); | ||
|
||
test('THEN: it passes jest-axe checks', async () => { | ||
const results = await axe($.html()); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
test('THEN: it renders the chart container with the correct data attributes', () => { | ||
expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('line'); | ||
expect($('[data-highcharts-base-chart]').attr('data-highcharts-theme')).toBe('primary'); | ||
expect($('[data-highcharts-base-chart]').attr('data-highcharts-title')).toBe('Example Line Chart'); | ||
expect($('[data-highcharts-base-chart]').attr('data-highcharts-uuid')).toBe('chart-123'); | ||
}); | ||
|
||
test('THEN: it includes the Highcharts JSON config', () => { | ||
const configScript = $(`script[data-highcharts-config--chart-123]`).html(); | ||
expect(configScript).toContain('"type":"line"'); | ||
expect(configScript).toContain('"text":"X Axis Title"'); | ||
expect(configScript).toContain('"text":"Y Axis Title"'); | ||
}); | ||
|
||
test('THEN: it does NOT render optional fields', () => { | ||
expect($('figcaption').length).toBe(0); | ||
expect($('.ons-chart__download-title').length).toBe(0); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GIVEN: Params: Config', () => { | ||
describe('WHEN: config params are provided', () => { | ||
const $ = cheerio.load(renderComponent('chart', EXAMPLE_CHART_WITH_CONFIG_PARAMS)); | ||
|
||
test('THEN: it renders the legend when enabled', () => { | ||
const configScript = $(`script[data-highcharts-config--chart-456]`).html(); | ||
expect(configScript).toContain('"enabled":true'); | ||
expect(configScript).toContain('"align":"right"'); | ||
expect(configScript).toContain('"verticalAlign":"top"'); | ||
expect(configScript).toContain('"layout":"vertical"'); | ||
}); | ||
|
||
test('THEN: it includes correct xAxis and yAxis titles', () => { | ||
const configScript = $(`script[data-highcharts-config--chart-456]`).html(); | ||
expect(configScript).toContain('"text":"X Axis Label"'); | ||
expect(configScript).toContain('"text":"Y Axis Label"'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GIVEN: Params: Caption', () => { | ||
describe('WHEN: caption is provided', () => { | ||
const $ = cheerio.load( | ||
renderComponent('chart', { | ||
...EXAMPLE_CHART_REQUIRED_PARAMS, | ||
caption: 'This is an example caption for the chart.', | ||
}), | ||
); | ||
|
||
test('THEN: it renders the caption when provided', () => { | ||
expect($('figcaption').text()).toBe('This is an example caption for the chart.'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GIVEN: Params: Description)', () => { | ||
describe('WHEN: description is provided', () => { | ||
const $ = cheerio.load( | ||
renderComponent('chart', { | ||
...EXAMPLE_CHART_REQUIRED_PARAMS, | ||
description: 'An accessible description for screen readers.', | ||
}), | ||
); | ||
|
||
test('THEN: it renders the description for accessibility', () => { | ||
expect($('.ons-u-vh').text()).toBe('An accessible description for screen readers.'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GIVEN: Params: Download)', () => { | ||
describe('WHEN: download object are provided', () => { | ||
const $ = cheerio.load( | ||
renderComponent('chart', { | ||
...EXAMPLE_CHART_REQUIRED_PARAMS, | ||
download: { | ||
title: 'Download Chart Data', | ||
itemsList: [ | ||
{ text: 'Download as PNG', url: 'https://example.com/chart.png' }, | ||
{ text: 'Download as CSV', url: 'https://example.com/chart.csv' }, | ||
], | ||
}, | ||
}), | ||
); | ||
|
||
test('THEN: it renders the download section correctly', () => { | ||
expect($('.ons-chart__download-title').text()).toBe('Download Chart Data'); | ||
|
||
const downloadLinks = $('.ons-chart__download-title').next().find('li a'); | ||
expect(downloadLinks.eq(0).text()).toBe('Download as PNG'); | ||
expect(downloadLinks.eq(0).attr('href')).toBe('https://example.com/chart.png'); | ||
expect(downloadLinks.eq(1).text()).toBe('Download as CSV'); | ||
expect(downloadLinks.eq(1).attr('href')).toBe('https://example.com/chart.csv'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const EXAMPLE_CHART_REQUIRED_PARAMS = { | ||
chartType: 'line', | ||
theme: 'primary', | ||
title: 'Example Line Chart', | ||
subtitle: 'A sample subtitle', | ||
uuid: 'chart-123', | ||
config: { | ||
chart: { type: 'line' }, | ||
xAxis: { title: { text: 'X Axis Title' }, categories: ['Jan', 'Feb', 'Mar'] }, | ||
yAxis: { title: { text: 'Y Axis Title' } }, | ||
series: [ | ||
{ name: 'Series 1', data: [10, 20, 30] }, | ||
{ name: 'Series 2', data: [15, 25, 35] }, | ||
], | ||
}, | ||
}; | ||
|
||
export const EXAMPLE_CHART_WITH_CONFIG_PARAMS = { | ||
chartType: 'bar', | ||
theme: 'alternate', | ||
title: 'Example Bar Chart', | ||
subtitle: 'A detailed subtitle', | ||
uuid: 'chart-456', | ||
config: { | ||
chart: { type: 'bar' }, | ||
legend: { enabled: true, align: 'right', verticalAlign: 'top', layout: 'vertical' }, | ||
xAxis: { title: { text: 'X Axis Label' }, categories: ['A', 'B', 'C'] }, | ||
yAxis: { title: { text: 'Y Axis Label' }, reversed: false }, | ||
series: [ | ||
{ name: 'Category 1', data: [5, 15, 25] }, | ||
{ name: 'Category 2', data: [10, 20, 30] }, | ||
], | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@precious-onyenaucheya-ons I assume I should remove this change - I think yarn added it automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please