-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderer.js
127 lines (107 loc) · 3.46 KB
/
renderer.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
const {remote} = require('electron');
const {Menu, MenuItem} = remote;
var dialog = remote.dialog;
var path = require('path');
var _ = require('lodash');
var fs = require('fs');
var requirejs = require('requirejs');
requirejs.config({
baseUrl: __dirname,
nodeRequire: require,
paths: {
'plotly-js': './node_modules/plotly.js/dist/'
}
});
try {
console.log('looking for deps here.');
var plotHtml = fs.readFileSync('plot.html').toString();
var parser = requirejs('./parser.js');
var userparser = requirejs('./userParser.js');
var plotter = requirejs('./plotter.js');
var plotly = requirejs('plotly-js/plotly.min');
var d3 = requirejs('d3');
}
catch (err) {
console.log(err);
console.log('looking for deps in electron dist.');
var plotHtml = fs.readFileSync('./resources/app/plot.html').toString();
var parser = requirejs('./resources/app/parser.js');
var userparser = requirejs('./resources/app/userParser.js');
var plotter = requirejs('./resources/app/plotter.js');
var plotly = requirejs('plotly-js/plotly.min');
var d3 = requirejs('d3');
}
var plotIDs = [];
function removeExtension(filename){
var lastDotPosition = filename.lastIndexOf(".");
if (lastDotPosition === -1) return filename;
else return filename.substr(0, lastDotPosition);
}
const menu = new Menu();
menu.append(new MenuItem({label: 'Open Log', click() {
dialog.showOpenDialog(function (fileNames) {
if(fileNames === undefined)
console.log("No file selected");
else {
console.log("Opened " + fileNames);
fs.readFile(fileNames[0], 'utf-8', function(err, data) {
if (err) {
alert("Couldn't open the file: " + err.message);
return;
}
fileNames[0] = removeExtension(path.basename(fileNames[0])).replace(/\./g, '_');
// init vars
var a = fileNames[0],
datas = {};
// Prepare hide plot func
var hidePlotFunc = function(a) {
var active = datas[a].active ? false : true;
var opacity = active ? 0 : 1;
var visibility = active ? 'hidden' : 'visible';
var display = active ? 'none' : 'block';
d3.select('#plot_'+a)
.style('display', display);
datas[a].active = active;
};
// parse the log
var parsed = parser.getDataFromAttribute(data);
if (_.isEmpty(parsed))
parsed = userparser.getDataFromAttribute(data);
datas[a] = parsed;
// plot the logs
for (var a in datas) {
// setup the html
$(plotHtml).appendTo('#main');
var container = $('#log');
$(container).attr('id', 'log_'+a);
var title = $(container).find('#title');
$(title).attr('id','title_'+a)
.on('click', function(_a) {
return function() {
hidePlotFunc(_a);
};
}(a));
title.append('<b>'+a+'</b>');
var p = $(container).find('#plot');
$(p).attr('id',"plot_" + a);
var data = datas[a];
if (!_.isEmpty(data)) {
plotter.plotData('plot_'+a, data);
plotIDs.push('#plot_'+a);
}
else
$(container).detach();
}
});
}
});
}}));
$( window ).resize(function() {
plotIDs.map(function(plotID) {
plotly.Plots.resize(d3.select(plotID).node());
});
});
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
menu.popup(remote.getCurrentWindow());
}, false);