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

feat(core): create alluvial chart #1132

Merged
merged 46 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ea4536f
add d3-sankey package
Akshat55 Aug 26, 2021
bd97000
create enum of all alluvial related events
Akshat55 Aug 26, 2021
49e7259
create basic alluvial chart
Akshat55 Aug 26, 2021
a3ad8cd
add alluvial chart options
Akshat55 Aug 26, 2021
7c32b61
create alluvial chart wrapper
Akshat55 Aug 26, 2021
ffa35f2
fix linting issues
Akshat55 Aug 26, 2021
388ec42
define default alluvial configs
Akshat55 Aug 26, 2021
1809c02
create alluvial react component
Akshat55 Aug 26, 2021
0c55efc
create alluvial angular component
Akshat55 Aug 26, 2021
c711872
Add simple alluvial demo under complex charts
Akshat55 Aug 27, 2021
cda8e77
remove skeleton import and comments
Akshat55 Aug 28, 2021
efcbb7a
add style for themes
Akshat55 Aug 30, 2021
a31c72c
add logic to add space between node and textbox
Akshat55 Aug 30, 2021
57eabb4
Merge branch 'master' of https://github.com/Akshat55/carbon-charts in…
Akshat55 Aug 30, 2021
36790bf
add configs & node group title
Akshat55 Aug 30, 2021
49a826a
add line event listeners
Akshat55 Aug 31, 2021
43f32dc
declare and export alluvial in ngmodule
Akshat55 Sep 1, 2021
0556651
add node event listener
Akshat55 Sep 1, 2021
2a3c5c3
Add multiple category alluvial demo
Akshat55 Sep 1, 2021
783e3e7
add monochrome option
Akshat55 Sep 1, 2021
a7099b5
add combined monochrome and nodePadding demo
Akshat55 Sep 1, 2021
29b0bb8
remove stroke from node rectangles
Akshat55 Sep 1, 2021
909d0bc
Add delay to events to stop flashing behaviour
Akshat55 Sep 2, 2021
59d8bee
add graph traversal to highlight links that pass node
Akshat55 Sep 2, 2021
97ba637
set minimum node padding to 24
Akshat55 Sep 3, 2021
11ee0fc
add units in aria-label and tooltip
Akshat55 Sep 3, 2021
e65f19f
update demo names
Akshat55 Sep 3, 2021
1ab3905
export alluvial chart
Akshat55 Sep 3, 2021
59a30ff
add condition to prevent firefox error
Akshat55 Sep 3, 2021
9ee1911
Merge branch 'carbon-design-system:master' into alluvial
Akshat55 Sep 3, 2021
fb38ff8
feat(core): create alluvial chart
Akshat55 Sep 3, 2021
433b0a7
Merge branch 'carbon-design-system:master' into alluvial
Akshat55 Sep 8, 2021
8e18b98
filter out unused nodes from rendering
Akshat55 Sep 9, 2021
d5d7873
update debounce for line events
Akshat55 Sep 9, 2021
f368d6f
update debounce for node events
Akshat55 Sep 9, 2021
9dc9439
order complex demos alphabetically
Akshat55 Sep 9, 2021
6b8c5b9
decrease debounce time
Akshat55 Sep 9, 2021
f5277b3
Merge remote-tracking branch 'upstream/master' into alluvial
Akshat55 Sep 9, 2021
6ef7885
improve link hover debounce
Akshat55 Sep 9, 2021
cbe901b
exclude legend from alluvial
Akshat55 Sep 9, 2021
84c5f7c
fix review changes
Akshat55 Sep 10, 2021
70bb9dc
wrap alluvial options in respective key
Akshat55 Sep 10, 2021
3f8106c
improve node debounce highlighting
Akshat55 Sep 12, 2021
7974f96
deep clone user passed data when creating graph
Akshat55 Sep 13, 2021
ff2d048
remove trailing space in aria-label
Akshat55 Sep 15, 2021
cef1bb0
Merge branch 'master' into alluvial
Akshat55 Sep 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/angular/src/alluvial-chart.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Component,
AfterViewInit
} from "@angular/core";

import { BaseChart } from "./base-chart.component";

import { AlluvialChart } from "@carbon/charts";

