Skip to content

Commit

Permalink
updated to remove unneeded code regarding offsets and to fix trace pl…
Browse files Browse the repository at this point in the history
…ot time stamp calculation in parser since move to absolute time.
  • Loading branch information
finger563 committed Apr 11, 2017
1 parent ef41a80 commit 2ccb6d2
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 163 deletions.
4 changes: 2 additions & 2 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ define([], function() {
data : [],
};
}
var enq = parseFloat(result[2]) * 1000000.0;
var comp = parseFloat(result[4]) * 1000000.0;
var enq = parseFloat(result[2]) * 1000.0;
var comp = parseFloat(result[4]) * 1000.0;
var exec_time = parseFloat(result[5]);
log_data[alias].data.push([enq, 0]);
log_data[alias].data.push([enq, exec_time]);
Expand Down
176 changes: 88 additions & 88 deletions plotter.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
define(['plotly-js/plotly.min', 'd3'], function(Plotly,d3) {
'use strict';
return {
plotData: function(plotId, data, offset) {
// extent returns array: [min, max]
var maxXs = Object.keys(data).map(function(key) {
return d3.extent(data[key].data, function(xy) { return xy[0] - offset; })[1];
});
var maxYs = Object.keys(data).map(function(key) {
return d3.extent(data[key].data, function(xy) { return xy[1]; })[1];
});
var xdomain = d3.max(maxXs);
var ydomain = d3.max(maxYs);
plotData: function(plotId, data) {
// extent returns array: [min, max]
var maxXs = Object.keys(data).map(function(key) {
return d3.extent(data[key].data, function(xy) { return xy[0]; })[1];
});
var maxYs = Object.keys(data).map(function(key) {
return d3.extent(data[key].data, function(xy) { return xy[1]; })[1];
});
var xdomain = d3.max(maxXs);
var ydomain = d3.max(maxYs);

var pdata = [];
var pdata = [];

Object.keys(data).map(function(key) {
pdata.push({
x : data[key].data.map(function(xy) { return new Date(xy[0]); }),
y : data[key].data.map(function(xy) { return xy[1]; }),
mode: 'lines',
Object.keys(data).map(function(key) {
pdata.push({
x : data[key].data.map(function(xy) { return new Date(xy[0]); }),
y : data[key].data.map(function(xy) { return xy[1]; }),
mode: 'lines',
type: 'scatter',
name: key,
name: key,
marker: {
maxdisplayed: 1000 // ,
/*
color: "rgb(164, 194, 244)",
size: 12,
line: {
color: "white",
width: 0.5
}
*/
color: "rgb(164, 194, 244)",
size: 12,
line: {
color: "white",
width: 0.5
}
*/
}
});
});
});
});

var layout = {
xaxis: {
title: 'Time (s)'
},
var layout = {
xaxis: {
title: 'Time (s)'
},
legend: {
xanchor: 'right'
},
Expand All @@ -52,66 +52,66 @@ define(['plotly-js/plotly.min', 'd3'], function(Plotly,d3) {
hovermode: 'closest',
autosize: true,
showlegend: true
};
};

Plotly.plot(plotId, pdata, layout, {
modeBarButtons: [[{
'name': 'toImage',
'title': 'Download plot as png',
'icon': Plotly.Icons.camera,
'click': function(gd) {
var format = 'png';
var id = '#'+plotId;
Plotly.plot(plotId, pdata, layout, {
modeBarButtons: [[{
'name': 'toImage',
'title': 'Download plot as png',
'icon': Plotly.Icons.camera,
'click': function(gd) {
var format = 'png';
var id = '#'+plotId;

/*
Plotly.Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
/*
Plotly.Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
if(Plotly.Lib.isIE()) {
Plotly.Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
format = 'svg';
}
*/

Plotly.downloadImage(gd, {
'format': format,
'width': $(id).width(),
'width': $(id).width(),
})
.then(function(filename) {
//Plotly.Lib.notifier('Snapshot succeeded - ' + filename, 'long');
})
.catch(function() {
//Plotly.Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
});
}
}],[
'zoom2d',
'pan2d',
'select2d',
'lasso2d',
'zoomIn2d',
'zoomOut2d',
'autoScale2d',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian'
]],
/*
modeBarButtonsToRemove: ['toImage', 'sendDataToCloud'],
modeBarButtonsToAdd: [{
name: 'toImage2',
icon: Plotly.Icons.camera,
click: function(gd) {
console.log($('#'+plotId).height());
console.log($('#'+plotId).width());
Plotly.downloadImage(gd, {
height: $('#'+plotId).height(),
width: $('#'+plotId).width(),
});
}
}],
*/
});
}
if(Plotly.Lib.isIE()) {
Plotly.Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
format = 'svg';
}
*/
Plotly.downloadImage(gd, {
'format': format,
'width': $(id).width(),
'height': $(id).height(),
})
.then(function(filename) {
//Plotly.Lib.notifier('Snapshot succeeded - ' + filename, 'long');
})
.catch(function() {
//Plotly.Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
});
}
}],[
'zoom2d',
'pan2d',
'select2d',
'lasso2d',
'zoomIn2d',
'zoomOut2d',
'autoScale2d',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian'
]],
/*
modeBarButtonsToRemove: ['toImage', 'sendDataToCloud'],
modeBarButtonsToAdd: [{
name: 'toImage2',
icon: Plotly.Icons.camera,
click: function(gd) {
console.log($('#'+plotId).height());
console.log($('#'+plotId).width());
Plotly.downloadImage(gd, {
height: $('#'+plotId).height(),
width: $('#'+plotId).width(),
});
}
}],
*/
});
}
};
});
127 changes: 54 additions & 73 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,90 +51,71 @@ function removeExtension(filename){
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 {
if(fileNames === undefined)
console.log("No file selected");
else {
console.log("Opened " + fileNames);
fs.readFile(fileNames[0], 'utf-8', function(err, data) {
if (err) {
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 = {},
first_time = undefined,
last_time = undefined;

// 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))
}
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;
var aliases = Object.keys(datas[a]);
aliases.map((key) => {
var d = datas[a][key].data;
var first_entry = d[0];
var last_entry = d[d.length-1];
if ( first_time === undefined || first_time > first_entry[0] ) {
first_time = first_entry[0];
}
if ( last_time === undefined || last_time < last_entry[0] ) {
last_time = last_entry[0];
}
});
// 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];
var offset = first_time;
if (!_.isEmpty(data)) {
var aliases = Object.keys(data);
aliases.map((key) => {
data[key].data.push([last_time, 0]);
});
plotter.plotData('plot_'+a, data, offset);
plotIDs.push('#plot_'+a); }
else
$(container).detach();
}
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());
plotly.Plots.resize(d3.select(plotID).node());
});
});

Expand Down

0 comments on commit 2ccb6d2

Please sign in to comment.