Let revision bars leave space for the pointer line end border

The end border for the pointer lines can not be displayed because the
bars on the biggest revisions used all the height. This patch reduces
the max height of the bars slightly and refactores the calculating method.

Bug: T163436
Change-Id: Idfa6bdb9f85221063e13f3ec16b22fcfbe6cbd9c
This commit is contained in:
WMDE-Fisch 2017-04-20 14:57:48 +02:00
parent 3c4c9fed0d
commit 72d19630ad
2 changed files with 25 additions and 3 deletions

View file

@ -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( $( '<div>' )
@ -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
*/

View file

@ -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' ) );
} );