Skip to content

Commit

Permalink
Merge pull request #141 from stefanjudis/feature/119-limit-displayed-…
Browse files Browse the repository at this point in the history
…results-in-ui

add number limited graph display for results - fix #119
  • Loading branch information
stefanjudis committed Nov 30, 2014
2 parents 6d53a60 + e5d30b1 commit 0669f7e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"quotmark": "single",
"unused": true,
"trailing": true,
"maxparams": 3,
"maxparams": 4,
"maxdepth": 3,
"predef": [ "-Promise" ]
}
2 changes: 1 addition & 1 deletion tasks/assets/sass/components/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@
[class*="p--switcher"] {
float: right;

margin : 0;
margin : 0 0 0 0.5em;
padding: 0;
}
48 changes: 35 additions & 13 deletions tasks/assets/scripts/phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@
/**
* draw the fancy line chart
*
* @param {Array} data data
* @param {String} metric metric
* @param {String} type median|max|min|...
* @param {Array} data data
* @param {String} metric metric
* @param {String} type median|max|min|...
* @param {Number|undefined} lastRuns number of last displayed runs
*/
function drawLineChart( data, metric, type ) {
function drawLineChart( data, metric, type, lastRuns ) {
// Helper functions on top of 8-)

/**
Expand Down Expand Up @@ -333,8 +334,10 @@
circleContainer,
zoom;

// Compute the minimum and maximum date
x.domain( [ data[ 0 ].date, data[ data.length - 1 ].date ] );
// Compute x-positions for the minimum and maximum date
lastRuns = lastRuns || 10;
var startIndex = ( data.length >= lastRuns ) ? data.length - lastRuns : 0;
x.domain( [ data[ startIndex ].date, data[ data.length - 1 ].date ] );
// hacky hacky hacky :(
y.domain( [
0,
Expand Down Expand Up @@ -434,7 +437,7 @@
// configure zoom
zoom = d3.behavior.zoom()
.x( x )
.scaleExtent( [ 1, 100 ] )
.scaleExtent( [ 0, 100 ] )
.on( 'zoom', zoomed );

// set up zoom pane
Expand Down Expand Up @@ -683,15 +686,32 @@
}


/**
* Attach event to select box to rerender
* graphs depending on chosen tyoe
*/
function attachLastRunsChangeEvent() {
var switcher = document.getElementById( 'p--switcher--lastRuns' );

addEvent( switcher, 'change', function( event ) {
var currentMetric = document.getElementById( 'p--switcher--metrics' ).value;

drawLineCharts( window.results, currentMetric, +event.target.value );
} );
}


/**
* Attach event to select box to rerender
* graphs depending on chosen tyoe
*/
function attachMetricChangeEvent() {
var switcher = document.getElementById( 'p--switcher--metrics' );
var switcher = document.getElementById( 'p--switcher--metrics' );

addEvent( switcher, 'change', function( event ) {
drawLineCharts( window.results, event.target.value );
var currentLastRuns = +document.getElementById( 'p--switcher--lastRuns' ).value;

drawLineCharts( window.results, event.target.value, currentLastRuns );
} );
}

Expand All @@ -705,6 +725,7 @@
attachDescriptionEvents();
attachHeaderEvents();
attachMetricChangeEvent();
attachLastRunsChangeEvent();
}


Expand Down Expand Up @@ -758,10 +779,11 @@
* Check all metrics if numeric values are
* included and initialize all graphs for it
*
* @param {Array} data data
* @param {String|undefined} type type of displayed data
* @param {Array} data data
* @param {String|undefined} type type of displayed data
* @parem {Number|undefined} lastRuns number of last displayed runs
*/
function drawLineCharts( data, type ) {
function drawLineCharts( data, type, lastRuns ) {
var lastMetric = data[ data.length - 1 ];
var loaders = document.querySelectorAll( '.p--graphs--loading' );

Expand All @@ -778,7 +800,7 @@
metric !== 'timestamp' &&
document.getElementById( 'graph--' + metric )
) {
setTimeout( drawLineChart.bind( null, data, metric, type ), 250 );
setTimeout( drawLineChart.bind( null, data, metric, type, lastRuns ), 250 );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/public/scripts/phantomas.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 0669f7e

Please sign in to comment.