Skip to content

Commit 11cc578

Browse files
add depth parameter and fuller featured example to vue d3 treemap example
1 parent 0fe9967 commit 11cc578

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

inst/examples/vue_d3_treemap.R

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <- tag(
2222
"rect",
2323
list(
2424
"v-for" = "(node, index) in nodes",
25-
"v-if" = "node.depth === 2",
25+
"v-if" = "node.depth === depth",
2626
"v-bind:x" = "node.x0",
2727
"v-bind:width" = "node.x1 - node.x0",
2828
"v-bind:y" = "node.y0",
@@ -60,6 +60,10 @@ Vue.component('treemap-component', {
6060
type: Function,
6161
default: d3.treemapSquarify
6262
},
63+
depth: {
64+
type: Number,
65+
default: 2
66+
},
6367
color: {
6468
type: Function,
6569
default: d3.scaleOrdinal(d3.schemeCategory10)
@@ -93,7 +97,7 @@ Vue.component('treemap-component', {
9397
.padding(1)(d3t)
9498
},
9599
onNodeClick: function(node) {
96-
this.$emit('NODE_CLICK', node)
100+
this.$emit('node_click', node, this)
97101
}
98102
}
99103
});
@@ -111,11 +115,13 @@ var app = new Vue({
111115
size: 'x',
112116
width: 800,
113117
height: 600,
114-
tile: d3.treemapSliceDice
118+
tile: d3.treemapSliceDice,
119+
depth: 1,
120+
color: d3.scaleOrdinal(d3.schemeCategory20c)
115121
},
116122
methods: {
117-
node_clicked: function(node) {
118-
console.log(node);
123+
node_clicked: function(node, component) {
124+
console.log(node, component);
119125
}
120126
}
121127
})
@@ -124,6 +130,7 @@ rhd_json
124130
)
125131
))
126132

133+
# one treemap example
127134
browsable(
128135
tagList(
129136
template,
@@ -132,7 +139,7 @@ browsable(
132139
id="app",
133140
tag(
134141
"treemap-component",
135-
list(":tree" = "tree",":sizefield"="'x'","v-on:NODE_CLICK"="node_clicked") #use defaults
142+
list(":tree" = "tree",":sizefield"="'x'","v-on:node_click"="node_clicked") #use defaults
136143
)
137144
),
138145
app,
@@ -158,13 +165,23 @@ browsable(
158165
),
159166
tag(
160167
"treemap-component",
161-
list(":tree" = "tree",":sizefield"="size",":treeheight"="height",":treewidth"="width")
168+
list(
169+
":tree" = "tree",":sizefield"="size",
170+
":treeheight"="height",":treewidth"="width",
171+
":depth"="depth", ":color"="color"
172+
)
162173
),
163174
tag(
164175
"treemap-component",
165-
list(":tree" = "tree",":sizefield"="size",":tile"="tile","v-on:NODE_CLICK"="node_clicked")
176+
list(":tree" = "tree",":sizefield"="size",":tile"="tile","v-on:node_click"="node_clicked")
166177
)
167178
),
179+
tags$script("
180+
setInterval(
181+
function(){app.$data.depth = app.$data.depth === 3 ? 1 : app.$data.depth + 1},
182+
2000
183+
)
184+
"),
168185
app,
169186
html_dependency_vue(offline=FALSE,minified=FALSE),
170187
d3_dep_v4(offline=FALSE)

0 commit comments

Comments
 (0)