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

Show pre-selected data groups #639

Merged
merged 51 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3c327c5
Add selectedGroups option
May 25, 2020
a013589
Bind selectedGroups with legend and dataGroups
May 25, 2020
0f2b92d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
May 25, 2020
45e73cc
improvement: move selectedGroup under data option
May 26, 2020
88184e5
refactor: update selectedGroup position
May 27, 2020
f7ac630
improvement: grab options from getOptions
May 28, 2020
8b57817
improvement: fix naming and update comments
May 28, 2020
e0b9f2b
Merge branch 'master' into selectedGroups
theiliad May 29, 2020
e71381e
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 2, 2020
1cc3cbe
Merge branch 'selectedGroups' of git://github.com/sophiiae/carbon-cha…
Jun 2, 2020
963ad97
improvement: simplify the code
Jun 4, 2020
01b1be0
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 4, 2020
96b454b
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 5, 2020
00c969e
improvement: remove updateSelectedGroups
Jun 8, 2020
f0857e2
fix: remove updateSelectedGroups from legend
Jun 8, 2020
534cb62
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 9, 2020
6486a72
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 10, 2020
9a5880d
Merge branch 'master' into selectedGroups
theiliad Jun 11, 2020
fd88f3d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 11, 2020
5c1700e
Merge branch 'selectedGroups' of https://github.com/sophiiae/carbon-c…
Jun 11, 2020
b5e050a
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 13, 2020
3f1f8e8
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 22, 2020
88fee02
test: add unit test for setting up selectedGroups
Jun 22, 2020
190fb67
test: modify unit test
Jun 22, 2020
e5cab17
test: renaming
Jun 22, 2020
63c9966
test: revise unit test
Jun 23, 2020
46f378a
test: update test description
Jun 23, 2020
b948159
style: revise the comment for selectedGroup
Jun 23, 2020
35cd830
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 24, 2020
a8a1a4b
test: update test
Jun 24, 2020
6168334
test: simplify the test code
Jun 24, 2020
bd22d0a
style: format the code
Jun 24, 2020
79cf257
test: add more tests
Jun 25, 2020
3b11c8e
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 25, 2020
efdeaa0
test: remove tests for events
Jun 25, 2020
d458da2
test: remove async function
Jun 25, 2020
9315f31
fix: fix check mark position issue and add demos
Jun 25, 2020
d334d6d
fix: fix multiple check marks bug
Jun 26, 2020
05e5c20
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 26, 2020
a2fce6d
fix: fix chart shrinks between legend click for selected groups
Jun 29, 2020
246f179
fix: fix legend height change with first legend click
Jun 29, 2020
4f2233d
fix: fix demo broken
Jun 30, 2020
af678c4
Merge branch 'master' of https://github.com/carbon-design-system/carb…
Jun 30, 2020
e1a911d
refactor: renaming
Jul 2, 2020
c3e86eb
refactor: get legend height
Jul 2, 2020
16056cc
remove semicolon
Jul 2, 2020
2606182
fix: fix data domain
Jul 6, 2020
647926e
Merge branch 'selectedGroups' of https://github.com/sophiiae/carbon-c…
Jul 6, 2020
5c942d3
refactor: rename the demo
Jul 6, 2020
a85684d
fix: fix angular and react height issue
Jul 6, 2020
2578d9f
Merge branch 'master' into selectedGroups
theiliad Jul 7, 2020
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
1 change: 1 addition & 0 deletions packages/core/src/components/essentials/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export class Legend extends Component {
const clickedItemData = clickedItem.datum() as any;

self.model.toggleDataLabel(clickedItemData.name);
self.model.updateSelectedGroups();
sophiiae marked this conversation as resolved.
Show resolved Hide resolved
sophiiae marked this conversation as resolved.
Show resolved Hide resolved
})
.on("mouseout", function () {
const hoveredItem = select(this);
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ const chart: BaseChartOptions = {
data: {
groupMapsTo: "group",
loading: false,
selectedGroups: []
},
color: {
scale: null,
},
scale: null
}
};

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/interfaces/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export interface BaseChartOptions {
* used to simulate data loading
*/
loading?: Boolean;
/**
* options related to pre-selected datasets
*/
selectedGroups?: string[];
};
/**
* options related to color scales
Expand Down
48 changes: 45 additions & 3 deletions packages/core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,39 @@ export class ChartModel {
});
}

/**
* Updates selected datasets
*/
updateSelectedGroups() {
const { ACTIVE, DISABLED } = Configuration.legend.items.status;
const dataGroups = this.getDataGroups();
const activeItems = dataGroups.filter(group => group.status === ACTIVE);

const hasDeactivatedItems = dataGroups.some(
group => group.status === DISABLED
);

// If there are deactivated items, map the label names into selected datasets
if (hasDeactivatedItems) {
this.state.options.data.selectedGroups = activeItems.map(activeItem => activeItem.name);
} else {
// If every item is active, clear array
this.state.options.data.selectedGroups = [];
};
}

checkSelectedGroups(uniqueDataGroups: string[]) {
if (this.state.options.data.selectedGroups.length) {
sophiiae marked this conversation as resolved.
Show resolved Hide resolved
// check if current groups includes every item in selected groups
const hasSelectedGroups = this.state.options.data.selectedGroups
.every(groupName => uniqueDataGroups.includes(groupName));

if (!hasSelectedGroups) {
this.state.options.data.selectedGroups = [];
};
};
}

/**
* Should the data point be filled?
* @param group
Expand Down Expand Up @@ -417,15 +450,24 @@ export class ChartModel {

protected generateDataGroups(data) {
const { groupMapsTo } = this.getOptions().data;
const { ACTIVE } = Configuration.legend.items.status;
const { ACTIVE, DISABLED } = Configuration.legend.items.status;

const uniqueDataGroups = map(
data,
(datum) => datum[groupMapsTo]
).keys();
return uniqueDataGroups.map((groupName) => ({

this.checkSelectedGroups(uniqueDataGroups);
const getStatus = (groupName) => {
return (!this.state.options.data.selectedGroups.length ||
this.state.options.data.selectedGroups.includes(groupName))
? ACTIVE
: DISABLED;
}

return uniqueDataGroups.map(groupName => ({
name: groupName,
status: ACTIVE,
status: getStatus(groupName)
}));
}

Expand Down