-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds an alternative display mode for treemap. In the original mode, leaf nodes are displayed inside the rectangle of their parent, that is itself inside the rectangle of its parent, and so on. With the new mode "headerBoxes" the parent rectangles do not contain their children, but are displayed as headers above them. The new mode is activated by setting the displayMode option to "headerBoxes" in the dataset.
- Loading branch information
1 parent
058f36e
commit 5be45aa
Showing
11 changed files
with
237 additions
and
15 deletions.
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
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,35 @@ | ||
const arrayN = (n) => Array.from({length: n}).map((_, i) => i); | ||
|
||
const groups = arrayN(10); | ||
const tree = groups.reduce((acc, grp) => [ | ||
...acc, | ||
...arrayN(grp * 10).map(i => ({grp: `group: ${grp}`, sub: `sub: ${i}`, value: (i % 10) * 10})) | ||
], []); | ||
|
||
export default { | ||
config: { | ||
type: 'treemap', | ||
data: { | ||
datasets: [{ | ||
tree, | ||
backgroundColor: (ctx) => ctx.raw.l ? 'dimgray' : 'silver', | ||
borderColor: (ctx) => ctx.raw.l ? 'white' : 'black', | ||
borderWidth: 0, | ||
spacing: 1, | ||
key: 'value', | ||
groups: ['grp', 'sub'], | ||
displayMode: 'headerBoxes', | ||
}] | ||
}, | ||
options: { | ||
events: [] | ||
} | ||
}, | ||
options: { | ||
spriteText: true, | ||
canvas: { | ||
height: 300, | ||
width: 800 | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const arrayN = (n) => Array.from({length: n}).map((_, i) => i); | ||
|
||
const groups = arrayN(4); | ||
const tree = groups.reduce((acc, grp) => [ | ||
...acc, | ||
...arrayN(grp * 4).map(i => ({grp: `group: ${grp}`, sub: `sub: ${i}`, value: (i % 4) * 4})) | ||
], []); | ||
|
||
export default { | ||
config: { | ||
type: 'treemap', | ||
data: { | ||
datasets: [{ | ||
tree, | ||
backgroundColor: (ctx) => ctx.raw.l ? 'lightblue' : 'dimgray', | ||
borderColor: 'dimgray', | ||
borderWidth: 1, | ||
spacing: 1, | ||
key: 'value', | ||
groups: ['grp', 'sub'], | ||
displayMode: 'headerBoxes' | ||
}] | ||
}, | ||
options: { | ||
events: [] | ||
} | ||
}, | ||
options: { | ||
spriteText: true, | ||
canvas: { | ||
height: 300, | ||
width: 800 | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const arrayN = (n) => Array.from({length: n}).map((_, i) => i); | ||
|
||
const groups = arrayN(10); | ||
const tree = groups.reduce((acc, grp) => [ | ||
...acc, | ||
...arrayN(grp * 10).map(i => ({grp: `group: ${grp}`, sub: `sub: ${i}`, value: (i % 10) * 10})) | ||
], []); | ||
|
||
export default { | ||
config: { | ||
type: 'treemap', | ||
data: { | ||
datasets: [{ | ||
tree, | ||
backgroundColor: (ctx) => ctx.raw.l ? 'dimgray' : 'silver', | ||
borderColor: (ctx) => ctx.raw.l ? 'white' : 'black', | ||
borderWidth: 0, | ||
spacing: 1, | ||
key: 'value', | ||
groups: ['grp', 'sub'], | ||
displayMode: 'headerBoxes', | ||
captions: { | ||
padding: 20, | ||
} | ||
}] | ||
}, | ||
options: { | ||
events: [] | ||
} | ||
}, | ||
options: { | ||
spriteText: true, | ||
canvas: { | ||
height: 200, | ||
width: 800 | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const arrayN = (n) => Array.from({length: n}).map((_, i) => i); | ||
|
||
const groups = arrayN(5); | ||
const tree = groups.reduce((acc, grp) => [ | ||
...acc, | ||
...arrayN(grp * 5).map(i => ({grp: `group: ${grp}`, sub: `sub: ${i}`, value: (i % 5) * 5})) | ||
], []); | ||
|
||
const colors = ['red', 'green', 'blue', 'yellow', 'purple']; | ||
|
||
export default { | ||
config: { | ||
type: 'treemap', | ||
data: { | ||
datasets: [{ | ||
tree, | ||
backgroundColor: (ctx) => { | ||
if (ctx.raw.l === 0) { | ||
return 'dimgray'; | ||
} | ||
const parentGrp = ctx.raw._data.grp; | ||
return colors[parentGrp[parentGrp.length - 1]]; | ||
}, | ||
borderWidth: 0, | ||
spacing: 1, | ||
key: 'value', | ||
groups: ['grp', 'sub'], | ||
displayMode: 'headerBoxes', | ||
captions: { | ||
display: false, | ||
} | ||
}] | ||
}, | ||
options: { | ||
events: [] | ||
} | ||
}, | ||
options: { | ||
spriteText: true, | ||
canvas: { | ||
height: 300, | ||
width: 800 | ||
} | ||
} | ||
}; |
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