-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
145 lines (135 loc) · 4.62 KB
/
Copy pathmain.js
File metadata and controls
145 lines (135 loc) · 4.62 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { piechart } from "./src/mainpie.js";
import { draw_scatt1, draw_scatt4, draw_scatt5 } from "./src/drawscatter.js";
import { draw_scatt2 } from "./src/drawscatter.js";
import { frame_init } from "./src/init.js";
import { dropdown } from "./src/dropdown_buttom.js";
import { draw_histamgram } from "./src/drawHistogram.js";
import { change_picture } from "./src/picture_change.js";
const FWith = 800,
FHeight = 400;
const FLeftTopX = 10,
FLeftTopY = 10;
const MARGIN = { LEFT: 100, RIGHT: 10, TOP: 10, BOTTOM: 100 };
const WIDTH = FWith - (MARGIN.LEFT + MARGIN.RIGHT);
const HEIGHT = FHeight - (MARGIN.TOP + MARGIN.BOTTOM);
//frame genration
const svg1 = d3
.select("#pie")
.append("svg")
.attr("width", FWith)
.attr("height", FHeight);
const g1 = svg1
.append("g")
.attr(
"transform",
`translate(${FLeftTopX + MARGIN.LEFT}, ${FLeftTopY + MARGIN.TOP})`
);
var g2 = frame_init("area1");
var g3 = frame_init("area2");
var g4 = frame_init("area3");
var g5 = frame_init("area4");
var gpic = frame_init("pic");
//main data
d3.csv("./persudu/data_clean.csv", d3.autoType).then(function (data) {
d3.json("./persudu/subcount.json").then(function (count) {
var botton = dropdown(count);
change_picture(gpic, "GOOGLE-PLAY");
var piechar = piechart(count, g1);
var pie = piechar["pie"];
var radius = piechar["radius"];
draw_scatt1(data, g2, undefined, count);
draw_scatt2(data, g3, undefined, count);
draw_scatt4(data, g4, undefined, count);
// draw_scatt5(data, g5);
draw_histamgram(data, count, g5);
pie
.on("mouseover", function (d, i) {
d3.select(this)
.transition()
.duration("50")
.attr("opacity", "0.5")
.attr(
"d",
d3
.arc()
.innerRadius(30)
.outerRadius(radius + 20)
);
})
.on("mouseout", function (d, i) {
d3.select(this)
.transition()
.duration("50")
.attr("opacity", "1")
.attr("d", d3.arc().innerRadius(0).outerRadius(radius));
})
.on("click", (d, i) => {
// the click we use that help the radius update by the click
var click_value = d.data.key;
d3.select(this).transition().duration("50");
var selectList = [];
data.forEach((element) => {
if (element["Category"] == click_value) {
selectList.push(element);
}
});
draw_scatt1(selectList, g2, click_value, count);
draw_scatt2(selectList, g3, click_value, count);
draw_scatt4(selectList, g4, click_value, count);
draw_histamgram(selectList, count, g5, 1, click_value);
gpic.selectAll(".sth").remove();
gpic.selectAll('text').remove();
change_picture(gpic, click_value);
});
botton["bottom"].on("change", function () {
// recover the option that has been chosen
gpic.selectAll(".sth").remove();
gpic.selectAll('text').remove();
var selectedOption = d3.select(this).property("value");
change_picture(gpic, "GOOGLE-PLAY");
pie.on("click", (d, i) => {
var click_value = d.data.key;
d3.select(this).transition().duration("50");
var selectList = [];
data.forEach((element) => {
if (selectedOption != "ALL") {
if (
element["Category"] == click_value &&
element["Type"] == selectedOption
) {
selectList.push(element);
}
} else {
if (element["Category"] == click_value) {
selectList.push(element);
}
}
});
draw_scatt1(selectList, g2, click_value, count);
draw_scatt2(selectList, g3, click_value, count);
draw_scatt4(selectList, g4, click_value, count);
draw_histamgram(selectList, count, g5, 1, click_value);
gpic.selectAll(".sth").remove();
gpic.selectAll('text').remove();
change_picture(gpic, click_value);
});
// // run the updateChart function with this selected option
// updateChart(selectedOption)
var selectList = [];
if (selectedOption != "ALL") {
data.forEach((element) => {
if (element["Type"] == selectedOption) {
//console.log(element)
selectList.push(element);
}
});
} else {
selectList = data;
}
draw_scatt1(selectList, g2, selectedOption, count);
draw_scatt2(selectList, g3, selectedOption, count);
draw_scatt4(selectList, g4, selectedOption, count);
draw_histamgram(selectList, count, g5, 1, selectedOption);
});
});
});