forked from Glavin001/ember-c3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drilldown.js
159 lines (136 loc) · 3.08 KB
/
drilldown.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { computed } from '@ember/object';
import { map } from '@ember/object/computed';
import { bind } from "@ember/runloop";
import { action } from "@ember/object";
import Controller from "@ember/controller";
export default class DrilldownController extends Controller {
baseData = [
["Blue Flowers", 30],
["Red Flowers", 120],
["Yellow Flowers", 300]
];
blueFlowers = [
["Wolfsbane", 5],
["Cornflower", 17],
["Hydrangea", 24],
["Triteleia", 51],
["Vanda", 3]
];
redFlowers = [
["Chrysanthemum", 15],
["Poppy", 2],
["Peony", 34],
["Azalea", 37],
["Gloxinia", 5]
];
yellowFlowers = [
["Marigold", 25],
["Yarrow", 10],
["Begonia", 21],
["Daisy", 39],
["Snapdragon", 5]
];
whiteData = [["White Flowers", 60]];
// chart title
title = { text: "Flowers by Color" };
padding = { top: 20 };
init() {
super.init(...arguments);
}
@map("whiteData", function(item) {
return item[0];
})
unloadWhite;
@map("blueFlowers", function(item) {
return item[0];
})
unloadBlue;
@map("redFlowers", function(item) {
return item[0];
})
unloadRed;
@map("yellowFlowers", function(item) {
return item[0];
})
unloadYellow;
// iris data from R
@computed
get data() {
return {
columns: [
["Blue Flowers", 30],
["Red Flowers", 120],
["Yellow Flowers", 300]
],
type: "pie",
onclick: bind(this, this.myClick)
};
}
myClick(d) {
switch (d.name) {
case "Blue Flowers":
this.drilldownBlue();
break;
case "Red Flowers":
this.drilldownRed();
break;
case "Yellow Flowers":
this.drilldownYellow();
break;
}
}
@action
addWhite() {
this.set("dtitle", { text: "Four Colors", refresh: false });
this.chart.load({ columns: this.whiteData });
}
@action
titleOnly() {
this.set("dtitle", { text: "Flowers are Colorful!!!", refresh: false });
}
@action
resetData() {
let c = this.chart;
this.set("dtitle", { text: "Flowers by Color", refresh: false });
c.load({ columns: this.baseData });
c.unload(
this.unloadBlue
.concat(this.unloadRed)
.concat(this.unloadYellow)
.concat(this.unloadWhite)
);
}
drilldownBlue() {
let c = this.chart;
this.set("dtitle", { text: "Four Colors", refresh: false });
c.load({ columns: this.blueFlowers });
c.unload([
"Blue Flowers",
"Red Flowers",
"Yellow Flowers",
"White Flowers"
]);
}
drilldownRed() {
let c = this.chart;
this.set("dtitle", { text: "Red Flowers", refresh: false });
c.load({ columns: this.redFlowers });
c.unload([
"Blue Flowers",
"Red Flowers",
"Yellow Flowers",
"White Flowers"
]);
}
drilldownYellow() {
let c = this.chart;
this.set("dtitle", { text: "Yellow Flowers", refrehs: false });
c.load({ columns: this.yellowFlowers });
c.unload([
"Blue Flowers",
"Red Flowers",
"Yellow Flowers",
"White Flowers"
]);
}
}