Skip to content

Commit 6e367d6

Browse files
committed
add font style options to gl-axes3d
1 parent 3631d1a commit 6e367d6

File tree

4 files changed

+125
-36
lines changed

4 files changed

+125
-36
lines changed

src/plots/gl3d/layout/convert.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function AxesOptions() {
1515
this.tickEnable = [ true, true, true ];
1616
this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ];
1717
this.tickSize = [ 12, 12, 12 ];
18-
this.tickWeight = [ 'normal', 'normal', 'normal', 'normal' ];
19-
this.tickStyle = [ 'normal', 'normal', 'normal', 'normal' ];
20-
this.tickStretch = [ 'normal', 'normal', 'normal', 'normal' ];
21-
this.tickVariant = [ 'normal', 'normal', 'normal', 'normal' ];
18+
this.tickFontWeight = [ 'normal', 'normal', 'normal', 'normal' ];
19+
this.tickFontStyle = [ 'normal', 'normal', 'normal', 'normal' ];
20+
this.tickFontStretch = [ 'normal', 'normal', 'normal', 'normal' ];
21+
this.tickFontVariant = [ 'normal', 'normal', 'normal', 'normal' ];
2222
this.tickAngle = [ 0, 0, 0 ];
2323
this.tickColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];
2424
this.tickPad = [ 18, 18, 18 ];
@@ -27,10 +27,10 @@ function AxesOptions() {
2727
this.labelEnable = [ true, true, true ];
2828
this.labelFont = ['Open Sans', 'Open Sans', 'Open Sans'];
2929
this.labelSize = [ 20, 20, 20 ];
30-
this.labelWeight = [ 'normal', 'normal', 'normal', 'normal' ];
31-
this.labelStyle = [ 'normal', 'normal', 'normal', 'normal' ];
32-
this.labelStretch = [ 'normal', 'normal', 'normal', 'normal' ];
33-
this.labelVariant = [ 'normal', 'normal', 'normal', 'normal' ];
30+
this.labelFontWeight = [ 'normal', 'normal', 'normal', 'normal' ];
31+
this.labelFontStyle = [ 'normal', 'normal', 'normal', 'normal' ];
32+
this.labelFontStretch = [ 'normal', 'normal', 'normal', 'normal' ];
33+
this.labelFontVariant = [ 'normal', 'normal', 'normal', 'normal' ];
3434
this.labelColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];
3535
this.labelPad = [ 30, 30, 30 ];
3636

@@ -91,10 +91,10 @@ proto.merge = function(fullLayout, sceneLayout) {
9191
if(axes.title.font.color) opts.labelColor[i] = str2RgbaArray(axes.title.font.color);
9292
if(axes.title.font.family) opts.labelFont[i] = axes.title.font.family;
9393
if(axes.title.font.size) opts.labelSize[i] = axes.title.font.size;
94-
if(axes.title.font.weight) opts.labelWeight[i] = axes.title.font.weight;
95-
if(axes.title.font.style) opts.labelStyle[i] = axes.title.font.style;
96-
if(axes.title.font.stretch) opts.labelStretch[i] = axes.title.font.stretch;
97-
if(axes.title.font.variant) opts.labelVariant[i] = axes.title.font.variant;
94+
if(axes.title.font.weight) opts.labelFontWeight[i] = axes.title.font.weight;
95+
if(axes.title.font.style) opts.labelFontStyle[i] = axes.title.font.style;
96+
if(axes.title.font.stretch) opts.labelFontStretch[i] = axes.title.font.stretch;
97+
if(axes.title.font.variant) opts.labelFontVariant[i] = axes.title.font.variant;
9898
}
9999

