Skip to content

Commit 27f8cfe

Browse files
committed
use axis formatting for contour labels
yeah, this needs major refactoring to be more useful for cases like this
1 parent d518c83 commit 27f8cfe

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/traces/contour/plot.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var d3 = require('d3');
1414
var Lib = require('../../lib');
1515
var Drawing = require('../../components/drawing');
1616
var svgTextUtils = require('../../lib/svg_text_utils');
17+
var Axes = require('../../plots/cartesian/axes');
18+
var setConvert = require('../../plots/cartesian/set_convert');
1719

1820
var heatmapPlot = require('../heatmap/plot');
1921
var makeCrossings = require('./make_crossings');
@@ -345,18 +347,27 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
345347
contourFormat = d3.format(contours.labelformat);
346348
}
347349
else {
348-
// round to 2 digits past magnitude of contours.size,
349-
// then remove trailing zeroes
350-
var valRound = 2 - Math.floor(Math.log(contours.size) / Math.LN10 + 0.01);
351-
if(valRound <= 0) {
352-
contourFormat = function(v) { return v.toFixed(); };
350+
var formatAxis;
351+
if(cd0.t.cb) {
352+
formatAxis = cd0.t.cb.axis;
353353
}
354354
else {
355-
contourFormat = function(v) {
356-
var valStr = v.toFixed(valRound);
357-
return valStr.replace(TRAILING_ZEROS, '');
355+
formatAxis = {
356+
type: 'linear',
357+
_separators: '.,',
358+
_id: 'ycontour',
359+
nticks: pathinfo.length,
360+
showexponent: 'all',
361+
range: [contours.start, contours.end]
358362
};
363+
setConvert(formatAxis, gd._fullLayout);
364+
Axes.calcTicks(formatAxis);
365+
formatAxis._tmin = null;
366+
formatAxis._tmax = null;
359367
}
368+
contourFormat = function(v) {
369+
return Axes.tickText(formatAxis, v).text;
370+
};
360371
}
361372

362373
var dummyText = defs.append('text')

0 commit comments

Comments
 (0)