Skip to content

Commit 7e6096c

Browse files
authored
Merge pull request #13 from gl-vis/font-styles
Font styles
2 parents cbc196b + ac02a12 commit 7e6096c

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

lib/text.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,21 @@ proto.update = function(options) {
211211
var x = tick.x
212212
var text = tick.text
213213
var font = tick.font || 'sans-serif'
214+
var fontStyle = tick.fontStyle || 'normal'
215+
var fontWeight = tick.fontWeight || 'normal'
216+
var fontVariant = tick.fontVariant || 'normal'
214217
scale = (tick.fontSize || 12)
215218

216219
var coordScale = 1.0 / (bounds[dimension+2] - bounds[dimension])
217220
var coordShift = bounds[dimension]
218221

219222
var rows = text.split('\n')
220223
for(var r = 0; r < rows.length; r++) {
221-
data = getText(font, rows[r]).data
224+
data = getText(font, rows[r], {
225+
fontStyle: fontStyle,
226+
fontWeight: fontWeight,
227+
fontVariant: fontVariant
228+
}).data
222229
for (j = 0; j < data.length; j += 2) {
223230
vertices.push(
224231
data[j] * scale,
@@ -239,7 +246,13 @@ proto.update = function(options) {
239246
for(dimension=0; dimension<2; ++dimension) {
240247
this.labelOffset[dimension] = Math.floor(vertices.length/3)
241248

242-
data = getText(options.labelFont[dimension], options.labels[dimension], { textAlign: 'center' }).data
249+
data = getText(options.labelFont[dimension], options.labels[dimension], {
250+
fontStyle: options.labelFontStyle[dimension],
251+
fontWeight: options.labelFontWeight[dimension],
252+
fontVariant: options.labelFontVariant[dimension],
253+
textAlign: 'center'
254+
}).data
255+
243256
scale = options.labelSize[dimension]
244257
for(i=0; i<data.length; i+=2) {
245258
vertices.push(data[i]*scale, -data[i+1]*scale, 0)
@@ -251,7 +264,11 @@ proto.update = function(options) {
251264

252265
//Add title
253266
this.titleOffset = Math.floor(vertices.length/3)
254-
data = getText(options.titleFont, options.title).data
267+
data = getText(options.titleFont, options.title, {
268+
fontStyle: options.titleFontStyle,
269+
fontWeight: options.titleFontWeight,
270+
fontVariant: options.titleFontVariant,
271+
}).data
255272
scale = options.titleSize
256273
for(i=0; i<data.length; i+=2) {
257274
vertices.push(data[i]*scale, -data[i+1]*scale, 0)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"gl-shader": "^4.2.1",
1919
"glsl-inverse": "^1.0.0",
2020
"glslify": "^7.0.0",
21-
"text-cache": "^4.2.2"
21+
"text-cache": "github:gl-vis/text-cache#5369cdcfa5b94077f6be76b1dfa74d6ac87e76f3"
2222
},
2323
"devDependencies": {
2424
"camera-2d": "^1.0.1",

plot.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,16 @@ proto.update = function(options) {
504504
labels: options.labels || ['x', 'y'],
505505
labelSize: options.labelSize || [12,12],
506506
labelFont: options.labelFont || ['sans-serif', 'sans-serif'],
507+
labelFontStyle: options.labelFontStyle || ['normal', 'normal'],
508+
labelFontWeight: options.labelFontWeight || ['normal', 'normal'],
509+
labelFontVariant: options.labelFontVariant || ['normal', 'normal'],
510+
507511
title: options.title || '',
508512
titleSize: options.titleSize || 18,
509-
titleFont: options.titleFont || 'sans-serif'
513+
titleFont: options.titleFont || 'sans-serif',
514+
titleFontStyle: options.titleFontStyle || 'normal',
515+
titleFontWeight: options.titleFontWeight || 'normal',
516+
titleFontVariant: options.titleFontVariant || 'normal'
510517
})
511518

512519
this.static = !!options.static;

0 commit comments

Comments
 (0)