-
Notifications
You must be signed in to change notification settings - Fork 51
[SPIKE] Carbon charts exploration - various charts #3100
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
KristinLBradley
wants to merge
8
commits into
main
Choose a base branch
from
kristin/hds-5289-carbon-charts-exploration
base: main
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
8 commits
Select commit
Hold shift + click to select a range
8ccd8aa
HDS-5289 Add basic example donut chart using Carbon Charts DonutChart
KristinLBradley 9cce992
HDS-5289 Add data sets and examples similar to Cloud-ui charts
KristinLBradley b38a313
HDS-5289 Add colorMap option to Donut, pass in custom colors for serv…
KristinLBradley e0276f2
HDS-5289 Remove level from Card examples
KristinLBradley f943c9f
HDS-5289 Add Meter Chart components based on Carbon Charts Meter, con…
KristinLBradley 9079bee
HDS-5289 Add simple bar chart component with Showcase example
KristinLBradley 373c173
HDS-5289 Add title to donut chart example
KristinLBradley c624dd8
HDS-5289 Fix failing tests
KristinLBradley 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 hidden or 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 hidden or 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,6 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
|
|
||
| <div {{did-insert this.setupChart}} class="hds-charts-bar" ...attributes></div> |
43 changes: 43 additions & 0 deletions
43
packages/components/src/components/hds/charts/bar/index.ts
This file contains hidden or 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,43 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| import { SimpleBarChart } from '@carbon/charts'; | ||
| import options from './options.js'; | ||
| import '@carbon/charts/styles.css'; | ||
|
|
||
| export interface HdsChartsBarSignature { | ||
| Args: { | ||
| title?: string; | ||
| data: Array<{ group: string; date: string; value: number }>; | ||
| }; | ||
| Blocks: { | ||
| default: []; | ||
| }; | ||
| Element: HTMLDivElement; | ||
| } | ||
|
|
||
| export default class HdsChartsBar extends Component<HdsChartsBarSignature> { | ||
| chart: SimpleBarChart | null = null; | ||
|
|
||
| @action | ||
| setupChart(element: HTMLDivElement): void { | ||
| const chartData = this.args.data; | ||
|
|
||
| // Merge the dynamic options into the default options | ||
| const chartOptions = { | ||
| ...options, | ||
| title: this.args.title || options.title, | ||
| }; | ||
|
|
||
| // Create the SimpleBarChart instance | ||
| this.chart = new SimpleBarChart(element, { | ||
| data: chartData, | ||
| options: chartOptions, | ||
| }); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
packages/components/src/components/hds/charts/bar/options.js
This file contains hidden or 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,26 @@ | ||
| import { ScaleTypes } from '@carbon/charts'; | ||
|
|
||
| export default { | ||
| title: '', | ||
| toolbar: { | ||
| enabled: false, // hide toolbar | ||
| }, | ||
| axes: { | ||
| left: { | ||
| mapsTo: 'value', | ||
| }, | ||
| bottom: { | ||
| mapsTo: 'date', | ||
| scaleType: ScaleTypes.LABELS, | ||
| }, | ||
| }, | ||
| grid: { | ||
| x: { | ||
| numberOfTicks: 0, | ||
| }, | ||
| }, | ||
| height: '400px', | ||
| legend: { | ||
| enabled: false, // hide legend (for single color bar chart) | ||
| }, | ||
| }; |
6 changes: 6 additions & 0 deletions
6
packages/components/src/components/hds/charts/donut/index.hbs
This file contains hidden or 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,6 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
|
|
||
| <div {{did-insert this.setupChart}} class="hds-charts-donut" ...attributes></div> |
46 changes: 46 additions & 0 deletions
46
packages/components/src/components/hds/charts/donut/index.ts
This file contains hidden or 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,46 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| import { DonutChart } from '@carbon/charts'; | ||
| import options from './options.js'; | ||
| import '@carbon/charts/styles.css'; | ||
| export interface HdsChartsDonutSignature { | ||
| Args: { | ||
| title?: string; | ||
| data: Array<{ group: string; value: number }>; | ||
| colorMap?: { [key: string]: string }; // Optional custom colors for the chart segments/slices | ||
| }; | ||
| Blocks: { | ||
| default: []; | ||
| }; | ||
| Element: HTMLDivElement; | ||
| } | ||
|
|
||
| export default class HdsChartsDonut extends Component<HdsChartsDonutSignature> { | ||
| chart: DonutChart | null = null; | ||
|
|
||
| @action | ||
| setupChart(element: HTMLDivElement): void { | ||
| const chartData = this.args.data; | ||
|
|
||
| // Merge the dynamic options into the default options | ||
| const chartOptions = { | ||
| ...options, | ||
| title: this.args.title || options.title, | ||
| color: { | ||
| scale: this.args.colorMap, | ||
| }, | ||
| }; | ||
|
|
||
| // Create the DonutChart instance | ||
| this.chart = new DonutChart(element, { | ||
| data: chartData, | ||
| options: chartOptions, | ||
| }); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
packages/components/src/components/hds/charts/donut/options.js
This file contains hidden or 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,24 @@ | ||
| export default { | ||
| title: '', // Set title using @title on the component | ||
| resizable: true, | ||
| legend: { | ||
| // alignment: 'left', // = alignment w/i container, options: 'left', 'right', 'center' | ||
| position: 'left', // = position relative to chart, options: 'top', 'bottom', 'left', 'right' | ||
| truncation: { | ||
| type: 'none', | ||
| }, | ||
| }, | ||
| toolbar: { | ||
| enabled: false, // hide toolbar | ||
| }, | ||
| donut: { | ||
| alignment: 'center', // = alignment w/i container, options: 'center', 'left', 'right' | ||
| }, | ||
| pie: { | ||
| labels: { | ||
| enabled: true, | ||
| formatter: (data) => data.value, | ||
| }, | ||
| }, | ||
| height: '175px', | ||
| }; |
6 changes: 6 additions & 0 deletions
6
packages/components/src/components/hds/charts/meter/index.hbs
This file contains hidden or 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,6 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
|
|
||
| <div class="hds-charts-meter" {{did-insert this.setupChart}} ...attributes></div> |
57 changes: 57 additions & 0 deletions
57
packages/components/src/components/hds/charts/meter/index.ts
This file contains hidden or 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,57 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| import { MeterChart } from '@carbon/charts'; | ||
| import options from './options.js'; | ||
| import '@carbon/charts/styles.css'; | ||
|
|
||
| export interface HdsChartsMeterSignature { | ||
| Args: { | ||
| title?: string; | ||
| data: Array<{ group: string; value: number }>; | ||
| total?: number; // if not passed in it will be calculated from the data | ||
| }; | ||
| Blocks: { | ||
| default: []; | ||
| }; | ||
| Element: HTMLDivElement; | ||
| } | ||
|
|
||
| export default class HdsChartsMeter extends Component<HdsChartsMeterSignature> { | ||
| chart: MeterChart | null = null; | ||
|
|
||
| @action | ||
| setupChart(element: HTMLDivElement): void { | ||
| const chartData = this.args.data; | ||
|
|
||
| // Dynamically calculate the total from the passed-in data | ||
| const chartTotal = chartData.reduce( | ||
| (sum, item): number => sum + item.value, | ||
| 0 | ||
| ); | ||
|
|
||
| // Merge the dynamic options into the default options | ||
| const chartOptions = { | ||
| ...options, | ||
| title: this.args.title || options.title, | ||
| meter: { | ||
| ...options.meter, | ||
| proportional: { | ||
| ...options.meter.proportional, | ||
| total: this.args.total || chartTotal, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| // Create the MeterChart instance | ||
| this.chart = new MeterChart(element, { | ||
| data: chartData, | ||
| options: chartOptions, | ||
| }); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
packages/components/src/components/hds/charts/meter/options.js
This file contains hidden or 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,12 @@ | ||
| export default { | ||
| title: '', | ||
| height: '130px', | ||
| meter: { | ||
| proportional: { | ||
| unit: '', | ||
| }, | ||
| }, | ||
| toolbar: { | ||
| enabled: false, // hide toolbar | ||
| }, | ||
| }; |
This file contains hidden or 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 hidden or 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,33 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| // | ||
| // CHARTS | ||
| // | ||
|
|
||
| // > DONUT | ||
|
|
||
| .hds-charts-donut { | ||
| // outline: 1px dotted red; // for testing - see boundaries of chart container | ||
|
|
||
| // increase stroke definition on slices (especially for resized/shrunken charts) | ||
| .slice { | ||
| stroke: #fff; | ||
| stroke-width: 1px; | ||
| } | ||
|
|
||
| // The size of the title affects the rendered size of the donut chart | ||
| .title { | ||
| min-height: 1.3em; | ||
| } | ||
| } | ||
|
|
||
| // > BAR | ||
|
|
||
| .hds-charts-bar { | ||
| .graph-frame { | ||
| overflow: hidden; // cut off bottom line which overflows container | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
I added this to improve the crispness of the thin white border on resized components, just as a test. (Not sure if we would actually want to recommend)