Skip to content
This repository was archived by the owner on Apr 21, 2022. It is now read-only.

Commit e21b21d

Browse files
clean up node/row work, add drills, fix console error on load, fix unused param
1 parent 464f45f commit e21b21d

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

dist/sunburst.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/examples/sunburst/sunburst.ts

+36-12
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import * as d3 from 'd3'
22
import { formatType, handleErrors } from '../common/utils'
33

44
import {
5-
Row,
5+
Link,
66
Looker,
7-
VisualizationDefinition,
8-
VisConfig
7+
LookerChartUtils,
8+
Row,
9+
VisConfig,
10+
VisualizationDefinition
911
} from '../types/types'
1012

1113
// Global values provided via the API
1214
declare var looker: Looker
15+
declare var LookerCharts: LookerChartUtils
16+
17+
const colorBy = {
18+
NODE: 'node',
19+
ROOT: 'root'
20+
}
1321

1422
interface SunburstVisualization extends VisualizationDefinition {
1523
svg?: any,
@@ -29,6 +37,7 @@ function descend(obj: any, depth: number = 0) {
2937
}
3038
if ('__data' in obj[k]) {
3139
child.data = obj[k].__data
40+
child.links = obj[k].__data.taxonomy.links
3241
}
3342
arr.push(child)
3443
}
@@ -62,6 +71,17 @@ function burrow(table: Row[], config: VisConfig) {
6271
}
6372
}
6473

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+
6585
const vis: SunburstVisualization = {
6686
id: 'sunburst', // id/label not required, but nice for testing and keeping manifests in sync
6787
label: 'Sunburst',
@@ -77,10 +97,10 @@ const vis: SunburstVisualization = {
7797
label: 'Color By',
7898
display: 'select',
7999
values: [
80-
{"Color By Root": "byroot"},
81-
{"Color By Node": "bynode"}
100+
{ 'Color By Root': colorBy.ROOT },
101+
{ 'Color By Node': colorBy.NODE }
82102
],
83-
default: "byroot"
103+
default: colorBy.ROOT
84104
},
85105
show_null_points: {
86106
type: 'boolean',
@@ -89,7 +109,7 @@ const vis: SunburstVisualization = {
89109
}
90110
},
91111
// Set up the initial state of the visualization
92-
create(element, config) {
112+
create(element, _config) {
93113
element.style.fontFamily = `"Open Sans", "Helvetica", sans-serif`
94114
this.svg = d3.select(element).append('svg')
95115
},
@@ -110,10 +130,11 @@ const vis: SunburstVisualization = {
110130
const format = formatType(measure.value_format) || ((s: any): string => s.toString())
111131

112132
const colorScale: d3.ScaleOrdinal<string, null> = d3.scaleOrdinal()
113-
const color = colorScale.range(config.color_range)
133+
const color = colorScale.range(config.color_range || [])
114134

115135
data.forEach(row => {
116136
row.taxonomy = {
137+
links: getLinksFromRow(row),
117138
value: dimensions.map((dimension) => row[dimension.name].value)
118139
}
119140
})
@@ -152,19 +173,22 @@ const vis: SunburstVisualization = {
152173
.attr('d', arc)
153174
.style('fill', (d: any) => {
154175
if (d.depth === 0) return 'none'
155-
if (config.color_by === 'bynode') {
176+
if (config.color_by === colorBy.NODE) {
156177
return color(d.data.name)
157178
} else {
158179
return color(d.ancestors().map((p: any) => p.data.name).slice(-2, -1))
159180
}
160-
161181
})
162182
.style('fill-opacity', (d: any) => 1 - d.depth * 0.15)
163183
.style('transition', (d: any) => 'fill-opacity 0.5s')
164184
.style('stroke', (d: any) => '#fff')
165185
.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+
})
168192
})
169193
.on('mouseenter', (d: any) => {
170194
const ancestorText = (

src/examples/types/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface VisOption {
111111
max?: number
112112
step?: number
113113
required?: boolean
114+
supports?: string[]
114115
}
115116

116117
export interface VisualizationError {

0 commit comments

Comments
 (0)