Skip to content

Commit 720db11

Browse files
committed
refactor image functions
1 parent 12b4b99 commit 720db11

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/traces/image/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
module.exports = {

src/traces/image/defaults.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Lib = require('../../lib');

src/traces/image/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
attributes: require('./attributes'),
1313
supplyDefaults: require('./defaults'),
1414
calc: require('./calc'),
15-
plot: require('./plot').plot,
15+
plot: require('./plot'),
1616
style: require('./style'),
1717
hoverPoints: require('./hover'),
1818
eventData: require('./event_data'),

src/traces/image/plot.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77
*/
88

99
'use strict';
10+
1011
var d3 = require('d3');
1112
var Lib = require('../../lib');
1213
var isNumeric = require('fast-isnumeric');
1314
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1415
var constants = require('./constants');
1516

16-
module.exports = {};
17+
function scale(zero, factor, min, max) {
18+
return function(c) {
19+
c = (c - zero) * factor;
20+
c = Lib.constrain(c, min, max);
21+
return c;
22+
};
23+
}
24+
25+
function constrain(min, max) {
26+
return function(c) { return Lib.constrain(c, min, max);};
27+
}
1728

1829
// Generate a function to scale color components according to zmin/zmax and the colormodel
19-
var scaler = function(trace) {
30+
var makeScaler = function(trace) {
2031
var colormodel = trace.colormodel;
2132
var n = colormodel.length;
2233
var cr = constants.colormodel[colormodel];
2334

24-
function scale(zero, factor, min, max) {
25-
return function(c) {
26-
c = (c - zero) * factor;
27-
c = Lib.constrain(c, min, max);
28-
return c;
29-
};
30-
}
31-
32-
function constrain(min, max) {
33-
return function(c) { return Lib.constrain(c, min, max);};
34-
}
35-
3635
var s = [];
3736
// Loop over all color components
3837
for(var k = 0; k < n; k++) {
@@ -58,7 +57,8 @@ var scaler = function(trace) {
5857
return c;
5958
};
6059
};
61-
module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
60+
61+
module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
6262
var xa = plotinfo.xaxis;
6363
var ya = plotinfo.yaxis;
6464

@@ -132,10 +132,11 @@ module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
132132
canvas.width = imageWidth;
133133
canvas.height = imageHeight;
134134
var context = canvas.getContext('2d');
135+
135136
var ipx = function(i) {return Lib.constrain(Math.round(xa.c2p(x0 + i * dx) - left), 0, imageWidth);};
136137
var jpx = function(j) {return Lib.constrain(Math.round(ya.c2p(y0 + j * dy) - top), 0, imageHeight);};
137138

138-
trace._scaler = scaler(trace);
139+
trace._scaler = makeScaler(trace);
139140
var fmt = constants.colormodel[trace.colormodel].fmt;
140141
var c;
141142
for(i = 0; i < cd0.w; i++) {

src/traces/image/style.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var d3 = require('d3');

0 commit comments

Comments
 (0)