@@ -2,14 +2,22 @@ import * as d3 from 'd3'
2
2
import { formatType , handleErrors } from '../common/utils'
3
3
4
4
import {
5
- Row ,
5
+ Link ,
6
6
Looker ,
7
- VisualizationDefinition ,
8
- VisConfig
7
+ LookerChartUtils ,
8
+ Row ,
9
+ VisConfig ,
10
+ VisualizationDefinition
9
11
} from '../types/types'
10
12
11
13
// Global values provided via the API
12
14
declare var looker : Looker
15
+ declare var LookerCharts : LookerChartUtils
16
+
17
+ const colorBy = {
18
+ NODE : 'node' ,
19
+ ROOT : 'root'
20
+ }
13
21
14
22
interface SunburstVisualization extends VisualizationDefinition {
15
23
svg ?: any ,
@@ -29,6 +37,7 @@ function descend(obj: any, depth: number = 0) {
29
37
}
30
38
if ( '__data' in obj [ k ] ) {
31
39
child . data = obj [ k ] . __data
40
+ child . links = obj [ k ] . __data . taxonomy . links
32
41
}
33
42
arr . push ( child )
34
43
}
@@ -62,6 +71,17 @@ function burrow(table: Row[], config: VisConfig) {
62
71
}
63
72
}
64
73
74
+ const getLinksFromRow = ( row : Row ) : Link [ ] => {
75
+ return Object . keys ( row ) . reduce ( ( links : Link [ ] , datum ) => {
76
+ if ( row [ datum ] . links ) {
77
+ const datumLinks = row [ datum ] . links as Link [ ]
78
+ return links . concat ( datumLinks )
79
+ } else {
80
+ return links
81
+ }
82
+ } , [ ] )
83
+ }
84
+
65
85
const vis : SunburstVisualization = {
66
86
id : 'sunburst' , // id/label not required, but nice for testing and keeping manifests in sync
67
87
label : 'Sunburst' ,
@@ -77,10 +97,10 @@ const vis: SunburstVisualization = {
77
97
label : 'Color By' ,
78
98
display : 'select' ,
79
99
values : [
80
- { " Color By Root" : "byroot" } ,
81
- { " Color By Node" : "bynode" }
100
+ { ' Color By Root' : colorBy . ROOT } ,
101
+ { ' Color By Node' : colorBy . NODE }
82
102
] ,
83
- default : "byroot"
103
+ default : colorBy . ROOT
84
104
} ,
85
105
show_null_points : {
86
106
type : 'boolean' ,
@@ -89,7 +109,7 @@ const vis: SunburstVisualization = {
89
109
}
90
110
} ,
91
111
// Set up the initial state of the visualization
92
- create ( element , config ) {
112
+ create ( element , _config ) {
93
113
element . style . fontFamily = `"Open Sans", "Helvetica", sans-serif`
94
114
this . svg = d3 . select ( element ) . append ( 'svg' )
95
115
} ,
@@ -110,10 +130,11 @@ const vis: SunburstVisualization = {
110
130
const format = formatType ( measure . value_format ) || ( ( s : any ) : string => s . toString ( ) )
111
131
112
132
const colorScale : d3 . ScaleOrdinal < string , null > = d3 . scaleOrdinal ( )
113
- const color = colorScale . range ( config . color_range )
133
+ const color = colorScale . range ( config . color_range || [ ] )
114
134
115
135
data . forEach ( row => {
116
136
row . taxonomy = {
137
+ links : getLinksFromRow ( row ) ,
117
138
value : dimensions . map ( ( dimension ) => row [ dimension . name ] . value )
118
139
}
119
140
} )
@@ -152,19 +173,22 @@ const vis: SunburstVisualization = {
152
173
. attr ( 'd' , arc )
153
174
. style ( 'fill' , ( d : any ) => {
154
175
if ( d . depth === 0 ) return 'none'
155
- if ( config . color_by === 'bynode' ) {
176
+ if ( config . color_by === colorBy . NODE ) {
156
177
return color ( d . data . name )
157
178
} else {
158
179
return color ( d . ancestors ( ) . map ( ( p : any ) => p . data . name ) . slice ( - 2 , - 1 ) )
159
180
}
160
-
161
181
} )
162
182
. style ( 'fill-opacity' , ( d : any ) => 1 - d . depth * 0.15 )
163
183
. style ( 'transition' , ( d : any ) => 'fill-opacity 0.5s' )
164
184
. style ( 'stroke' , ( d : any ) => '#fff' )
165
185
. style ( 'stroke-width' , ( d : any ) => '0.5px' )
166
- . on ( 'click' , ( d : any ) => {
167
- console . log ( d )
186
+ . on ( 'click' , function ( this : any , d : any ) {
187
+ const event : object = { pageX : d3 . event . pageX , pageY : d3 . event . pageY }
188
+ LookerCharts . Utils . openDrillMenu ( {
189
+ links : d . data . links ,
190
+ event : event
191
+ } )
168
192
} )
169
193
. on ( 'mouseenter' , ( d : any ) => {
170
194
const ancestorText = (
0 commit comments