Skip to content

Commit 505614d

Browse files
committed
parcoords fonts
1 parent 5e7eaaf commit 505614d

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/traces/parcoords/attributes.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ var colorAttributes = require('../../components/colorscale/color_attributes');
1212
var colorbarAttrs = require('../../components/colorbar/attributes');
1313
var colorscales = require('../../components/colorscale/scales');
1414
var axesAttrs = require('../../plots/cartesian/layout_attributes');
15+
var fontAttrs = require('../../plots/font_attributes');
1516

1617
var extendDeep = require('../../lib/extend').extendDeep;
1718
var extendFlat = require('../../lib/extend').extendFlat;
1819

20+
1921
module.exports = {
2022

2123
domain: {
@@ -47,6 +49,10 @@ module.exports = {
4749
}
4850
},
4951

52+
labelfont: extendFlat({}, fontAttrs, {description: 'Sets the font for the `dimension` labels.'}),
53+
tickfont: extendFlat({}, fontAttrs, {description: 'Sets the font for the `dimension` tick values.'}),
54+
rangefont: extendFlat({}, fontAttrs, {description: 'Sets the font for the `dimension` range values.'}),
55+
5056
dimensions: {
5157
_isLinkedToArray: 'dimension',
5258
label: {

src/traces/parcoords/defaults.js

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ function dimensionsDefaults(traceIn, traceOut) {
8181
return dimensionsOut;
8282
}
8383

84+
function coerceFont(fontAttr, coerce, defaultFont) {
85+
var fontSpec = Lib.coerceFont(coerce, fontAttr);
86+
Lib.coerceFont(coerce, fontAttr, Lib.extendFlat({}, defaultFont, fontSpec));
87+
}
8488

8589
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
8690
function coerce(attr, dflt) {
@@ -97,4 +101,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
97101
if(!Array.isArray(dimensions) || !dimensions.length) {
98102
traceOut.visible = false;
99103
}
104+
105+
coerceFont('labelfont', coerce, layout.font);
106+
coerceFont('tickfont', coerce, layout.font);
107+
coerceFont('rangefont', coerce, layout.font);
100108
};

src/traces/parcoords/parcoords.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var lineLayerMaker = require('./lines');
1212
var c = require('./constants');
1313
var Lib = require('../../lib');
1414
var d3 = require('d3');
15+
var Drawing = require('../../components/drawing');
1516

1617

1718
function keyFun(d) {return d.key;}
@@ -122,7 +123,10 @@ function model(layout, d, i) {
122123
line = trace.line,
123124
domain = trace.domain,
124125
dimensions = trace.dimensions,
125-
width = layout.width;
126+
width = layout.width,
127+
labelFont = trace.labelfont,
128+
tickFont = trace.tickfont,
129+
rangeFont = trace.rangefont;
126130

127131
var lines = Lib.extendDeep({}, line, {
128132
color: lineColor.map(domainToUnitScale({values: lineColor, range: [line.cmin, line.cmax]})),
@@ -144,6 +148,9 @@ function model(layout, d, i) {
144148
tickDistance: c.tickDistance,
145149
unitToColor: unitToColorScale(cscale),
146150
lines: lines,
151+
labelFont: labelFont,
152+
tickFont: tickFont,
153+
rangeFont: rangeFont,
147154
translateX: domain.x[0] * width,
148155
translateY: layout.height - domain.y[1] * layout.height,
149156
pad: pad,
@@ -227,8 +234,6 @@ function styleExtentTexts(selection) {
227234
selection
228235
.classed('axisExtentText', true)
229236
.attr('text-anchor', 'middle')
230-
.style('font-weight', 100)
231-
.style('font-size', '10px')
232237
.style('cursor', 'default')
233238
.style('user-select', 'none');
234239
}
@@ -545,6 +550,7 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
545550
var scale = d.domainScale;
546551
var sdom = scale.domain();
547552
var texts = d.ticktext;
553+
Drawing.font(axis, d.model.tickFont)
548554
d3.select(this)
549555
.call(d3.svg.axis()
550556
.orient('left')
@@ -567,8 +573,6 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
567573

568574
axis
569575
.selectAll('text')
570-
.style('font-weight', 100)
571-
.style('font-size', '10px')
572576
.style('fill', 'black')
573577
.style('fill-opacity', 1)
574578
.style('stroke', 'none')
@@ -590,15 +594,14 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
590594
.append('text')
591595
.classed('axisTitle', true)
592596
.attr('text-anchor', 'middle')
593-
.style('font-family', 'sans-serif')
594-
.style('font-size', '10px')
595597
.style('cursor', 'ew-resize')
596598
.style('user-select', 'none')
597599
.style('pointer-events', 'auto');
598600

599601
axisTitle
600602
.attr('transform', 'translate(0,' + -c.axisTitleOffset + ')')
601-
.text(function(d) {return d.label;});
603+
.text(function(d) {return d.label;})
604+
.each(function(d) {Drawing.font(axisTitle, d.model.labelFont);});
602605

603606
var axisExtent = axisOverlays.selectAll('.axisExtent')
604607
.data(repeat, keyFun);
@@ -631,7 +634,8 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
631634
.call(styleExtentTexts);
632635

633636
axisExtentTopText
634-
.text(function(d) {return formatExtreme(d)(d.domainScale.domain().slice(-1)[0]);});
637+
.text(function(d) {return formatExtreme(d)(d.domainScale.domain().slice(-1)[0]);})
638+
.each(function(d) {Drawing.font(axisExtentTopText, d.model.rangeFont);});
635639

636640
var axisExtentBottom = axisExtent.selectAll('.axisExtentBottom')
637641
.data(repeat, keyFun);
@@ -653,7 +657,8 @@ module.exports = function(root, svg, styledData, layout, callbacks) {
653657
.call(styleExtentTexts);
654658

655659
axisExtentBottomText
656-
.text(function(d) {return formatExtreme(d)(d.domainScale.domain()[0]);});
660+
.text(function(d) {return formatExtreme(d)(d.domainScale.domain()[0]);})
661+
.each(function(d) {Drawing.font(axisExtentBottomText, d.model.rangeFont);});
657662

658663
var axisBrush = axisOverlays.selectAll('.axisBrush')
659664
.data(repeat, keyFun);

0 commit comments

Comments
 (0)