@@ -16,6 +16,7 @@ var binFunctions = require('../histogram/bin_functions');
16
16
var normFunctions = require ( '../histogram/norm_functions' ) ;
17
17
var doAvg = require ( '../histogram/average' ) ;
18
18
var cleanBins = require ( '../histogram/clean_bins' ) ;
19
+ var getBinSpanLabelRound = require ( '../histogram/bin_label_vals' ) ;
19
20
20
21
21
22
module . exports = function calc ( gd , trace ) {
@@ -30,7 +31,7 @@ module.exports = function calc(gd, trace) {
30
31
var xc2r = function ( v ) { return xa . c2r ( v , 0 , xcalendar ) ; } ;
31
32
var yc2r = function ( v ) { return ya . c2r ( v , 0 , ycalendar ) ; } ;
32
33
33
- var i , n , m ;
34
+ var i , j , n , m ;
34
35
35
36
var serieslen = Math . min ( x . length , y . length ) ;
36
37
if ( x . length > serieslen ) x . splice ( serieslen , x . length - serieslen ) ;
@@ -46,10 +47,13 @@ module.exports = function calc(gd, trace) {
46
47
var zerocol = [ ] ;
47
48
var nonuniformBinsX = ( typeof ( trace . xbins . size ) === 'string' ) ;
48
49
var nonuniformBinsY = ( typeof ( trace . ybins . size ) === 'string' ) ;
49
- var xbins = nonuniformBinsX ? [ ] : trace . xbins ;
50
- var ybins = nonuniformBinsY ? [ ] : trace . ybins ;
50
+ var xEdges = [ ] ;
51
+ var yEdges = [ ] ;
52
+ var xbins = nonuniformBinsX ? xEdges : trace . xbins ;
53
+ var ybins = nonuniformBinsY ? yEdges : trace . ybins ;
51
54
var total = 0 ;
52
55
var counts = [ ] ;
56
+ var inputPoints = [ ] ;
53
57
var norm = trace . histnorm ;
54
58
var func = trace . histfunc ;
55
59
var densitynorm = ( norm . indexOf ( 'density' ) !== - 1 ) ;
@@ -83,10 +87,10 @@ module.exports = function calc(gd, trace) {
83
87
84
88
for ( i = binStart ; i < binEnd ; i = Axes . tickIncrement ( i , binSpec . size , false , xcalendar ) ) {
85
89
onecol . push ( sizeinit ) ;
86
- if ( nonuniformBinsX ) xbins . push ( i ) ;
90
+ xEdges . push ( i ) ;
87
91
if ( doavg ) zerocol . push ( 0 ) ;
88
92
}
89
- if ( nonuniformBinsX ) xbins . push ( i ) ;
93
+ xEdges . push ( i ) ;
90
94
91
95
var nx = onecol . length ;
92
96
var x0c = xr2c ( trace . xbins . start ) ;
@@ -100,10 +104,13 @@ module.exports = function calc(gd, trace) {
100
104
101
105
for ( i = binStart ; i < binEnd ; i = Axes . tickIncrement ( i , binSpec . size , false , ycalendar ) ) {
102
106
z . push ( onecol . slice ( ) ) ;
103
- if ( nonuniformBinsY ) ybins . push ( i ) ;
107
+ yEdges . push ( i ) ;
108
+ var ipCol = new Array ( nx ) ;
109
+ for ( j = 0 ; j < nx ; j ++ ) ipCol [ j ] = [ ] ;
110
+ inputPoints . push ( ipCol ) ;
104
111
if ( doavg ) counts . push ( zerocol . slice ( ) ) ;
105
112
}
106
- if ( nonuniformBinsY ) ybins . push ( i ) ;
113
+ yEdges . push ( i ) ;
107
114
108
115
var ny = z . length ;
109
116
var y0c = yr2c ( trace . ybins . start ) ;
@@ -121,11 +128,36 @@ module.exports = function calc(gd, trace) {
121
128
if ( ! nonuniformBinsY && ya . type === 'date' ) ybins = binsToCalc ( yr2c , ybins ) ;
122
129
123
130
// put data into bins
131
+ var uniqueValsPerX = true ;
132
+ var uniqueValsPerY = true ;
133
+ var xVals = new Array ( nx ) ;
134
+ var yVals = new Array ( ny ) ;
135
+ var xGapLow = Infinity ;
136
+ var xGapHigh = Infinity ;
137
+ var yGapLow = Infinity ;
138
+ var yGapHigh = Infinity ;
124
139
for ( i = 0 ; i < serieslen ; i ++ ) {
125
- n = Lib . findBin ( x [ i ] , xbins ) ;
126
- m = Lib . findBin ( y [ i ] , ybins ) ;
140
+ var xi = x [ i ] ;
141
+ var yi = y [ i ] ;
142
+ n = Lib . findBin ( xi , xbins ) ;
143
+ m = Lib . findBin ( yi , ybins ) ;
127
144
if ( n >= 0 && n < nx && m >= 0 && m < ny ) {
128
145
total += binfunc ( n , i , z [ m ] , rawCounterData , counts [ m ] ) ;
146
+ inputPoints [ m ] [ n ] . push ( i ) ;
147
+
148
+ if ( uniqueValsPerX ) {
149
+ if ( xVals [ n ] === undefined ) xVals [ n ] = xi ;
150
+ else if ( xVals [ n ] !== xi ) uniqueValsPerX = false ;
151
+ }
152
+ if ( uniqueValsPerY ) {
153
+ if ( yVals [ n ] === undefined ) yVals [ n ] = yi ;
154
+ else if ( yVals [ n ] !== yi ) uniqueValsPerY = false ;
155
+ }
156
+
157
+ xGapLow = Math . min ( xGapLow , xi - xEdges [ n ] ) ;
158
+ xGapHigh = Math . min ( xGapHigh , xEdges [ n + 1 ] - xi ) ;
159
+ yGapLow = Math . min ( yGapLow , yi - yEdges [ m ] ) ;
160
+ yGapHigh = Math . min ( yGapHigh , yEdges [ m + 1 ] - yi ) ;
129
161
}
130
162
}
131
163
// normalize, if needed
@@ -138,12 +170,15 @@ module.exports = function calc(gd, trace) {
138
170
139
171
return {
140
172
x : x ,
173
+ xRanges : getRanges ( xEdges , uniqueValsPerX && xVals , xGapLow , xGapHigh , xa , xcalendar ) ,
141
174
x0 : x0 ,
142
175
dx : dx ,
143
176
y : y ,
177
+ yRanges : getRanges ( yEdges , uniqueValsPerY && yVals , yGapLow , yGapHigh , ya , ycalendar ) ,
144
178
y0 : y0 ,
145
179
dy : dy ,
146
- z : z
180
+ z : z ,
181
+ pts : inputPoints
147
182
} ;
148
183
} ;
149
184
@@ -195,3 +230,17 @@ function binsToCalc(r2c, bins) {
195
230
size : bins . size
196
231
} ;
197
232
}
233
+
234
+ function getRanges ( edges , uniqueVals , gapLow , gapHigh , ax , calendar ) {
235
+ var i ;
236
+ var len = edges . length - 1 ;
237
+ var out = new Array ( len ) ;
238
+ if ( uniqueVals ) {
239
+ for ( i = 0 ; i < len ; i ++ ) out [ i ] = [ uniqueVals [ i ] , uniqueVals [ i ] ] ;
240
+ }
241
+ else {
242
+ var roundFn = getBinSpanLabelRound ( gapLow , gapHigh , edges , ax , calendar ) ;
243
+ for ( i = 0 ; i < len ; i ++ ) out [ i ] = [ roundFn ( edges [ i ] ) , roundFn ( edges [ i + 1 ] , true ) ] ;
244
+ }
245
+ return out ;
246
+ }
0 commit comments