Skip to content

Commit d6abde9

Browse files
committed
improve new image mock and refactor scale function in calc
1 parent d4fec74 commit d6abde9

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

src/traces/image/calc.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ module.exports = function calc(gd, trace) {
4343
return [cd0];
4444
};
4545

46-
function scale(zero, factor, min, max) {
46+
function scale(zero, ratio, min, max) {
4747
return function(c) {
48-
c = (c - zero) * factor;
49-
c = Lib.constrain(c, min, max);
50-
return c;
48+
return Lib.constrain((c - zero) * ratio, min, max);
5149
};
5250
}
5351

12.4 KB
Loading

test/image/mocks/image_non_numeric.json

+82-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,91 @@
44
"hoverinfo": "all",
55
"z": [
66
[
7-
[true, true, true],
8-
[false, false, false]
7+
[255, 0, 0],
8+
[191, 0, 0],
9+
[127, 0, 0]
10+
],
11+
[
12+
[0, 255, 0],
13+
[0, 191, 0],
14+
[0, 127, 0]
15+
],
16+
[
17+
[0, 0, 255],
18+
[0, 0, 191],
19+
[0, 0, 127]
20+
]
21+
]
22+
}, {
23+
"yaxis": "y2",
24+
"xaxis": "x2",
25+
"type": "image",
26+
"hoverinfo": "all",
27+
"z": [
28+
[
29+
[255, 0, 0],
30+
[191, 0, null],
31+
[127, 0, 0]
32+
],
33+
[
34+
[0, 255, 0],
35+
[false, 191, 0],
36+
[0, 127, 0]
37+
],
38+
[
39+
[0, 0, 255],
40+
[0, true, 191],
41+
[0, 0, 127]
42+
]
43+
]
44+
}, {
45+
"yaxis": "y3",
46+
"xaxis": "x3",
47+
"type": "image",
48+
"hoverinfo": "all",
49+
"z": [
50+
[
51+
[255, 0, 0],
52+
[191, 0, 0],
53+
[-10000, 0, 0]
54+
],
55+
[
56+
[0, 255, 0],
57+
[0, "", 0],
58+
[0, 127, 0]
59+
],
60+
[
61+
[0, 0, 10000],
62+
[0, 0, 191],
63+
[0, 0, 127]
964
]
1065
]
66+
}, {
67+
"yaxis": "y4",
68+
"xaxis": "x4",
69+
"type": "image",
70+
"hoverinfo": "all",
71+
"z": [
72+
[
73+
[255, 0],
74+
[191, 0, null],
75+
[127, 0, ""]
76+
],
77+
[
78+
[true, 255, 0],
79+
[false, 191, 0],
80+
["text", 127, 0]
81+
],
82+
[]
83+
]
1184
}],
1285
"layout": {
13-
"width": 400,
14-
"height": 400
86+
"width": 600,
87+
"height": 600,
88+
"grid": {
89+
"rows": 2,
90+
"columns": 2,
91+
"pattern": "independent"
92+
}
1593
}
1694
}

0 commit comments

Comments
 (0)