Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "bold" weight, "italic" style and "small-caps" variant to fonts #6956

Merged
merged 102 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
351b98f
add weight, style, stretch and variant to font
archmoj Apr 11, 2024
fe1acac
bar
archmoj Apr 11, 2024
c278383
carpet
archmoj Apr 11, 2024
0e6a833
contour
archmoj Apr 11, 2024
cc6308d
heatmap
archmoj Apr 11, 2024
eddbda1
indicator
archmoj Apr 11, 2024
9e0ff17
parcats
archmoj Apr 11, 2024
666b10e
parcoords
archmoj Apr 11, 2024
08041dc
pie
archmoj Apr 11, 2024
4ff859f
sankey
archmoj Apr 11, 2024
acc71b2
scatter
archmoj Apr 11, 2024
f13d7b2
scattergl
archmoj Apr 11, 2024
9a6f9c2
sunburst
archmoj Apr 11, 2024
55ba43b
table
archmoj Apr 11, 2024
f4bc74e
scatter3d
archmoj Apr 11, 2024
2c39a8e
scattermapbox
archmoj Apr 11, 2024
caad472
annotations
archmoj Apr 11, 2024
34f3d48
colorbar
archmoj Apr 11, 2024
948689e
legend
archmoj Apr 11, 2024
cf56d6e
titles
archmoj Apr 11, 2024
2f8b4ed
hover effects
archmoj Apr 11, 2024
d1e041b
plots
archmoj Apr 11, 2024
151ebb0
cartesian
archmoj Apr 11, 2024
6f0ecfa
polar
archmoj Apr 11, 2024
9859bf0
ternary
archmoj Apr 11, 2024
1bbe369
gl3d
archmoj Apr 11, 2024
9760db0
gl-text fix for handling styles
archmoj Apr 11, 2024
a29adb1
new schema
archmoj Apr 10, 2024
9caa963
add and adjust jasmine tests
archmoj Apr 11, 2024
75ef984
style waterfall_profit-loss_2018vs2019_textinfo_base
archmoj Apr 11, 2024
446a549
style heatmap_xyz-gaps-on-sides
archmoj Apr 11, 2024
3892130
style gl2d_text_chart_arrays
archmoj Apr 11, 2024
83f9408
style text_chart_arrays
archmoj Apr 11, 2024
8d84ea7
style text_on_shapes_basic
archmoj Apr 11, 2024
62bf5a2
style bar_annotation_max_range_eq_category
archmoj Apr 11, 2024
e000763
style texttemplate_scatter
archmoj Apr 11, 2024
2498045
style texttemplate
archmoj Apr 11, 2024
bdb24cf
fix typo in src/components/fx/hover.js
archmoj Apr 14, 2024
6095b93
add extras option to integer in lib.coerce
archmoj Apr 14, 2024
28087ee
declare weight as integer
archmoj Apr 14, 2024
e75001d
update schema
archmoj Apr 14, 2024
7d3facf
adjust bar
archmoj Apr 14, 2024
dfd6a2e
fix src/traces/sunburst/fx.js
archmoj Apr 14, 2024
2d7ba1d
use Lib.coerceFont in indicator
archmoj Apr 14, 2024
238b7dc
style test/image/mocks/indicator_attrs
archmoj Apr 14, 2024
44fb6a4
style indicator_bullet
archmoj Apr 14, 2024
6409b5e
style gl2d_parcoords_constraints
archmoj Apr 14, 2024
104d7fe
style parcats_basic_freeform
archmoj Apr 14, 2024
c9fc006
style scattercarpet-text
archmoj Apr 14, 2024
d8a59f9
use layout.font in carpet/defaults.js
archmoj Apr 14, 2024
5bbcd5d
style funnelarea_with_other_traces
archmoj Apr 14, 2024
7154f5e
style treemap_fonts_nocolor
archmoj Apr 14, 2024
e92e930
style sankey_energy
archmoj Apr 14, 2024
ba372e0
style trace_metatext
archmoj Apr 14, 2024
96f8166
style parcats
archmoj Apr 14, 2024
68a0f66
fix indicator guage.axis default font
archmoj Apr 14, 2024
e0f9811
Revert "scattermapbox"
archmoj Apr 14, 2024
3631d1a
no support in scattermapbox
archmoj Apr 14, 2024
6e367d6
add font style options to gl-axes3d
archmoj Apr 15, 2024
7aae57b
update trace_metatext
archmoj Apr 15, 2024
dfe5670
handle font styles in gl-scatter3d
archmoj Apr 15, 2024
f92ff86
style gl3d_scatter3d-blank-text
archmoj Apr 15, 2024
eb82700
handle styles in gl-plot2d and text-cache
archmoj Apr 15, 2024
ff56034
style gl2d_heatmapgl
archmoj Apr 15, 2024
888bf20
revise font.stretch options
archmoj Apr 15, 2024
dd81225
correct oblique options
archmoj Apr 15, 2024
3829ca9
drop oblique angle options that are quite confusing
archmoj Apr 15, 2024
50b8ccd
remove stretch from src
archmoj Apr 17, 2024
31e04de
remove stretch from test
archmoj Apr 17, 2024
673b33e
update schema diff
archmoj Apr 17, 2024
1097e34
remove stretch in gl-axes3d gl-plot2d and text-cache
archmoj Apr 17, 2024
369c95d
adjust toimage_test
archmoj Apr 17, 2024
c90f098
add descriptions
archmoj Apr 17, 2024
a877179
fix hover
archmoj Apr 17, 2024
cc28647
use layout.font styling defaults in hover
archmoj Apr 17, 2024
dfde4b1
make arrayOk styling attributes
archmoj Apr 18, 2024
3a624ab
revise variant options
archmoj Apr 18, 2024
a03ec91
image test for font-variants
archmoj Apr 18, 2024
1a6fc90
keep working options in test
archmoj Apr 18, 2024
d0c583c
revise new attributes
archmoj Apr 18, 2024
062c862
new tests
archmoj Apr 19, 2024
593717b
update link to gl-scatter3d
archmoj Apr 19, 2024
accb7b7
handle array font family, weight, style & variant in gl-scatter3d
archmoj Apr 19, 2024
a040564
skip font-variant-bar in mock test
archmoj Apr 19, 2024
9a92474
update package-lock.json
archmoj Apr 22, 2024
1c02804
test font options in scattergl and scatter3d
archmoj Apr 22, 2024
2fdb90c
revise font options
archmoj Apr 22, 2024
8452e53
limit variant options for scattergl and scatter3d - arrayOk scatter3d…
archmoj Apr 22, 2024
b8877ff
add bold and italic to scattermapbox
archmoj Apr 22, 2024
f4d4f4c
no integer weight
archmoj Apr 22, 2024
82b9181
do not include font styling options in svg when set to normal
archmoj Apr 22, 2024
0d38a5d
refactor
archmoj Apr 23, 2024
a631894
fix mapbox font
archmoj Apr 23, 2024
f963280
correct coerce function and remove unused code
archmoj Apr 23, 2024
d048236
revise opt name
archmoj Apr 23, 2024
33591c2
remove comments - these are arrayOk & handled now by gl-scatter3d
archmoj Apr 23, 2024
9bfe8d1
revise mock
archmoj Apr 23, 2024
3937f2f
fix cluster mapbox font inherit family, weight & style
archmoj Apr 23, 2024
3ac2fa1
draft log
archmoj Apr 23, 2024
21e187e
bump gl-text
archmoj Apr 23, 2024
77c73ff
bump stackgl modules
archmoj Apr 23, 2024
35a025a
npm audit fix
archmoj Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"d3-time-format": "^2.2.3",
"fast-isnumeric": "^1.1.4",
"gl-mat4": "^1.2.0",
"gl-text": "^1.3.1",
"gl-text": "github:gl-vis/gl-text#837f75920836807dd21ef2d22dc12856608c76aa",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"has-hover": "^1.0.1",
"has-passive-events": "^1.0.0",
"is-mobile": "^4.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/components/annotations/common_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module.exports = function handleAnnotationCommonDefaults(annIn, annOut, fullLayo

