-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
131 lines (105 loc) · 3.8 KB
/
index.js
File metadata and controls
131 lines (105 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import Visualization from 'zeppelin-vis'
import AdvancedTransformation from 'zeppelin-tabledata/advanced-transformation'
import Highcharts from 'highcharts/highcharts'
require('highcharts/modules/heatmap')(Highcharts);
require('highcharts/modules/data')(Highcharts)
require('highcharts/modules/exporting')(Highcharts)
import { HeatmapParameter, createHeatmapChartDataStructure, createHeatmapChartOption, } from './chart/heatmap'
export default class Chart extends Visualization {
constructor(targetEl, config) {
super(targetEl, config)
const spec = {
charts: {
'heatmap': {
transform: { method: 'array:2-key', },
sharedAxis: false,
axis: {
'xAxis': { dimension: 'multiple', axisType: 'key', minAxisCount: 1, description: 'categorical', },
'yAxis': { dimension: 'multiple', axisType: 'key', minAxisCount: 1, description: 'categorical', },
'zAxis': { dimension: 'single', axisType: 'aggregator', minAxisCount: 1, description: 'numeric', },
},
parameter: HeatmapParameter,
},
},
}
this.transformation = new AdvancedTransformation(config, spec)
}
getChartElementId() {
return this.targetEl[0].id
}
refresh() {
try {
this.chartInstance && this.chartInstance.setSize(this.targetEl.width())
} catch (e) {
console.warn(e)
}
}
getChartElement() {
return document.getElementById(this.getChartElementId())
}
clearChart() {
if (this.chartInstance) { this.chartInstance.destroy() }
}
hideChart() {
this.clearChart()
this.getChartElement().innerHTML = `
<div style="margin-top: 60px; text-align: center; font-weight: 100">
<span style="font-size:30px;">
Please set axes in
</span>
<span style="font-size: 30px; font-style:italic;">
Settings
</span>
</div>`
}
showError(error) {
this.clearChart()
this.getChartElement().innerHTML = `
<div style="margin-top: 60px; text-align: center; font-weight: 300">
<span style="font-size:30px; color: #e4573c;">
${error.message}
</span>
</div>`
}
drawHeatmapChart(parameter, column, transformer) {
if (column.aggregator.length === 0 || column.key.length === 0) {
this.hideChart()
return /** have nothing to display, if aggregator is not specified at all */
}
const { rows, selectors, key1Names, key2Names,
key1NameWithIndex, key2NameWithIndex } = transformer()
const data = createHeatmapChartDataStructure(rows, key1NameWithIndex, key2NameWithIndex,
selectors, parameter)
const chartOption = createHeatmapChartOption(Highcharts, data, parameter, key1Names, key2Names)
this.chartInstance = Highcharts.chart(this.getChartElementId(), chartOption)
}
drawTreeChart(parameter, column, transformer) {
if (column.aggregator.length === 0) {
this.hideChart()
return /** have nothing to display, if aggregator is not specified at all */
}
const { rows, selectors, key1Names, key2Names,
key1NameWithIndex, key2NameWithIndex } = transformer()
const data = createTreeChartDataStructure(rows, selectors)
const chartOption = createTreeChartOption(Highcharts, data, parameter)
this.chartInstance = Highcharts.chart(this.getChartElementId(), chartOption)
}
render(data) {
const {
chartChanged, parameterChanged,
chart, parameter, column, transformer,
} = data
if (!chartChanged && !parameterChanged) { return }
try {
if (chart === 'heatmap') {
this.drawHeatmapChart(parameter, column, transformer)
}
} catch (error) {
console.error(error)
this.showError(error)
}
}
getTransformation() {
return this.transformation
}
}