Skip to content

Commit 73c0740

Browse files
committed
image: fix style, update attribute's valType and description
1 parent e7eeb38 commit 73c0740

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Plotly.register([
2323
require('./violin'),
2424
require('./funnel'),
2525
require('./waterfall'),
26+
require('./image'),
2627

2728
require('./pie'),
2829
require('./sunburst'),
@@ -56,7 +57,6 @@ Plotly.register([
5657

5758
require('./sankey'),
5859
require('./indicator'),
59-
require('./image'),
6060

6161
require('./table'),
6262

src/traces/image/attributes.js

+30-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
var plotAttrs = require('../../plots/attributes');
1212
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
1313
var extendFlat = require('../../lib/extend').extendFlat;
14+
var colormodel = require('./constants').colormodel;
15+
16+
var cm = ['rgb', 'rgba', 'hsl', 'hsla'];
17+
var zminDesc = [];
18+
var zmaxDesc = [];
19+
for(var i = 0; i < cm.length; i++) {
20+
zminDesc.push('For the `' + cm[i] + '` colormodel, it is [' + colormodel[cm[i]].min.join(', ') + ']');
21+
zmaxDesc.push('For the `' + cm[i] + '` colormodel, it is [' + colormodel[cm[i]].max.join(', ') + ']');
22+
}
1423

1524
module.exports = extendFlat({
1625
z: {
@@ -23,29 +32,43 @@ module.exports = extendFlat({
2332
},
2433
colormodel: {
2534
valType: 'enumerated',
26-
values: ['rgb', 'rgba', 'hsl', 'hsla'],
35+
values: cm,
2736
dflt: 'rgb',
2837
role: 'info',
2938
editType: 'plot',
3039
description: 'Color model used to map the numerical color components described in `z` into colors.'
3140
},
3241
zmin: {
33-
valType: 'data_array',
42+
valType: 'info_array',
43+
dimensions: '1-2',
44+
items: [
45+
{valType: 'number', editType: 'plot'},
46+
{valType: 'number', editType: 'plot'},
47+
{valType: 'number', editType: 'plot'},
48+
{valType: 'number', editType: 'plot'}
49+
],
3450
role: 'info',
3551
editType: 'plot',
3652
description: [
3753
'Array defining the lower bound for each color component.',
38-
'For example, for the `rgba` colormodel, the default value is [0, 0, 0, 0].'
39-
].join(' ')
54+
'Note that the default value will depend on the colormodel.'
55+
].concat(zminDesc).join(' ')
4056
},
4157
zmax: {
42-
valType: 'data_array',
58+
valType: 'info_array',
59+
dimensions: '1-2',
60+
items: [
61+
{valType: 'number', editType: 'plot'},
62+
{valType: 'number', editType: 'plot'},
63+
{valType: 'number', editType: 'plot'},
64+
{valType: 'number', editType: 'plot'}
65+
],
4366
role: 'info',
4467
editType: 'plot',
4568
description: [
4669
'Array defining the higher bound for each color component.',
47-
'For example, for the `rgba` colormodel, the default value is [255, 255, 255, 1].'
48-
].join(' ')
70+
'Note that the default value will depend on the colormodel.'
71+
].concat(zmaxDesc).join(' ')
4972
},
5073
x0: {
5174
valType: 'number',

src/traces/image/calc.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
'use strict';
1010

11-
// var Registry = require('../../registry');
12-
// var Lib = require('../../lib');
1311
var Axes = require('../../plots/cartesian/axes');
1412

1513
module.exports = function calc(gd, trace) {

src/traces/image/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
1818
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
1919
}
2020
var z = coerce('z');
21-
if(z === undefined || !z.length) {
21+
if(z === undefined || !z.length || !z[0] || !z[0].length) {
2222
traceOut.visible = false;
2323
return;
2424
}

src/traces/image/hover.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ var Fx = require('../../components/fx');
1212
var Lib = require('../../lib');
1313
var constants = require('./constants');
1414

15-
// var Axes = require('../../plots/cartesian/axes');
16-
1715
module.exports = function hoverPoints(pointData, xval, yval) {
1816
var cd0 = pointData.cd[0];
1917
var trace = cd0.trace;
@@ -26,7 +24,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
2624
return;
2725
}
2826

29-
// Find nearest pixel's index and pixel center
27+
// Find nearest pixel's index
3028
var nx = Math.floor((xval - cd0.x0) / trace.dx);
3129
var ny = Math.floor(Math.abs(yval - cd0.y0) / trace.dy);
3230

@@ -49,7 +47,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
4947
if(dims === 4) colorstring.push(', ' + c[3] + s[3]);
5048
colorstring.push(']');
5149
colorstring = colorstring.join('');
52-
pointData.extraText = '<span style="text-transform:uppercase">' + colormodel + '</span>: ' + colorstring;
50+
pointData.extraText = colormodel.toUpperCase() + ': ' + colorstring;
5351
}
5452

5553
var py = ya.c2p(cd0.y0 + (ny + 0.5) * trace.dy);

src/traces/image/plot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var constants = require('./constants');
1515
module.exports = {};
1616

1717
// Generate a function to scale color components according to zmin/zmax and the colormodel
18-
module.exports.scaler = function(trace) {
18+
var scaler = function(trace) {
1919
var colormodel = trace.colormodel;
2020
var n = colormodel.length;
2121
var cr = constants.colormodel[colormodel];
@@ -114,7 +114,7 @@ module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
114114
var ipx = function(i) {return Lib.constrain(Math.round(xa.c2p(x0 + i * dx) - left), 0, imageWidth);};
115115
var jpx = function(j) {return Lib.constrain(Math.round(ya.c2p(y0 + j * dy) - top), 0, imageHeight);};
116116

117-
trace._scaler = module.exports.scaler(trace);
117+
trace._scaler = scaler(trace);
118118
var fmt = constants.colormodel[trace.colormodel].fmt;
119119
var c;
120120
for(var i = 0; i < cd0.w; i++) {

test/jasmine/tests/image_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describe('image hover:', function() {
298298
.then(function() {_hover(205, 125);})
299299
.then(function() {
300300
assertHoverLabelContent({
301-
nums: 'x: 25.5\ny: 14.5\nz: [54, 136, 153]\n<tspan style="text-transform:uppercase">rgb</tspan>: [54, 136, 153]',
301+
nums: 'x: 25.5\ny: 14.5\nz: [54, 136, 153]\nRGB: [54, 136, 153]',
302302
name: ''
303303
});
304304
})
@@ -312,7 +312,7 @@ describe('image hover:', function() {
312312
.then(function() {_hover(255, 295);})
313313
.then(function() {
314314
assertHoverLabelContent({
315-
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">rgba</tspan>: [128, 77, 54, 1]',
315+
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\nRGBA: [128, 77, 54, 1]',
316316
name: ''
317317
});
318318
})
@@ -327,7 +327,7 @@ describe('image hover:', function() {
327327
.then(function() {_hover(255, 295);})
328328
.then(function() {
329329
assertHoverLabelContent({
330-
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54]\n<tspan style="text-transform:uppercase">hsl</tspan>: [128°, 77%, 54%]',
330+
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54]\nHSL: [128°, 77%, 54%]',
331331
name: ''
332332
});
333333
})
@@ -342,7 +342,7 @@ describe('image hover:', function() {
342342
.then(function() {_hover(255, 295);})
343343
.then(function() {
344344
assertHoverLabelContent({
345-
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">hsla</tspan>: [128°, 77%, 54%, 1]',
345+
nums: 'x: 31.5\ny: 35.5\nz: [128, 77, 54, 254]\nHSLA: [128°, 77%, 54%, 1]',
346346
name: ''
347347
});
348348
})

0 commit comments

Comments
 (0)