/**
* Wrapper around `Alluvial` in carbon charts library
*
* Most functions just call their equivalent from the chart library.
*/
@Component({
selector: "ibm-alluvial-chart",
template: ``
})
export class AlluvialChartComponent extends BaseChart implements AfterViewInit {
/**
* Runs after view init to create a chart, attach it to `elementRef` and draw it.
*/
ngAfterViewInit() {
this.chart = new AlluvialChart(
this.elementRef.nativeElement,
{
data: this.data,
options: this.options
}
);

Object.assign(this, this.chart);
}
}
3 changes: 3 additions & 0 deletions packages/angular/src/charts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { BaseChart } from './base-chart.component';
import { AlluvialChartComponent } from './alluvial-chart.component';
import { AreaChartComponent } from './area-chart.component';
import { StackedAreaChartComponent } from './area-chart-stacked.component';
import { SimpleBarChartComponent } from './bar-chart-simple.component';
Expand Down Expand Up @@ -29,6 +30,7 @@ import { WordCloudChartComponent } from './wordcloud-chart.component';
imports: [CommonModule],
declarations: [
BaseChart,
AlluvialChartComponent,
AreaChartComponent,
StackedAreaChartComponent,
SimpleBarChartComponent,
Expand All @@ -54,6 +56,7 @@ import { WordCloudChartComponent } from './wordcloud-chart.component';
],
exports: [
BaseChart,
AlluvialChartComponent,
AreaChartComponent,
StackedAreaChartComponent,
SimpleBarChartComponent,
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export * from './tree-chart.component';
export * from './treemap-chart.component';
export * from './circle-pack-chart.component';
export * from './wordcloud-chart.component';
export * from './alluvial-chart.component';

// Diagrams
export * from './diagrams/card-node/card-node.module';
Expand Down
5 changes: 5 additions & 0 deletions packages/core/demo/data/CHART_TYPES.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
AlluvialChart: {
vanilla: 'AlluvialChart',
angular: 'ibm-alluvial-chart',
vue: 'ccv-alluvial-chart',
},
AreaChart: {
vanilla: 'AreaChart',
angular: 'ibm-area-chart',
Expand Down
134 changes: 134 additions & 0 deletions packages/core/demo/data/alluvial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export const alluvialSimpleData = [
{ source: 'A', target: 'X', value: 3 },
{ source: 'A', target: 'Y', value: 5 },
{ source: 'A', target: 'Z', value: 8 },
{ source: 'B', target: 'X', value: 6 },
{ source: 'B', target: 'Y', value: 1 },
{ source: 'B', target: 'Z', value: 7 },
{ source: 'C', target: 'X', value: 5 },
{ source: 'C', target: 'Y', value: 5 },
{ source: 'C', target: 'Z', value: 1 },
];

export const alluvialSimpleOptions = {
title: 'Alluvial',
alluvial: {
units: 'GB',
nodes: [
{ name: 'A', category: 'Start' },
{ name: 'B', category: 'Start' },
{ name: 'C', category: 'Start' },
{ name: 'X', category: 'Finish' },
{ name: 'Y', category: 'Finish' },
{ name: 'Z', category: 'Finish' },
],
},
};

export const alluvialMultipleCategoryOptions = {
title: 'Alluvial (multiple categories)',
alluvial: {
nodes: [
{ name: '1st', category: 'Class' },
{ name: '2nd', category: 'Class' },
{ name: 'Crew', category: 'Class' },
{ name: 'Male', category: 'Sex' },
{ name: 'Female', category: 'Sex' },
{ name: 'Child', category: 'Age' },
{ name: 'Adult', category: 'Age' },
{ name: 'Yes', category: 'Survived' },
{ name: 'No', category: 'Survived' },
],
},
};

export const alluvialMultipleCategoryData = [
{
source: '1st',
target: 'Female',
value: 25,
},
{
source: '1st',
target: 'Male',
value: 35,
},
{
source: '2nd',
target: 'Female',
value: 35,
},
{
source: '2nd',
target: 'Male',
value: 50,
},
{
source: 'Crew',
target: 'Male',
value: 43,
},
{
source: 'Crew',
target: 'Female',
value: 18,
},
{
source: 'Male',
target: 'Child',
value: 38,
},
{
source: 'Male',
target: 'Adult',
value: 90,
},
{
source: 'Female',
target: 'Adult',
value: 52,
},
{
source: 'Female',
target: 'Child',
value: 26,
},
{
source: 'Child',
target: 'Yes',
value: 58,
},
{
source: 'Child',
target: 'No',
value: 6,
},
{
source: 'Adult',
target: 'Yes',
value: 22,
},
{
source: 'Adult',
target: 'No',
value: 120,
},
];

export const alluvialMonochromeData = alluvialSimpleData;

export const alluvialMonochromeOptions = {
title: 'Alluvial (monochrome with custom node padding)',
alluvial: {
nodes: [
{ name: 'A', category: 'Start' },
{ name: 'B', category: 'Start' },
{ name: 'C', category: 'Start' },
{ name: 'X', category: 'Finish' },
{ name: 'Y', category: 'Finish' },
{ name: 'Z', category: 'Finish' },
],
monochrome: true,
nodePadding: 33,
},
};
59 changes: 41 additions & 18 deletions packages/core/demo/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as toolbarDemos from './toolbar';
import * as wordCloudDemos from './wordcloud';
import * as zoomBarDemos from './zoom-bar';
import * as highScaleDemos from './high-scale';
import * as alluvialDemos from './alluvial';

export * from './area';
export * from './bar';
Expand All @@ -46,6 +47,7 @@ export * from './toolbar';
export * from './wordcloud';
export * from './zoom-bar';
export * from './high-scale';
export * from './alluvial';

import {
createChartSandbox,
Expand Down Expand Up @@ -1060,31 +1062,23 @@ const simpleChartDemos = [

const complexChartDemos = [
{
title: 'Tree',
configs: {
excludeColorPaletteControl: true,
},
title: 'Alluvial',
demos: [
{
data: treeDemos.treeData,
options: treeDemos.dendogramOptions,
chartType: chartTypes.TreeChart,
options: alluvialDemos.alluvialSimpleOptions,
data: alluvialDemos.alluvialSimpleData,
chartType: chartTypes.AlluvialChart,
mainDemo: true,
},
{
data: treeDemos.treeData,
options: treeDemos.treeOptions,
chartType: chartTypes.TreeChart,
options: alluvialDemos.alluvialMultipleCategoryOptions,
data: alluvialDemos.alluvialMultipleCategoryData,
chartType: chartTypes.AlluvialChart,
},
],
},
{
title: 'Treemap',
demos: [
{
data: treemapDemos.treemapData,
options: treemapDemos.treemapOptions,
chartType: chartTypes.TreemapChart,
options: alluvialDemos.alluvialMonochromeOptions,
data: alluvialDemos.alluvialMonochromeData,
chartType: chartTypes.AlluvialChart,
},
],
},
Expand Down Expand Up @@ -1119,6 +1113,35 @@ const complexChartDemos = [
},
],
},
{
title: 'Tree',
configs: {
excludeColorPaletteControl: true,
},
demos: [
{
data: treeDemos.treeData,
options: treeDemos.dendogramOptions,
chartType: chartTypes.TreeChart,
mainDemo: true,
},
{
data: treeDemos.treeData,
options: treeDemos.treeOptions,
chartType: chartTypes.TreeChart,
},
],
},
{
title: 'Treemap',
demos: [
{
data: treemapDemos.treemapData,
options: treemapDemos.treemapOptions,
chartType: chartTypes.TreemapChart,
},
],
},
].map((demoGroup: any) => {
demoGroup.type = DemoGroupTypes.COMPLEX_CHART;

Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@carbon/utils-position": "1.1.1",
"carbon-components": "10.40.0",
"d3-cloud": "1.2.5",
"d3-sankey": "0.12.3",
"date-fns": "2.8.1",
"dom-to-image": "2.6.0",
"lodash-es": "4.17.21",
Expand Down
50 changes: 50 additions & 0 deletions packages/core/src/charts/alluvial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Internal Imports
import { Chart } from '../chart';
import * as Configuration from '../configuration';
import { ChartConfig, AlluvialChartOptions } from '../interfaces/index';
import { Tools } from '../tools';

// Components
import {
Alluvial,
// the imports below are needed because of typescript bug (error TS4029)
Tooltip,
Legend,
LayoutComponent,
} from '../components/index';

export class AlluvialChart extends Chart {
constructor(
holder: Element,
chartConfigs: ChartConfig<AlluvialChartOptions>
) {
super(holder, chartConfigs);

// Merge the default options for this chart
// With the user provided options
this.model.setOptions(
Tools.mergeDefaultChartOptions(
Configuration.options.alluvialChart,
chartConfigs.options
)
);

// Initialize data, services, components etc.
this.init(holder, chartConfigs);
}

getComponents() {
// Specify what to render inside the graph-frame
const graphFrameComponents: any = [
new Alluvial(this.model, this.services),
];

const components: any[] = this.getChartComponents(
graphFrameComponents,
{
excludeLegend: true,
}
);
return components;
}
}
1 change: 1 addition & 0 deletions packages/core/src/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './tree';
export * from './treemap';
export * from './circle-pack';
export * from './wordcloud';
export * from './alluvial';