Skip to content

Commit eb82700

Browse files
committed
handle styles in gl-plot2d and text-cache
1 parent f92ff86 commit eb82700

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

stackgl_modules/index.js

+54-6
Original file line numberDiff line numberDiff line change
@@ -19350,14 +19350,23 @@ proto.update = function(options) {
1935019350
var x = tick.x
1935119351
var text = tick.text
1935219352
var font = tick.font || 'sans-serif'
19353+
var fontStyle = tick.fontStyle || 'normal'
19354+
var fontWeight = tick.fontWeight || 'normal'
19355+
var fontStretch = tick.fontStretch || 'normal'
19356+
var fontVariant = tick.fontVariant || 'normal'
1935319357
scale = (tick.fontSize || 12)
1935419358

1935519359
var coordScale = 1.0 / (bounds[dimension+2] - bounds[dimension])
1935619360
var coordShift = bounds[dimension]
1935719361

1935819362
var rows = text.split('\n')
1935919363
for(var r = 0; r < rows.length; r++) {
19360-
data = getText(font, rows[r]).data
19364+
data = getText(font, rows[r], {
19365+
fontStyle: fontStyle,
19366+
fontWeight: fontWeight,
19367+
fontStretch: fontStretch,
19368+
fontVariant: fontVariant
19369+
}).data
1936119370
for (j = 0; j < data.length; j += 2) {
1936219371
vertices.push(
1936319372
data[j] * scale,
@@ -19378,7 +19387,14 @@ proto.update = function(options) {
1937819387
for(dimension=0; dimension<2; ++dimension) {
1937919388
this.labelOffset[dimension] = Math.floor(vertices.length/3)
1938019389

19381-
data = getText(options.labelFont[dimension], options.labels[dimension], { textAlign: 'center' }).data
19390+
data = getText(options.labelFont[dimension], options.labels[dimension], {
19391+
fontStyle: options.labelFontStyle[dimension],
19392+
fontWeight: options.labelFontWeight[dimension],
19393+
fontStretch: options.labelFontStretch[dimension],
19394+
fontVariant: options.labelFontVariant[dimension],
19395+
textAlign: 'center'
19396+
}).data
19397+
1938219398
scale = options.labelSize[dimension]
1938319399
for(i=0; i<data.length; i+=2) {
1938419400
vertices.push(data[i]*scale, -data[i+1]*scale, 0)
@@ -19390,7 +19406,12 @@ proto.update = function(options) {
1939019406

1939119407
//Add title
1939219408
this.titleOffset = Math.floor(vertices.length/3)
19393-
data = getText(options.titleFont, options.title).data
19409+
data = getText(options.titleFont, options.title, {
19410+
fontStyle: options.titleFontStyle,
19411+
fontWeight: options.titleFontWeight,
19412+
fontStretch: options.titleFontStretch,
19413+
fontVariant: options.titleFontVariant,
19414+
}).data
1939419415
scale = options.titleSize
1939519416
for(i=0; i<data.length; i+=2) {
1939619417
vertices.push(data[i]*scale, -data[i+1]*scale, 0)
@@ -19927,9 +19948,18 @@ proto.update = function(options) {
1992719948
labels: options.labels || ['x', 'y'],
1992819949
labelSize: options.labelSize || [12,12],
1992919950
labelFont: options.labelFont || ['sans-serif', 'sans-serif'],
19951+
labelFontStyle: options.labelFontStyle || ['normal', 'normal'],
19952+
labelFontWeight: options.labelFontWeight || ['normal', 'normal'],
19953+
labelFontStretch: options.labelFontStretch || ['normal', 'normal'],
19954+
labelFontVariant: options.labelFontVariant || ['normal', 'normal'],
19955+
1993019956
title: options.title || '',
1993119957
titleSize: options.titleSize || 18,
19932-
titleFont: options.titleFont || 'sans-serif'
19958+
titleFont: options.titleFont || 'sans-serif',
19959+
titleFontStyle: options.titleFontStyle || 'normal',
19960+
titleFontWeight: options.titleFontWeight || 'normal',
19961+
titleFontStretch: options.titleFontStretch || 'normal',
19962+
titleFontVariant: options.titleFontVariant || 'normal'
1993319963
})
1993419964

1993519965
this.static = !!options.static;
@@ -40224,9 +40254,23 @@ function unwrap(mesh) {
4022440254

4022540255
function textGet(font, text, opts) {
4022640256
var opts = opts || {}
40227-
var fontcache = __TEXT_CACHE[font]
40257+
40258+
var fontStyle = opts.fontStyle || 'normal'
40259+
var fontWeight = opts.fontWeight || 'normal'
40260+
var fontStretch = opts.fontStretch || 'normal'
40261+
var fontVariant = opts.fontVariant || 'normal'
40262+
40263+
var fontKey = [
40264+
fontStyle,
40265+
fontWeight,
40266+
fontStretch,
40267+
fontVariant,
40268+
font
40269+
].join('_')
40270+
40271+
var fontcache = __TEXT_CACHE[fontKey]
4022840272
if(!fontcache) {
40229-
fontcache = __TEXT_CACHE[font] = {
40273+
fontcache = __TEXT_CACHE[fontKey] = {
4023040274
' ': {
4023140275
data: new Float32Array(0),
4023240276
shape: 0.2
@@ -40239,6 +40283,10 @@ function textGet(font, text, opts) {
4023940283
mesh = fontcache[text] = unwrap(vectorizeText(text, {
4024040284
triangles: true,
4024140285
font: font,
40286+
fontStyle: fontStyle,
40287+
fontWeight: fontWeight,
40288+
fontStretch: fontStretch,
40289+
fontVariant: fontVariant,
4024240290
textAlign: opts.textAlign || 'left',
4024340291
textBaseline: 'alphabetic',
4024440292
styletags: {

stackgl_modules/package-lock.json

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

stackgl_modules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"gl-heatmap2d": "^1.1.1",
2020
"gl-line3d": "1.2.1",
2121
"gl-mesh3d": "^2.3.1",
22-
"gl-plot2d": "^1.4.5",
22+
"gl-plot2d": "github:gl-vis/gl-plot2d#bb6788ee546f4da8550faf2cc4be3632fbb4a11d",
2323
"gl-plot3d": "^2.4.7",
2424
"gl-pointcloud2d": "^1.0.3",
2525
"gl-scatter3d": "github:gl-vis/gl-scatter3d#eeb947a712fc6a17fa0dc1775397976de926887a",

0 commit comments

Comments
 (0)