Skip to content

Commit 10d5558

Browse files
committed
declare new text font styling attributes
1 parent 5142be6 commit 10d5558

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

src/components/drawing/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,32 @@ drawing.font = function(s, font) {
4646
if(style) s.style('font-style', style);
4747
if(variant) s.style('font-variant', variant);
4848

49+
if(capitalize) s.style('text-transform', capitalize2transform(capitalize));
4950
if(shadow) s.style('text-shadow', shadow === 'auto' ? svgTextUtils.makeTextShadow(Color.contrast(color)) : shadow);
50-
if(striding) s.style('text-decoration-line', striding);
51-
if(capitalize) s.style('text-transform', capitalize === 'word' ? 'capitalize' : capitalize);
51+
if(striding) s.style('text-decoration-line', striding2decorationLine(striding));
5252
};
5353

54+
function capitalize2transform(capitalize) {
55+
return (
56+
capitalize === 'word' ?
57+
'capitalize' :
58+
capitalize
59+
);
60+
}
61+
drawing.capitalize2transform = capitalize2transform;
62+
63+
function striding2decorationLine(striding) {
64+
return (
65+
striding
66+
.replace('under', 'underline')
67+
.replace('over', 'overline')
68+
.replace('through', 'line-through')
69+
.split('+')
70+
.join(' ')
71+
);
72+
}
73+
drawing.striding2decorationLine = striding2decorationLine;
74+
5475
/*
5576
* Positioning helpers
5677
* Note: do not use `setPosition` with <text> nodes modified by

src/plots/font_attributes.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,43 @@ module.exports = function(opts) {
8686
].join(' ')
8787
},
8888

89+
capitalize: opts.noFontCapitalize ? undefined : {
90+
editType: editType,
91+
valType: 'enumerated',
92+
values: ['none', 'word', 'uppercase', 'lowercase'],
93+
dflt: 'none',
94+
description: [
95+
'Sets capitalization of text.',
96+
'It can be used to make text appear in all-uppercase or all-lowercase,',
97+
'or with each word capitalized.'
98+
].join(' ')
99+
},
100+
101+
striding: opts.noFontStriding ? undefined : {
102+
editType: editType,
103+
valType: 'flaglist',
104+
flags: ['under', 'over', 'through'],
105+
extras: ['none'],
106+
dflt: 'none',
107+
description: [
108+
'Sets the kind of decoration line(s) with text,',
109+
'such as an *under*, *over* or *through*',
110+
'as well as combinations e.g. *under+over*, etc.'
111+
].join(' ')
112+
},
113+
114+
shadow: opts.noFontCapitalize ? undefined : {
115+
editType: editType,
116+
valType: 'string',
117+
dflt: 'none',
118+
extras: ['auto'],
119+
description: [
120+
'Sets the shape and color of the shadow behind text.',
121+
'See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow.',
122+
'*auto* places minimal shadow and applies contrast text font color.'
123+
].join(' ')
124+
},
125+
89126
editType: editType,
90127
// blank strings so compress_attributes can remove
91128
// TODO - that's uber hacky... better solution?

0 commit comments

Comments
 (0)