Skip to content

Commit ebf57f0

Browse files
committed
apply per dimension tickformat in linear axes ticktext
1 parent 407d72a commit ebf57f0

12 files changed

+24
-22
lines changed

src/traces/parcoords/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969
dflt: '3s',
7070
role: 'style',
7171
editType: 'plot',
72-
description: [ // TODO: should update this description?
72+
description: [
7373
'Sets the tick label formatting rule using d3 formatting mini-language',
7474
'which is similar to those of Python. See',
7575
'https://github.com/d3/d3-format/blob/master/README.md#locale_format'

src/traces/parcoords/parcoords.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var d3 = require('d3');
1212
var rgba = require('color-rgba');
1313

14+
var Axes = require('../../plots/cartesian/axes');
1415
var Lib = require('../../lib');
1516
var svgTextUtils = require('../../lib/svg_text_utils');
1617
var Drawing = require('../../components/drawing');
@@ -25,17 +26,6 @@ var c = require('./constants');
2526
var brush = require('./axisbrush');
2627
var lineLayerMaker = require('./lines');
2728

28-
var tickText = require('../../plots/cartesian/axes').tickText;
29-
var parcoordsLayout;
30-
31-
function linearFormat(v) {
32-
return tickText(
33-
parcoordsLayout.linearAxis,
34-
parcoordsLayout.linearAxis.d2l(v),
35-
true
36-
).text;
37-
}
38-
3929
function visible(dimension) { return !('visible' in dimension) || dimension.visible; }
4030

4131
function dimensionExtent(dimension) {
@@ -364,7 +354,21 @@ function calcTilt(angle) {
364354
module.exports = function(gd, svg, parcoordsLineLayers, cdModule, layout, callbacks) {
365355
var state = parcoordsInteractionState();
366356

367-
parcoordsLayout = layout;
357+
var fullLayout = gd._fullLayout;
358+
359+
// mock one linear axes for tick formatting
360+
var linearAxis = { type: 'linear', showexponent: 'all', exponentformat: 'B' };
361+
Axes.setConvert(linearAxis, fullLayout);
362+
363+
function linearFormat(v, tickformat) {
364+
linearAxis.tickformat = tickformat;
365+
366+
return Axes.tickText(
367+
linearAxis,
368+
linearAxis.d2l(v),
369+
true
370+
).text;
371+
}
368372

369373
var vm = cdModule
370374
.filter(function(d) { return unwrap(d).trace.visible; })
@@ -579,7 +583,9 @@ module.exports = function(gd, svg, parcoordsLineLayers, cdModule, layout, callba
579583
.tickValues(d.ordinal ? // and this works for ordinal scales
580584
sdom :
581585
null)
582-
.tickFormat(d.ordinal ? function(d) { return d; } : function(d) { return linearFormat(d); })
586+
.tickFormat(function(v) {
587+
return d.ordinal ? v : linearFormat(v, d.tickFormat);
588+
})
583589
.scale(scale));
584590
Drawing.font(axis.selectAll('text'), d.model.tickFont);
585591
});
@@ -663,7 +669,7 @@ module.exports = function(gd, svg, parcoordsLineLayers, cdModule, layout, callba
663669
if(d.ordinal) return '';
664670
var domain = d.domainScale.domain();
665671
var v = (domain[isTop ? domain.length - 1 : 0]);
666-
return linearFormat(v);
672+
return linearFormat(v, d.tickFormat);
667673
}
668674

669675
axisExtentTopText.enter()

src/traces/parcoords/plot.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var parcoords = require('./parcoords');
1212
var prepareRegl = require('../../lib/prepare_regl');
13-
var setConvert = require('../../plots/cartesian/axes').setConvert;
1413

1514
module.exports = function plot(gd, cdModule) {
1615
var fullLayout = gd._fullLayout;
@@ -20,10 +19,6 @@ module.exports = function plot(gd, cdModule) {
2019
var success = prepareRegl(gd);
2120
if(!success) return;
2221

23-
// mock linear and category axes for tick formatting
24-
var linearAxis = { type: 'linear', showexponent: 'all', exponentformat: 'B' };
25-
setConvert(linearAxis, fullLayout);
26-
2722
var gdDimensions = {};
2823
var gdDimensionsOriginalOrder = {};
2924
var fullIndices = {};
@@ -151,8 +146,7 @@ module.exports = function plot(gd, cdModule) {
151146
r: size.r,
152147
b: size.b,
153148
l: size.l
154-
},
155-
linearAxis: linearAxis
149+
}
156150
},
157151
{ // callbacks
158152
filterChanged: filterChanged,
-269 Bytes
Loading
Loading
866 Bytes
Loading
495 Bytes
Loading
-811 Bytes
Loading
Loading
Loading
Loading

test/image/mocks/gl2d_parcoords_tick_format.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
]
1313
},
1414
{
15+
"tickformat": ".3f",
1516
"label": "Bananas",
1617
"values": [
1718
-0.99999,
1819
0.99999
1920
]
2021
},
2122
{
23+
"tickformat": ".6s",
2224
"label": "Cherries",
2325
"values": [
2426
-0.99999,

0 commit comments

Comments
 (0)