100100
// Lines
@@ -134,10 +134,10 @@ proto.merge = function(fullLayout, sceneLayout) {
134134
if(axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color);
135135
if(axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family;
136136
if(axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size;
137-
if(axes.tickfont.weight) opts.tickWeight[i] = axes.tickfont.weight;
138-
if(axes.tickfont.style) opts.tickStyle[i] = axes.tickfont.style;
139-
if(axes.tickfont.stretch) opts.tickStretch[i] = axes.tickfont.stretch;
140-
if(axes.tickfont.variant) opts.tickVariant[i] = axes.tickfont.variant;
137+
if(axes.tickfont.weight) opts.tickFontWeight[i] = axes.tickfont.weight;
138+
if(axes.tickfont.style) opts.tickFontStyle[i] = axes.tickfont.style;
139+
if(axes.tickfont.stretch) opts.tickFontStretch[i] = axes.tickfont.stretch;
140+
if(axes.tickfont.variant) opts.tickFontVariant[i] = axes.tickfont.variant;
141141
}
142142

143143
if('mirror' in axes) {

stackgl_modules/index.js

+101-15
Original file line numberDiff line numberDiff line change
@@ -11925,6 +11925,10 @@ function Axes(gl) {
1192511925

1192611926
this.tickEnable = [ true, true, true ]
1192711927
this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ]
11928+
this.tickFontStyle = [ 'normal', 'normal', 'normal' ]
11929+
this.tickFontWeight = [ 'normal', 'normal', 'normal' ]
11930+
this.tickFontStretch = [ 'normal', 'normal', 'normal' ]
11931+
this.tickFontVariant = [ 'normal', 'normal', 'normal' ]
1192811932
this.tickSize = [ 12, 12, 12 ]
1192911933
this.tickAngle = [ 0, 0, 0 ]
1193011934
this.tickAlign = [ 'auto', 'auto', 'auto' ]
@@ -11938,7 +11942,11 @@ function Axes(gl) {
1193811942

1193911943
this.labels = [ 'x', 'y', 'z' ]
1194011944
this.labelEnable = [ true, true, true ]
11941-
this.labelFont = 'sans-serif'
11945+
this.labelFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ]
11946+
this.labelFontStyle = [ 'normal', 'normal', 'normal' ]
11947+
this.labelFontWeight = [ 'normal', 'normal', 'normal' ]
11948+
this.labelFontStretch = [ 'normal', 'normal', 'normal' ]
11949+
this.labelFontVariant = [ 'normal', 'normal', 'normal' ]
1194211950
this.labelSize = [ 20, 20, 20 ]
1194311951
this.labelAngle = [ 0, 0, 0 ]
1194411952
this.labelAlign = [ 'auto', 'auto', 'auto' ]
@@ -12075,19 +12083,28 @@ i_loop:
1207512083

1207612084
//Parse tick properties
1207712085
BOOLEAN('tickEnable')
12078-
if(STRING('tickFont')) {
12079-
ticksUpdate = true //If font changes, must rebuild vbo
12080-
}
12086+
12087+
//If font changes, must rebuild vbo
12088+
if(STRING('tickFont')) ticksUpdate = true
12089+
if(STRING('tickFontStyle')) ticksUpdate = true
12090+
if(STRING('tickFontWeight')) ticksUpdate = true
12091+
if(STRING('tickFontStretch')) ticksUpdate = true
12092+
if(STRING('tickFontVariant')) ticksUpdate = true
12093+
1208112094
NUMBER('tickSize')
1208212095
NUMBER('tickAngle')
1208312096
NUMBER('tickPad')
1208412097
COLOR('tickColor')
1208512098

1208612099
//Axis labels
1208712100
var labelUpdate = STRING('labels')
12088-
if(STRING('labelFont')) {
12089-
labelUpdate = true
12090-
}
12101+
12102+
if(STRING('labelFont')) labelUpdate = true
12103+
if(STRING('labelFontStyle')) labelUpdate = true
12104+
if(STRING('labelFontWeight')) labelUpdate = true
12105+
if(STRING('labelFontStretch')) labelUpdate = true
12106+
if(STRING('labelFontVariant')) labelUpdate = true
12107+
1209112108
BOOLEAN('labelEnable')
1209212109
NUMBER('labelSize')
1209312110
NUMBER('labelPad')
@@ -12120,22 +12137,70 @@ i_loop:
1212012137
BOOLEAN('backgroundEnable')
1212112138
COLOR('backgroundColor')
1212212139

12140+
var labelFontOpts = [
12141+
{
12142+
family: this.labelFont[0],
12143+
style: this.labelFontStyle[0],
12144+
weight: this.labelFontWeight[0],
12145+
stretch: this.labelFontStretch[0],
12146+
variant: this.labelFontVariant[0],
12147+
},
12148+
{
12149+
family: this.labelFont[1],
12150+
style: this.labelFontStyle[1],
12151+
weight: this.labelFontWeight[1],
12152+
stretch: this.labelFontStretch[1],
12153+
variant: this.labelFontVariant[1],
12154+
},
12155+
{
12156+
family: this.labelFont[2],
12157+
style: this.labelFontStyle[2],
12158+
weight: this.labelFontWeight[2],
12159+
stretch: this.labelFontStretch[2],
12160+
variant: this.labelFontVariant[2],
12161+
}
12162+
]
12163+
12164+
var tickFontOpts = [
12165+
{
12166+
family: this.tickFont[0],
12167+
style: this.tickFontStyle[0],
12168+
weight: this.tickFontWeight[0],
12169+
stretch: this.tickFontStretch[0],
12170+
variant: this.tickFontVariant[0],
12171+
},
12172+
{
12173+
family: this.tickFont[1],
12174+
style: this.tickFontStyle[1],
12175+
weight: this.tickFontWeight[1],
12176+
stretch: this.tickFontStretch[1],
12177+
variant: this.tickFontVariant[1],
12178+
},
12179+
{
12180+
family: this.tickFont[2],
12181+
style: this.tickFontStyle[2],
12182+
weight: this.tickFontWeight[2],
12183+
stretch: this.tickFontStretch[2],
12184+
variant: this.tickFontVariant[2],
12185+
}
12186+
]
12187+
1212312188
//Update text if necessary
1212412189
if(!this._text) {
1212512190
this._text = createText(
1212612191
this.gl,
1212712192
this.bounds,
1212812193
this.labels,
12129-
this.labelFont,
12194+
labelFontOpts,
1213012195
this.ticks,
12131-
this.tickFont)
12196+
tickFontOpts)
1213212197
} else if(this._text && (labelUpdate || ticksUpdate)) {
1213312198
this._text.update(
1213412199
this.bounds,
1213512200
this.labels,
12136-
this.labelFont,
12201+
labelFontOpts,
1213712202
this.ticks,
12138-
this.tickFont)
12203+
tickFontOpts)
1213912204
}
1214012205

1214112206
//Update lines if necessary
@@ -13183,15 +13248,27 @@ proto.update = function(bounds, labels, labelFont, ticks, tickFont) {
1318313248
var data = []
1318413249

1318513250
function addItem(t, text, font, size, lineSpacing, styletags) {
13186-
var fontcache = __TEXT_CACHE[font]
13251+
var fontKey = [
13252+
font.style,
13253+
font.weight,
13254+
font.stretch,
13255+
font.variant,
13256+
font.family
13257+
].join('_')
13258+
13259+
var fontcache = __TEXT_CACHE[fontKey]
1318713260
if(!fontcache) {
13188-
fontcache = __TEXT_CACHE[font] = {}
13261+
fontcache = __TEXT_CACHE[fontKey] = {}
1318913262
}
1319013263
var mesh = fontcache[text]
1319113264
if(!mesh) {
1319213265
mesh = fontcache[text] = tryVectorizeText(text, {
1319313266
triangles: true,
13194-
font: font,
13267+
font: font.family,
13268+
fontStyle: font.style,
13269+
fontWeight: font.weight,
13270+
fontStretch: font.stretch,
13271+
fontVariant: font.variant,
1319513272
textAlign: 'center',
1319613273
textBaseline: 'middle',
1319713274
lineSpacing: lineSpacing,
@@ -13243,10 +13320,19 @@ proto.update = function(bounds, labels, labelFont, ticks, tickFont) {
1324313320
if(!ticks[d][i].text) {
1324413321
continue
1324513322
}
13323+
13324+
var font = {
13325+
family: ticks[d][i].font || tickFont[d].family,
13326+
style: tickFont[d].fontStyle || tickFont[d].style,
13327+
weight: tickFont[d].fontWeight || tickFont[d].weight,
13328+
stretch: tickFont[d].fontStretch || tickFont[d].stretch,
13329+
variant: tickFont[d].fontVariant || tickFont[d].variant,
13330+
}
13331+
1324613332
addItem(
1324713333
ticks[d][i].x,
1324813334
ticks[d][i].text,
13249-
ticks[d][i].font || tickFont,
13335+
font,
1325013336
ticks[d][i].fontSize || 12,
1325113337
lineSpacing,
1325213338
styletags

stackgl_modules/package-lock.json

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stackgl_modules/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"box-intersect": "plotly/box-intersect#v1.1.0",
1414
"convex-hull": "^1.0.3",
1515
"delaunay-triangulate": "^1.1.6",
16+
"gl-axes3d": "github:gl-vis/gl-axes3d#445a7aad8fe75ea791ac98a1960cff2dab4412c3",
1617
"gl-cone3d": "^1.6.0",
1718
"gl-error3d": "^1.0.16",
1819
"gl-heatmap2d": "^1.1.1",

0 commit comments

Comments
 (0)