Lib.coerceFont(coerce, 'hoverlabel.font', {
family: globalHoverLabel.font.family,
weight: globalHoverLabel.font.weight,
style: globalHoverLabel.font.style,
stretch: globalHoverLabel.font.stretch,
variant: globalHoverLabel.font.variant,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it would be simpler to use coerceFont AND easier to read the logic if it accepted TWO default objects - the first letting you pass on an entire unchanged font object, the second letting you override just one or two parts. If we did that, this call would turn into something like
Lib.coerceFont(coerce, ‘hoverlabel.font’, globalHoverLabel.font, {color: globalHoverLabel.font.color || hoverBorder})

size: globalHoverLabel.font.size,
color: globalHoverLabel.font.color || hoverBorder
});
Expand Down
6 changes: 5 additions & 1 deletion src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
borderColor: hoverOptions.bordercolor,
fontFamily: hoverFont.family,
fontSize: hoverFont.size,
fontColor: hoverFont.color
fontColor: hoverFont.color,
fontWeight: hoverFont.weight,
fontStyle: hoverFont.style,
fontStretch: hoverFont.stretch,
fontVariant: hoverFont.variant
}, {
container: fullLayout._hoverlayer.node(),
outerContainer: fullLayout._paper.node(),
Expand Down
4 changes: 4 additions & 0 deletions src/components/colorbar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {

var tickFont = colorbarOut.showticklabels ? colorbarOut.tickfont : font;
var dfltTitleFont = Lib.extendFlat({}, tickFont, {
weight: font.weight,
style: font.style,
stretch: font.stretch,
variant: font.variant,
color: font.color,
size: Lib.bigFont(tickFont.size)
});
Expand Down
26 changes: 20 additions & 6 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@ var drawing = module.exports = {};
// styling functions for plot elements
// -----------------------------------------------------

drawing.font = function(s, family, size, color) {
// also allow the form font(s, {family, size, color})
drawing.font = function(s, family, size, color, weight, style, stretch, variant) {
// also allow the form font(s, {family, size, color, weight, style, stretch, variant})
if(Lib.isPlainObject(family)) {
variant = family.variant;
stretch = family.stretch;
style = family.style;
weight = family.weight;
color = family.color;
size = family.size;
family = family.family;
}
if(family) s.style('font-family', family);
if(size + 1) s.style('font-size', size + 'px');
if(color) s.call(Color.fill, color);

if(weight) s.style('font-weight', weight);
if(style) s.style('font-style', style);
if(stretch) s.style('font-stretch', stretch);
if(variant) s.style('font-variant', variant);
};

/*
Expand Down Expand Up @@ -1126,10 +1135,15 @@ drawing.textPointStyle = function(s, trace, gd) {
selectedTextColorFn(d) :
(d.tc || trace.textfont.color);

p.call(drawing.font,
d.tf || trace.textfont.family,
fontSize,
fontColor)
p.call(drawing.font, {
family: d.tf || trace.textfont.family,
weight: d.tw || trace.textfont.weight,
style: d.ty || trace.textfont.style,
stretch: d.th || trace.textfont.stretch,
variant: d.tv || trace.textfont.variant,
size: fontSize,
color: fontColor
})
.text(text)
.call(svgTextUtils.convertToTspans, gd)
.call(textPointPosition, pos, fontSize, d.mrc);
Expand Down
4 changes: 4 additions & 0 deletions src/components/fx/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = function calc(gd) {
fillFn(trace.hoverlabel.font.size, cd, 'hts');
fillFn(trace.hoverlabel.font.color, cd, 'htc');
fillFn(trace.hoverlabel.font.family, cd, 'htf');
fillFn(trace.hoverlabel.font.weight, cd, 'htw');
fillFn(trace.hoverlabel.font.style, cd, 'hty');
fillFn(trace.hoverlabel.font.stretch, cd, 'hth');
fillFn(trace.hoverlabel.font.variant, cd, 'htv');
fillFn(trace.hoverlabel.namelength, cd, 'hnl');
fillFn(trace.hoverlabel.align, cd, 'hta');
}
Expand Down
40 changes: 34 additions & 6 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ exports.loneHover = function loneHover(hoverItems, opts) {
fontFamily: hoverItem.fontFamily,
fontSize: hoverItem.fontSize,
fontColor: hoverItem.fontColor,
fontWeight: hoverItem.fontWeight,
fontStyle: hoverItem.fontStyle,
fontStretch: hoverItem.fontStretch,
fontVariant: hoverItem.fontVariant,
nameLength: hoverItem.nameLength,
textAlign: hoverItem.textAlign,

Expand Down Expand Up @@ -925,6 +929,10 @@ function createHoverText(hoverData, opts) {
// can override this.
var fontFamily = opts.fontFamily || constants.HOVERFONT;
var fontSize = opts.fontSize || constants.HOVERFONTSIZE;
var fontWeight = opts.fontWeight || 'normal';
var fontStyle = opts.fontStyle || 'normal';
var fontStretch = opts.fontStretch || 'normal';
var fontVariant = opts.fontVariant || 'normal';

var c0 = hoverData[0];
var xa = c0.xa;
Expand Down Expand Up @@ -1006,9 +1014,13 @@ function createHoverText(hoverData, opts) {
var commonStroke = commonLabelOpts.bordercolor || Color.contrast(commonBgColor);
var contrastColor = Color.contrast(commonBgColor);
var commonLabelFont = {
weight: commonLabelOpts.font.weight || fontWeight,
style: commonLabelOpts.font.style || fontStyle,
stretch: commonLabelOpts.font.stretch || fontStretch,
varinat: commonLabelOpts.font.variant || fontVariant,
archmoj marked this conversation as resolved.
Show resolved Hide resolved
family: commonLabelOpts.font.family || fontFamily,
size: commonLabelOpts.font.size || fontSize,
color: commonLabelOpts.font.color || contrastColor
color: commonLabelOpts.font.color || contrastColor,
};

lpath.style({
Expand Down Expand Up @@ -1327,7 +1339,14 @@ function createHoverText(hoverData, opts) {
g.append('path')
.style('stroke-width', '1px');
g.append('text').classed('nums', true)
.call(Drawing.font, fontFamily, fontSize);
.call(Drawing.font, {
weight: fontWeight,
style: fontStyle,
stretch: fontStretch,
variant: fontVariant,
family: fontFamily,
size: fontSize
});
});
hoverLabels.exit().remove();

Expand Down Expand Up @@ -1362,10 +1381,15 @@ function createHoverText(hoverData, opts) {

// main label
var tx = g.select('text.nums')
.call(Drawing.font,
d.fontFamily || fontFamily,
d.fontSize || fontSize,
d.fontColor || contrastColor)
.call(Drawing.font, {
family: d.fontFamily || fontFamily,
size: d.fontSize || fontSize,
color: d.fontColor || contrastColor,
weight: d.fontWeight || fontWeight,
style: d.fontStyle || fontStyle,
stretch: d.fontStretch || fontStretch,
variant: d.fontVariant || fontVariant
})
.text(text)
.attr('data-notex', 1)
.call(svgTextUtils.positionText, 0, 0)
Expand Down Expand Up @@ -1924,6 +1948,10 @@ function cleanPoint(d, hovermode) {
fill('fontFamily', 'htf', 'hoverlabel.font.family');
fill('fontSize', 'hts', 'hoverlabel.font.size');
fill('fontColor', 'htc', 'hoverlabel.font.color');
fill('fontWeight', 'htw', 'hoverlabel.font.weight');
fill('fontStyle', 'hty', 'hoverlabel.font.style');
fill('fontStretch', 'hth', 'hoverlabel.font.stretch');
fill('fontVariant', 'htv', 'hoverlabel.font.variant');
fill('nameLength', 'hnl', 'hoverlabel.namelength');
fill('textAlign', 'hta', 'hoverlabel.align');

Expand Down
4 changes: 4 additions & 0 deletions src/components/fx/hoverlabel_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts
inheritFontAttr('size');
inheritFontAttr('family');
inheritFontAttr('color');
inheritFontAttr('weight');
inheritFontAttr('style');
inheritFontAttr('stretch');
inheritFontAttr('variant');

if(hasLegend) {
if(!opts.bgcolor) opts.bgcolor = Color.combine(contOut.legend.bgcolor, contOut.paper_bgcolor);
Expand Down
4 changes: 4 additions & 0 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ module.exports = function style(s, gd, legend) {
dEdit.ts = 10;
dEdit.tc = boundVal('textfont.color', pickFirst);
dEdit.tf = boundVal('textfont.family', pickFirst);
dEdit.tw = boundVal('textfont.weight', pickFirst);
dEdit.ty = boundVal('textfont.style', pickFirst);
dEdit.th = boundVal('textfont.stretch', pickFirst);
dEdit.tv = boundVal('textfont.variant', pickFirst);
}

dMod = [Lib.minExtend(d0, dEdit)];
Expand Down
9 changes: 8 additions & 1 deletion src/components/titles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function draw(gd, titleClass, options) {
var fontFamily = font.family;
var fontSize = font.size;
var fontColor = font.color;
var fontWeight = font.weight;
var fontStyle = font.style;
var fontStretch = font.stretch;
var fontVariant = font.variant;

// only make this title editable if we positively identify its property
// as one that has editing enabled.
Expand Down Expand Up @@ -146,7 +150,10 @@ function draw(gd, titleClass, options) {
'font-size': d3.round(fontSize, 2) + 'px',
fill: Color.rgb(fontColor),
opacity: opacity * Color.opacity(fontColor),
'font-weight': Plots.fontWeight
'font-weight': fontWeight,
'font-style': fontStyle,
'font-stretch': fontStretch,
'font-variant': fontVariant
})
.attr(attributes)
.call(svgTextUtils.convertToTspans, gd);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ exports.coerceFont = function(coerce, attr, dfltObj) {
out.family = coerce(attr + '.family', dfltObj.family);
out.size = coerce(attr + '.size', dfltObj.size);
out.color = coerce(attr + '.color', dfltObj.color);
out.weight = coerce(attr + '.weight', dfltObj.weight);
out.style = coerce(attr + '.style', dfltObj.style);
out.stretch = coerce(attr + '.stretch', dfltObj.stretch);
out.variant = coerce(attr + '.variant', dfltObj.variant);

return out;
};
Expand Down
14 changes: 13 additions & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,10 @@ function tickTextObj(ax, x, text) {
text: text || '',
fontSize: tf.size,
font: tf.family,
fontWeight: tf.weight,
fontStyle: tf.style,
fontStretch: tf.stretch,
fontVariant: tf.variant,
fontColor: tf.color
};
}
Expand Down Expand Up @@ -3498,7 +3502,15 @@ axes.drawLabels = function(gd, ax, opts) {

thisLabel
.call(svgTextUtils.positionText, labelFns.xFn(d), labelFns.yFn(d))
.call(Drawing.font, d.font, d.fontSize, d.fontColor)
.call(Drawing.font, {
family: d.font,
size: d.fontSize,
color: d.fontColor,
weight: d.fontWeight,
style: d.fontStyle,
stretch: d.fontStretch,
variant: d.fontVariant
})
.text(d.text)
.call(svgTextUtils.convertToTspans, gd);

Expand Down
4 changes: 4 additions & 0 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
coerce('title.text', dfltTitle);
Lib.coerceFont(coerce, 'title.font', {
family: font.family,
weight: font.weight,
style: font.style,
stretch: font.stretch,
variant: font.variant,
size: Lib.bigFont(font.size),
color: dfltFontColor
});
Expand Down
4 changes: 4 additions & 0 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe

Lib.coerceFont(coerce, 'tickfont', {
family: font.family,
weight: font.weight,
style: font.style,
stretch: font.stretch,
variant: font.variant,
size: font.size,
color: dfltFontColor
});
Expand Down
Loading