diff --git a/modules/ext.RevisionSlider.RevisionListView.js b/modules/ext.RevisionSlider.RevisionListView.js index b0d3956f..24a0dc2c 100644 --- a/modules/ext.RevisionSlider.RevisionListView.js +++ b/modules/ext.RevisionSlider.RevisionListView.js @@ -20,6 +20,16 @@ */ revisionWidth: 16, + /** + * @type {number} + */ + minRevisionHeight: 5, + + /** + * @type {number} + */ + maxRevisionHeight: 66, + /** * @type {number} */ @@ -59,7 +69,7 @@ for ( i = 0; i < revs.length; i++ ) { diffSize = revs[ i ].getRelativeSize(); - relativeChangeSize = diffSize !== 0 ? Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5 : 0; + relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged ); this.$html .append( $( '
' ) @@ -95,9 +105,11 @@ var revs = this.revisionList.getRevisions(), maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ), i, diffSize, relativeChangeSize; + for ( i = 0; i < revs.length; i++ ) { diffSize = revs[ i ].getRelativeSize(); - relativeChangeSize = diffSize !== 0 ? Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5 : 0; + relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged ); + $renderedList.find( '.mw-revslider-revision[data-pos="' + ( i + 1 ) + '"]' ).css( { height: relativeChangeSize + 'px', top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0 @@ -105,6 +117,16 @@ } }, + calcRelativeChangeSize: function( diffSize, maxChangeSizeLogged ) { + if ( diffSize === 0 ) { + return 0; + } + return Math.ceil( + ( this.maxRevisionHeight - this.minRevisionHeight ) * + Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged + ) + this.minRevisionHeight; + }, + /** * Hides the current tooltip immediately */ diff --git a/tests/qunit/RevisionSlider.RevisionListView.test.js b/tests/qunit/RevisionSlider.RevisionListView.test.js index 05ab6267..e88d3923 100644 --- a/tests/qunit/RevisionSlider.RevisionListView.test.js +++ b/tests/qunit/RevisionSlider.RevisionListView.test.js @@ -21,7 +21,7 @@ assert.equal( $( $revisionDivs[ 0 ] ).attr( 'data-revid' ), 1 ); assert.equal( $( $revisionDivs[ 2 ] ).attr( 'data-revid' ), 37 ); assert.equal( $( $revisionDivs[ 1 ] ).css( 'width' ), '11px' ); - assert.equal( $( $revisionDivs[ 1 ] ).css( 'height' ), '70px' ); // max relative size + assert.equal( $( $revisionDivs[ 1 ] ).css( 'height' ), '66px' ); // max relative size assert.ok( $( $revisionDivs[ 1 ] ).hasClass( 'mw-revslider-revision-up' ) ); assert.ok( $( $revisionDivs[ 2 ] ).hasClass( 'mw-revslider-revision-down' ) ); } );