Skip to content

Commit

Permalink
fix #4; add back in mark support
Browse files Browse the repository at this point in the history
  • Loading branch information
englercj committed Feb 9, 2015
1 parent 28927dc commit 833a410
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/panels/Performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Performance.prototype.createPanelElement = function () {
};

Performance.prototype.update = function () {
this.graph.addData(this.parent.timings);
this.graph.addData(this.parent.timings, this.eventQueue.shift());
};

Performance.prototype.mark = function (label) {
Expand Down
29 changes: 26 additions & 3 deletions src/util/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function Graph(container, width, height, colors, options) {
this.legendBoxSize = 10;
this.legendIndent = 5;

this.eventY = this.padding * 2;

this.colors = colors;

this.dataCanvas = document.createElement('canvas');
Expand All @@ -38,13 +40,13 @@ Graph.prototype.constructor = Graph;
module.exports = Graph;

// render the graph with the new data point
Graph.prototype.addData = function (values) {
Graph.prototype.addData = function (values, event) {
// clear the main canvas
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);

this.drawBg();
this.drawLegend(values);
this.drawData(values);
this.drawData(values, event);
};

Graph.prototype.drawBg = function () {
Expand Down Expand Up @@ -116,7 +118,7 @@ Graph.prototype.drawLegend = function (values) {
}
};

Graph.prototype.drawData = function (values) {
Graph.prototype.drawData = function (values, event) {
var x = this.dataCanvas.width - this.dataLineWidth + 0.5,
y = this.dataCanvas.height - 0.5;

Expand All @@ -136,6 +138,27 @@ Graph.prototype.drawData = function (values) {
// draw the buffer back to the data canvas
this.dctx.drawImage(this.dataCanvasBuffer, 0, 0);

// draw event to the new line of the data canvas if there was one
if (event) {
this.dctx.beginPath();
this.dctx.strokeStyle = this.dctx.fillStyle = '#ff0000';
this.dctx.lineWidth = this.dataLineWidth;

this.dctx.moveTo(x, y);
this.dctx.lineTo(x, 0);

this.dctx.stroke();

this.dctx.textAlign = 'right';
this.dctx.fillText(event, x - this.padding, this.eventY);

this.eventY += (this.padding * 2);

if (this.eventY > (this.dataCanvas.height / 2)) {
this.eventY = (this.padding * 2);
}
}

// draws the data values to the new line of the data canvas

// draw the new data points
Expand Down

0 comments on commit 833a410

Please sign in to comment.