-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable tree data as an object using the hierarchy of its properties (#98
) * Enable tree data as an object using its hierarchy * reduces complexity to group function * removes hardcoded group key using index number as string * fixes parent group converting as string * adds test case with tree object with groups with number array * adds treeLeafKey option * fixes path calculation * changes check if the tree is an object * tests pull_request_target event on CI * reverts pull_request_target from CI * adds sample * adds sample - 2
- Loading branch information
1 parent
3aefb91
commit b91f42a
Showing
17 changed files
with
501 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ module.exports = { | |
'basic', | ||
'labels', | ||
'groups', | ||
'tree', | ||
'captions', | ||
'dividers', | ||
'rtl' | ||
|
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,77 @@ | ||
# Tree | ||
|
||
```js chart-editor | ||
// <block:options:1> | ||
const options = { | ||
plugins: { | ||
title: { | ||
display: true | ||
}, | ||
legend: { | ||
display: false | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
title(items) { | ||
const dataItem = items[0].raw; | ||
const obj = dataItem._data; | ||
return obj.name; | ||
}, | ||
} | ||
} | ||
} | ||
}; | ||
// </block:options> | ||
|
||
// <block:config:0> | ||
const config = { | ||
type: 'treemap', | ||
data: { | ||
datasets: [{ | ||
tree: Data.objectsTree, | ||
treeLeafKey: 'name', | ||
key: 'value', | ||
groups: [], | ||
spacing: 1, | ||
borderWidth: 0.5, | ||
borderColor: '#FF8F00', | ||
backgroundColor: 'rgba(255,167,38,0.3)', | ||
hoverBackgroundColor: 'rgba(238,238,238,0.5)', | ||
captions: { | ||
align: 'center' | ||
}, | ||
labels: { | ||
display: true, | ||
formatter: (ctx) => { | ||
return ctx.raw.v; | ||
} | ||
} | ||
}] | ||
}, | ||
options | ||
}; | ||
// </block:config> | ||
|
||
function toggle(chart) { | ||
const dataset = chart.data.datasets[0]; | ||
if (dataset.groups.length) { | ||
dataset.groups = []; | ||
} else { | ||
dataset.groups = [0, 1]; | ||
dataset.groups.push('name'); | ||
} | ||
chart.update(); | ||
} | ||
|
||
const actions = [ | ||
{ | ||
name: 'Toggle GroupBy', | ||
handler: (chart) => toggle(chart) | ||
} | ||
]; | ||
|
||
module.exports = { | ||
actions, | ||
config, | ||
}; | ||
``` |
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
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
Oops, something went wrong.