Skip to content

Commit 3a4d428

Browse files
committed
add parcoords labelside (top|bottom) help display tilted labels with no conflict with the title
1 parent 9cbbcbf commit 3a4d428

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

src/traces/parcoords/attributes.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@ module.exports = {
2222
labelangle: {
2323
valType: 'angle',
2424
dflt: 0,
25-
role: 'style',
25+
role: 'info',
2626
editType: 'plot',
2727
description: [
2828
'Sets the angle of the labels with respect to the horizontal.',
29-
'For example, a `tickangle` of -90 draws the labels vertically.'
29+
'For example, a `tickangle` of -90 draws the labels vertically.',
30+
'Tilted labels with *labelangle* may be positioned better',
31+
'inside margins when `labelposition` is set to *bottom*.'
32+
].join(' ')
33+
},
34+
35+
labelside: {
36+
valType: 'enumerated',
37+
role: 'info',
38+
values: ['top', 'bottom'],
39+
dflt: 'top',
40+
editType: 'plot',
41+
description: [
42+
'Specifies the location of the `label`.',
43+
'*top* positions labels above, next to the title',
44+
'*bottom* positions labels below the graph',
45+
'Tilted labels with *labelangle* may be positioned better',
46+
'inside margins when `labelposition` is set to *bottom*.'
3047
].join(' ')
3148
},
3249

src/traces/parcoords/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
102102
Lib.coerceFont(coerce, 'rangefont', fontDflt);
103103

104104
coerce('labelangle');
105+
coerce('labelside');
105106
};

src/traces/parcoords/parcoords.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function model(layout, d, i) {
148148
var dimensions = trace.dimensions;
149149
var width = layout.width;
150150
var labelAngle = trace.labelangle;
151+
var labelSide = trace.labelside;
151152
var labelFont = trace.labelfont;
152153
var tickFont = trace.tickfont;
153154
var rangeFont = trace.rangefont;
@@ -177,6 +178,7 @@ function model(layout, d, i) {
177178
unitToColor: unitToColorScale(cscale),
178179
lines: lines,
179180
labelAngle: labelAngle,
181+
labelSide: labelSide,
180182
labelFont: labelFont,
181183
tickFont: tickFont,
182184
rangeFont: rangeFont,
@@ -347,11 +349,13 @@ function parcoordsInteractionState() {
347349
};
348350
}
349351

350-
function calcTilt(angle) {
352+
function calcTilt(angle, position) {
353+
var dir = (position === 'top') ? 1 : -1;
351354
var radians = angle * Math.PI / 180;
352355
var dx = Math.sin(radians);
353356
var dy = Math.cos(radians);
354357
return {
358+
dir: dir,
355359
dx: dx,
356360
dy: dy,
357361
degrees: angle
@@ -634,19 +638,21 @@ module.exports = function(gd, svg, parcoordsLineLayers, cdModule, layout, callba
634638
svgTextUtils.convertToTspans(e, gd);
635639
})
636640
.attr('transform', function(d) {
637-
var tilt = calcTilt(d.model.labelAngle);
641+
var tilt = calcTilt(d.model.labelAngle, d.model.labelSide);
638642
var r = c.axisTitleOffset;
639643
return (
644+
(tilt.dir > 0 ? '' : 'translate(0,' + (2 * r + d.model.height) + ')') +
640645
'rotate(' + tilt.degrees + ')' +
641-
'translate(' + -r * tilt.dx + ',' + -r * tilt.dy + ')'
646+
'translate(' + (-r * tilt.dx) + ',' + (-r * tilt.dy) + ')'
642647
);
643648
})
644649
.attr('text-anchor', function(d) {
645-
var tilt = calcTilt(d.model.labelAngle);
650+
var tilt = calcTilt(d.model.labelAngle, d.model.labelSide);
646651
var adx = Math.abs(tilt.dx);
647652
var ady = Math.abs(tilt.dy);
653+
648654
if(2 * adx > ady) {
649-
return (tilt.dx < 0) ? 'start' : 'end';
655+
return (tilt.dir * tilt.dx < 0) ? 'start' : 'end';
650656
} else {
651657
return 'middle';
652658
}
19.2 KB
Loading
-63 Bytes
Loading

test/image/mocks/gl2d_parcoords_60_dims.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"type": "parcoords",
55
"labelangle": -45,
6+
"labelside": "bottom",
67
"dimensions": [
78
{
89
"label": "one",
@@ -1606,10 +1607,6 @@
16061607
"height": 500,
16071608
"title": {
16081609
"text": "60 dimensions"
1609-
},
1610-
"margin": {
1611-
"t": 200,
1612-
"b": 25
16131610
}
16141611
}
16151612
}

test/image/mocks/gl2d_parcoords_tick_format.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"type": "parcoords",
55
"labelangle": -90,
6+
"labelside": "bottom",
67
"dimensions": [
78
{
89
"label": "Apples",
@@ -35,10 +36,6 @@
3536
"height": 400,
3637
"title": {
3738
"text": "<sup>Tick formatting and <i><b>labelangle</b></i></sup>"
38-
},
39-
"margin": {
40-
"t": 150,
41-
"b": 25
4239
}
4340
}
4441
}

0 commit comments

Comments
 (0)