@@ -1530,7 +1530,7 @@ links.Graph3d.prototype._redrawDataGrid = function() {
15301530
15311531 // calculate the translation of the point at the bottom (needed for sorting)
15321532 var transBottom = this . _convertPointToTranslation ( this . dataPoints [ i ] . bottom ) ;
1533- this . dataPoints [ i ] . dist = transBottom . length ( ) ;
1533+ this . dataPoints [ i ] . dist = this . showPerspective ? transBottom . length ( ) : - transBottom . z ;
15341534 }
15351535
15361536 // sort the points on depth of their (x,y) position (not on z)
@@ -1668,7 +1668,7 @@ links.Graph3d.prototype._redrawDataDot = function() {
16681668
16691669 // calculate the distance from the point at the bottom to the camera
16701670 var transBottom = this . _convertPointToTranslation ( this . dataPoints [ i ] . bottom ) ;
1671- this . dataPoints [ i ] . dist = transBottom . length ( ) ;
1671+ this . dataPoints [ i ] . dist = this . showPerspective ? transBottom . length ( ) : - transBottom . z ;
16721672 }
16731673
16741674 // order the translated points by depth
@@ -1764,7 +1764,7 @@ links.Graph3d.prototype._redrawDataBar = function() {
17641764
17651765 // calculate the distance from the point at the bottom to the camera
17661766 var transBottom = this . _convertPointToTranslation ( this . dataPoints [ i ] . bottom ) ;
1767- this . dataPoints [ i ] . dist = transBottom . length ( ) ;
1767+ this . dataPoints [ i ] . dist = this . showPerspective ? transBottom . length ( ) : - transBottom . z ;
17681768 }
17691769
17701770 // order the translated points by depth
@@ -1844,12 +1844,20 @@ links.Graph3d.prototype._redrawDataBar = function() {
18441844 ( corners [ 0 ] . point . z + corners [ 1 ] . point . z + corners [ 2 ] . point . z + corners [ 3 ] . point . z ) / 4
18451845 ) ;
18461846 var trans = this . _convertPointToTranslation ( center ) ;
1847- surface . dist = trans . length ( ) ;
1847+ surface . dist = this . showPerspective ? trans . length ( ) : - trans . z ;
18481848 }
18491849
18501850 // order the surfaces by their (translated) depth
18511851 surfaces . sort ( function ( a , b ) {
1852- return b . dist - a . dist ;
1852+ var diff = b . dist - a . dist ;
1853+ if ( diff ) return diff ;
1854+
1855+ // if equal depth, sort the top surface last
1856+ if ( a . corners === top ) return 1 ;
1857+ if ( b . corners === top ) return - 1 ;
1858+
1859+ // both are equal
1860+ return 0 ;
18531861 } ) ;
18541862
18551863 // draw the ordered surfaces
0 commit comments