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): Pass treemap tile data to getFillColor #1342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions packages/core/CHANGELOG.md
Expand Up @@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [Unreleased]

### Added

* **core:** pass treemap data to `getFillColor`





# [0.56.0](https://github.com/carbon-design-system/carbon-charts/compare/v0.55.1...v0.56.0) (2022-03-28)


Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/components/graphs/treemap.ts
Expand Up @@ -167,8 +167,7 @@ export class Treemap extends Component {
.attr('width', (d) => d.x1 - d.x0)
.attr('height', (d) => d.y1 - d.y0)
.style('fill', (d) => {
while (d.depth > 1) d = d.parent;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the treemap does not support nested data structures, so this while loop seems safe to delete.

return this.model.getFillColor(d.data.name);
return this.model.getFillColor(d.parent.data.name, undefined, d);
});

// Update all clip paths
Expand Down Expand Up @@ -220,7 +219,7 @@ export class Treemap extends Component {
let parent = d;
while (parent.depth > 1) parent = parent.parent;
const color = hsl(
this.model.getFillColor(parent.data.name)
this.model.getFillColor(parent.data.name, undefined, d)
);
return [
{
Expand Down Expand Up @@ -285,7 +284,9 @@ export class Treemap extends Component {
)
.style('fill', (d: any) => {
const customColor = self.model.getFillColor(
d.parent.data.name
d.parent.data.name,
undefined,
d
);
if (customColor) {
fillColor = customColor;
Expand Down Expand Up @@ -361,7 +362,11 @@ export class Treemap extends Component {
})
)
.style('fill', (d: any) =>
self.model.getFillColor(d.parent.data.name)
self.model.getFillColor(
d.parent.data.name,
undefined,
d
)
);

// Dispatch mouse event
Expand Down