@@ -15,6 +15,7 @@ var Axes = require('../../plots/cartesian/axes');
15
15
var binFunctions = require ( '../histogram/bin_functions' ) ;
16
16
var normFunctions = require ( '../histogram/norm_functions' ) ;
17
17
var doAvg = require ( '../histogram/average' ) ;
18
+ var cleanBins = require ( '../histogram/clean_bins' ) ;
18
19
19
20
20
21
module . exports = function calc ( gd , trace ) {
@@ -29,6 +30,9 @@ module.exports = function calc(gd, trace) {
29
30
z ,
30
31
i ;
31
32
33
+ cleanBins ( trace , xa , 'x' ) ;
34
+ cleanBins ( trace , ya , 'y' ) ;
35
+
32
36
var serieslen = Math . min ( x . length , y . length ) ;
33
37
if ( x . length > serieslen ) x . splice ( serieslen , x . length - serieslen ) ;
34
38
if ( y . length > serieslen ) y . splice ( serieslen , y . length - serieslen ) ;
@@ -38,8 +42,10 @@ module.exports = function calc(gd, trace) {
38
42
if ( trace . autobinx || ! ( 'xbins' in trace ) ) {
39
43
trace . xbins = Axes . autoBin ( x , xa , trace . nbinsx , '2d' ) ;
40
44
if ( trace . type === 'histogram2dcontour' ) {
41
- trace . xbins . start -= trace . xbins . size ;
42
- trace . xbins . end += trace . xbins . size ;
45
+ // the "true" last argument reverses the tick direction (which we can't
46
+ // just do with a minus sign because of month bins)
47
+ trace . xbins . start = xa . c2r ( Axes . tickIncrement ( xa . r2c ( trace . xbins . start ) , trace . xbins . size , true ) ) ;
48
+ trace . xbins . end = xa . c2r ( Axes . tickIncrement ( xa . r2c ( trace . xbins . end ) , trace . xbins . size ) ) ;
43
49
}
44
50
45
51
// copy bin info back to the source data.
@@ -48,8 +54,8 @@ module.exports = function calc(gd, trace) {
48
54
if ( trace . autobiny || ! ( 'ybins' in trace ) ) {
49
55
trace . ybins = Axes . autoBin ( y , ya , trace . nbinsy , '2d' ) ;
50
56
if ( trace . type === 'histogram2dcontour' ) {
51
- trace . ybins . start -= trace . ybins . size ;
52
- trace . ybins . end += trace . ybins . size ;
57
+ trace . ybins . start = ya . c2r ( Axes . tickIncrement ( ya . r2c ( trace . ybins . start ) , trace . ybins . size , true ) ) ;
58
+ trace . ybins . end = ya . c2r ( Axes . tickIncrement ( ya . r2c ( trace . ybins . end ) , trace . ybins . size ) ) ;
53
59
}
54
60
trace . _input . ybins = trace . ybins ;
55
61
}
@@ -91,11 +97,11 @@ module.exports = function calc(gd, trace) {
91
97
92
98
// decrease end a little in case of rounding errors
93
99
var binspec = trace . xbins ,
94
- binend = binspec . end +
95
- ( binspec . start - Axes . tickIncrement ( binspec . start , binspec . size ) ) / 1e6 ;
100
+ binStart = xa . r2c ( binspec . start ) ,
101
+ binEnd = xa . r2c ( binspec . end ) +
102
+ ( binStart - Axes . tickIncrement ( binStart , binspec . size ) ) / 1e6 ;
96
103
97
- for ( i = binspec . start ; i < binend ;
98
- i = Axes . tickIncrement ( i , binspec . size ) ) {
104
+ for ( i = binStart ; i < binEnd ; i = Axes . tickIncrement ( i , binspec . size ) ) {
99
105
onecol . push ( sizeinit ) ;
100
106
if ( Array . isArray ( xbins ) ) xbins . push ( i ) ;
101
107
if ( doavg ) zerocol . push ( 0 ) ;
@@ -104,15 +110,16 @@ module.exports = function calc(gd, trace) {
104
110
105
111
var nx = onecol . length ;
106
112
x0 = trace . xbins . start ;
107
- dx = ( i - x0 ) / nx ;
108
- x0 += dx / 2 ;
113
+ var x0c = xa . r2c ( x0 ) ;
114
+ dx = ( i - x0c ) / nx ;
115
+ x0 = xa . c2r ( x0c + dx / 2 ) ;
109
116
110
117
binspec = trace . ybins ;
111
- binend = binspec . end +
112
- ( binspec . start - Axes . tickIncrement ( binspec . start , binspec . size ) ) / 1e6 ;
118
+ binStart = ya . r2c ( binspec . start ) ;
119
+ binEnd = ya . r2c ( binspec . end ) +
120
+ ( binStart - Axes . tickIncrement ( binStart , binspec . size ) ) / 1e6 ;
113
121
114
- for ( i = binspec . start ; i < binend ;
115
- i = Axes . tickIncrement ( i , binspec . size ) ) {
122
+ for ( i = binStart ; i < binEnd ; i = Axes . tickIncrement ( i , binspec . size ) ) {
116
123
z . push ( onecol . concat ( ) ) ;
117
124
if ( Array . isArray ( ybins ) ) ybins . push ( i ) ;
118
125
if ( doavg ) counts . push ( zerocol . concat ( ) ) ;
@@ -121,8 +128,9 @@ module.exports = function calc(gd, trace) {
121
128
122
129
var ny = z . length ;
123
130
y0 = trace . ybins . start ;
124
- dy = ( i - y0 ) / ny ;
125
- y0 += dy / 2 ;
131
+ var y0c = ya . r2c ( y0 ) ;
132
+ dy = ( i - y0c ) / ny ;
133
+ y0 = ya . c2r ( y0c + dy / 2 ) ;
126
134
127
135
if ( densitynorm ) {
128
136
xinc = onecol . map ( function ( v , i ) {
0 commit comments