@@ -22,7 +22,7 @@ template <- tag(
22
22
" rect" ,
23
23
list (
24
24
" v-for" = " (node, index) in nodes" ,
25
- " v-if" = " node.depth === 2 " ,
25
+ " v-if" = " node.depth === depth " ,
26
26
" v-bind:x" = " node.x0" ,
27
27
" v-bind:width" = " node.x1 - node.x0" ,
28
28
" v-bind:y" = " node.y0" ,
@@ -60,6 +60,10 @@ Vue.component('treemap-component', {
60
60
type: Function,
61
61
default: d3.treemapSquarify
62
62
},
63
+ depth: {
64
+ type: Number,
65
+ default: 2
66
+ },
63
67
color: {
64
68
type: Function,
65
69
default: d3.scaleOrdinal(d3.schemeCategory10)
@@ -93,7 +97,7 @@ Vue.component('treemap-component', {
93
97
.padding(1)(d3t)
94
98
},
95
99
onNodeClick: function(node) {
96
- this.$emit('NODE_CLICK ', node)
100
+ this.$emit('node_click ', node, this )
97
101
}
98
102
}
99
103
});
@@ -111,11 +115,13 @@ var app = new Vue({
111
115
size: 'x',
112
116
width: 800,
113
117
height: 600,
114
- tile: d3.treemapSliceDice
118
+ tile: d3.treemapSliceDice,
119
+ depth: 1,
120
+ color: d3.scaleOrdinal(d3.schemeCategory20c)
115
121
},
116
122
methods: {
117
- node_clicked: function(node) {
118
- console.log(node);
123
+ node_clicked: function(node, component ) {
124
+ console.log(node, component );
119
125
}
120
126
}
121
127
})
@@ -124,6 +130,7 @@ rhd_json
124
130
)
125
131
))
126
132
133
+ # one treemap example
127
134
browsable(
128
135
tagList(
129
136
template ,
@@ -132,7 +139,7 @@ browsable(
132
139
id = " app" ,
133
140
tag(
134
141
" 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
136
143
)
137
144
),
138
145
app ,
@@ -158,13 +165,23 @@ browsable(
158
165
),
159
166
tag(
160
167
" 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
+ )
162
173
),
163
174
tag(
164
175
" 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" )
166
177
)
167
178
),
179
+ tags $ script("
180
+ setInterval(
181
+ function(){app.$data.depth = app.$data.depth === 3 ? 1 : app.$data.depth + 1},
182
+ 2000
183
+ )
184
+ " ),
168
185
app ,
169
186
html_dependency_vue(offline = FALSE ,minified = FALSE ),
170
187
d3_dep_v4(offline = FALSE )
0 commit comments