|
9 | 9 |
|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 |
| -var Axes = require('../../plots/cartesian/axes'); |
13 |
| -var extendFlat = require('../../lib').extendFlat; |
14 | 12 | var heatmapCalc = require('../heatmap/calc');
|
15 |
| - |
| 13 | +var setContours = require('./set_contours'); |
16 | 14 |
|
17 | 15 | // most is the same as heatmap calc, then adjust it
|
18 | 16 | // though a few things inside heatmap calc still look for
|
19 | 17 | // contour maps, because the makeBoundArray calls are too entangled
|
20 | 18 | module.exports = function calc(gd, trace) {
|
21 |
| - var cd = heatmapCalc(gd, trace), |
22 |
| - contours = trace.contours; |
23 |
| - |
24 |
| - // check if we need to auto-choose contour levels |
25 |
| - if(trace.autocontour !== false) { |
26 |
| - var dummyAx = autoContours(trace.zmin, trace.zmax, trace.ncontours); |
27 |
| - |
28 |
| - contours.size = dummyAx.dtick; |
29 |
| - |
30 |
| - contours.start = Axes.tickFirst(dummyAx); |
31 |
| - dummyAx.range.reverse(); |
32 |
| - contours.end = Axes.tickFirst(dummyAx); |
33 |
| - |
34 |
| - if(contours.start === trace.zmin) contours.start += contours.size; |
35 |
| - if(contours.end === trace.zmax) contours.end -= contours.size; |
36 |
| - |
37 |
| - // if you set a small ncontours, *and* the ends are exactly on zmin/zmax |
38 |
| - // there's an edge case where start > end now. Make sure there's at least |
39 |
| - // one meaningful contour, put it midway between the crossed values |
40 |
| - if(contours.start > contours.end) { |
41 |
| - contours.start = contours.end = (contours.start + contours.end) / 2; |
42 |
| - } |
43 |
| - |
44 |
| - // copy auto-contour info back to the source data. |
45 |
| - // previously we copied the whole contours object back, but that had |
46 |
| - // other info (coloring, showlines) that should be left to supplyDefaults |
47 |
| - if(!trace._input.contours) trace._input.contours = {}; |
48 |
| - extendFlat(trace._input.contours, { |
49 |
| - start: contours.start, |
50 |
| - end: contours.end, |
51 |
| - size: contours.size |
52 |
| - }); |
53 |
| - trace._input.autocontour = true; |
54 |
| - } |
55 |
| - else { |
56 |
| - // sanity checks on manually-supplied start/end/size |
57 |
| - var start = contours.start, |
58 |
| - end = contours.end, |
59 |
| - inputContours = trace._input.contours; |
60 |
| - |
61 |
| - if(start > end) { |
62 |
| - contours.start = inputContours.start = end; |
63 |
| - end = contours.end = inputContours.end = start; |
64 |
| - start = contours.start; |
65 |
| - } |
66 |
| - |
67 |
| - if(!(contours.size > 0)) { |
68 |
| - var sizeOut; |
69 |
| - if(start === end) sizeOut = 1; |
70 |
| - else sizeOut = autoContours(start, end, trace.ncontours).dtick; |
71 |
| - |
72 |
| - inputContours.size = contours.size = sizeOut; |
73 |
| - } |
74 |
| - } |
75 |
| - |
| 19 | + var cd = heatmapCalc(gd, trace); |
| 20 | + setContours(trace); |
76 | 21 | return cd;
|
77 | 22 | };
|
78 |
| - |
79 |
| -/* |
80 |
| - * autoContours: make a dummy axis object with dtick we can use |
81 |
| - * as contours.size, and if needed we can use Axes.tickFirst |
82 |
| - * with this axis object to calculate the start and end too |
83 |
| - * |
84 |
| - * start: the value to start the contours at |
85 |
| - * end: the value to end at (must be > start) |
86 |
| - * ncontours: max number of contours to make, like roughDTick |
87 |
| - * |
88 |
| - * returns: an axis object |
89 |
| - */ |
90 |
| -function autoContours(start, end, ncontours) { |
91 |
| - var dummyAx = { |
92 |
| - type: 'linear', |
93 |
| - range: [start, end] |
94 |
| - }; |
95 |
| - |
96 |
| - Axes.autoTicks( |
97 |
| - dummyAx, |
98 |
| - (end - start) / (ncontours || 15) |
99 |
| - ); |
100 |
| - |
101 |
| - return dummyAx; |
102 |
| -} |
0 commit comments