-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
270 lines (247 loc) · 9.97 KB
/
Copy pathmain.js
File metadata and controls
270 lines (247 loc) · 9.97 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
var tone = require('./response.js');
var $ = require('./jquery-1.12.4.js');
var d3 = require("d3");
var c3 = require("c3")
'use strict';
//Executes when the Document Object Model (DOM) is ready for JavaScript code
$( document ).ready(function() {
var gmail = new Gmail();
var make_emotion_array_for_d3 = function(data, status, compose) {
var emotion_toneA = "";
var emotion_toneB = "";
var emotion_toneC = "";
var emotion_toneD = "";
var emotion_toneE = "";
var emotion_scoreA = "";
var emotion_scoreB = "";
var emotion_scoreC = "";
var emotion_scoreD = "";
var emotion_scoreE = "";
emotion_toneA = (data.document_tone.tone_categories[0].tones[0].tone_name);
emotion_scoreA = (data.document_tone.tone_categories[0].tones[0].score*100);
emotion_toneB = (data.document_tone.tone_categories[0].tones[1].tone_name);
emotion_scoreB = (data.document_tone.tone_categories[0].tones[1].score*100);
emotion_toneC = (data.document_tone.tone_categories[0].tones[2].tone_name);
emotion_scoreC = (data.document_tone.tone_categories[0].tones[2].score*100);
emotion_toneD = (data.document_tone.tone_categories[0].tones[3].tone_name);
emotion_scoreD = (data.document_tone.tone_categories[0].tones[3].score*100);
emotion_toneE = (data.document_tone.tone_categories[0].tones[4].tone_name);
emotion_scoreE = (data.document_tone.tone_categories[0].tones[4].score*100);
var emotion = [ emotion_toneA, emotion_scoreA, emotion_toneB, emotion_scoreB, emotion_toneC, emotion_scoreC, emotion_toneD, emotion_scoreD, emotion_toneE, emotion_scoreE ];
var myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin() {
myWindow.close();
}
// var email_content = compose.body();
// compose.body(email_content, pie_chart(d3,c3, emotion));
// var myWindown = window.open("tone", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
};
// var myWindown = window.open("", "MsgWindow", "width=200, height=200");
// myWindown.document.getElementById("emotion_chart").innerHTML = (pie_chart(d3,c3,emotion));
//
// };
var pie_chart = function(d3, c3, emotion) {
var container = d3.select("div"); // container
container.append("div")
.text("Emotion Tone")
.style("font-size", "15px")
.style("margin-top", "30px")
.style("margin-left", "48px")
.attr("class", "tone_chart");
container.append("div") //
.attr("class", "tone_chart")
.attr("id", "emotion_chart");
var pie = c3.generate({
size: {
height: 300,
width: 480
},
data: {
columns: [
[emotion[0], emotion[1]],
[emotion[2], emotion[3]],
[emotion[4], emotion[5]],
[emotion[6], emotion[7]],
[emotion[8], emotion[9]]
],
type : 'pie',
},
color: {
pattern: ["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]
},
bindto: '#emotion_chart',
});
};
//
// var make_social_array_for_d3 = function(data, status, compose) {
// var social_toneA = "";
// var social_toneB = "";
// var social_toneC = "";
// var social_toneD = "";
// var social_toneE = "";
// var social_scoreA = "";
// var social_scoreB = "";
// var social_scoreC = "";
// var social_scoreD = "";
// var social_scoreE = "";
//
// social_toneA = (data.document_tone.tone_categories[2].tones[0].tone_name);
// social_scoreA = (data.document_tone.tone_categories[2].tones[0].score*100);
// social_toneB = (data.document_tone.tone_categories[2].tones[1].tone_name);
// social_scoreB = (data.document_tone.tone_categories[2].tones[1].score*100);
// social_toneC = (data.document_tone.tone_categories[2].tones[2].tone_name);
// social_scoreC = (data.document_tone.tone_categories[2].tones[2].score*100);
// social_toneD = (data.document_tone.tone_categories[2].tones[3].tone_name);
// social_scoreD = (data.document_tone.tone_categories[2].tones[3].score*100);
// social_toneE = (data.document_tone.tone_categories[2].tones[4].tone_name);
// social_scoreE = (data.document_tone.tone_categories[2].tones[4].score*100);
//
// var social = [ social_toneA, social_scoreA, social_toneB, social_scoreB, social_toneC, social_scoreC, social_toneD, social_scoreD, social_toneE, social_scoreE ];
//
// // var email_content = compose.body();
// // compose.body(email_content, pie_chart2(d3,c3, social));
// // window.open("pie_chart2(d3,c3, social)");
// };
//
// var pie_chart2 = function(d3, c3, social) {
// var container = d3.select(".aoX"); // container M9
// container.append("div") // creates an h1 and returns it
// .text("Social Tone") //operating on h1 sets text and returns the h1 element
// .style("font-size", "16px")
// .style("margin-top", "30px")
// .style("margin-left", "48px")
// .attr("class", "tone_chart");
// container.append("div") //
// .attr("class", "tone_chart")
// .attr("id", "social_chart");
//
// var pie = c3.generate({
// size: {
// height: 300,
// width: 480
// },
// data: {
// columns: [
// [social[0], social[1]],
// [social[2], social[3]],
// [social[4], social[5]],
// [social[6], social[7]],
// [social[8], social[9]]
// ],
// type : 'pie',
// },
// color: {
// pattern: ["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]
// },
// bindto: '#social_chart',
// });
// };
// var make_language_array_for_d3 = function(data, status, compose) {
// var language_toneA = "";
// var language_toneB = "";
// var language_toneC = "";
// var language_scoreA = "";
// var language_scoreB = "";
// var language_scoreC = "";
//
// language_toneA = (data.document_tone.tone_categories[1].tones[0].tone_name);
// language_scoreA = (data.document_tone.tone_categories[1].tones[0].score*100);
// language_toneB = (data.document_tone.tone_categories[1].tones[1].tone_name);
// language_scoreB = (data.document_tone.tone_categories[1].tones[1].score*100);
// language_toneC = (data.document_tone.tone_categories[1].tones[2].tone_name);
// language_scoreC = (data.document_tone.tone_categories[1].tones[2].score*100);
//
//
// var language = [ language_toneA, language_scoreA, language_toneB, language_scoreB, language_toneC, language_scoreC];
// console.log(language_toneA);
// console.log(language_scoreA);
// var email_content = compose.body();
// compose.body(email_content, pie_chart3(d3,c3, language));
// };
//
//
// var pie_chart3 = function(d3, c3, language) {
// console.log(language);
// var container = d3.select(".aoX"); // container
// container.append("div")
// .text("Language Tone")
// .style("margin-top", "30px")
// .style("margin-left", "48px")
// .attr("class", "tone_chart");
// container.append("div") //
// .attr("class", "tone_chart")
// .attr("id", "language_chart");
//
// var pie = c3.generate({
// size: {
// height: 300,
// width: 480
// },
// data: {
// columns: [
// [language[0], language[1]],
// [language[2], language[3]],
// [language[4], language[5]],
// ],
// type : 'pie',
// },
// color: {
// pattern: ["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]
// },
// bindto: '#language_chart',
// });
// };
var create_handler_for = function(compose) {
var clicked = false; //
var click_handler = function(event) {
clicked = !clicked;
console.log(clicked);
// $(".Hq").mousedown(function() {
// console.log('are we here?');
// $(".Am.Al.editable.LW-avf").css('min-height', '0px');
// setTimeout(function(){
// $(".Am.Al.editable.LW-avf").css('min-height', '0px');
//
// }, 500);
// });
if (clicked === true) {
// step 1: get the compose text body
var email_content = compose.body();
// Step 2: Send it to my app
$.post("https://tonalyze.herokuapp.com/analyze",
// wrapped the reportMaker that takes data and status so that it could also pass through compose
{ text: email_content }, function(data, status) {
// reportMaker(data, status, compose);
// $(".Am.Al.editable.LW-avf").css('min-height', '0px');
// step 3: call d3 functions
make_emotion_array_for_d3(data, status, compose);
// make_social_array_for_d3(data, status, compose);
// make_language_array_for_d3(data, status, compose);
}); // calling these 3 functions
}
// Step 4: Click function that removes analysis
else if (clicked === false){
d3.selectAll(".tone_chart").remove();
// myWindow.close(); // this is what I want to remove the window
}
};
return click_handler;
};
// Returns the html element (button) of the last composed email
var make_button = function(compose, type) {
// Makes a custom click_handler function for the window that is stored in the "compose" variable
var handler = create_handler_for(compose);
gmail.tools.add_compose_button(
compose,'Tonalyze', handler, 'test_this' );
};
// Makes a button when a new compose window opens
gmail = new Gmail();
gmail.observe.on(
"compose", make_button
);
console.log( 'ready!' );
});