Skip to content

Font styles #13

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

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions lib/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,21 @@ proto.update = function(options) {
var x = tick.x
var text = tick.text
var font = tick.font || 'sans-serif'
var fontStyle = tick.fontStyle || 'normal'
var fontWeight = tick.fontWeight || 'normal'
var fontVariant = tick.fontVariant || 'normal'
scale = (tick.fontSize || 12)

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

var rows = text.split('\n')
for(var r = 0; r < rows.length; r++) {
data = getText(font, rows[r]).data
data = getText(font, rows[r], {
fontStyle: fontStyle,
fontWeight: fontWeight,
fontVariant: fontVariant
}).data
for (j = 0; j < data.length; j += 2) {
vertices.push(
data[j] * scale,
Expand All @@ -239,7 +246,13 @@ proto.update = function(options) {
for(dimension=0; dimension<2; ++dimension) {
this.labelOffset[dimension] = Math.floor(vertices.length/3)

data = getText(options.labelFont[dimension], options.labels[dimension], { textAlign: 'center' }).data
data = getText(options.labelFont[dimension], options.labels[dimension], {
fontStyle: options.labelFontStyle[dimension],
fontWeight: options.labelFontWeight[dimension],
fontVariant: options.labelFontVariant[dimension],
textAlign: 'center'
}).data

scale = options.labelSize[dimension]
for(i=0; i<data.length; i+=2) {
vertices.push(data[i]*scale, -data[i+1]*scale, 0)
Expand All @@ -251,7 +264,11 @@ proto.update = function(options) {

//Add title
this.titleOffset = Math.floor(vertices.length/3)
data = getText(options.titleFont, options.title).data
data = getText(options.titleFont, options.title, {
fontStyle: options.titleFontStyle,
fontWeight: options.titleFontWeight,
fontVariant: options.titleFontVariant,
}).data
scale = options.titleSize
for(i=0; i<data.length; i+=2) {
vertices.push(data[i]*scale, -data[i+1]*scale, 0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"gl-shader": "^4.2.1",
"glsl-inverse": "^1.0.0",
"glslify": "^7.0.0",
"text-cache": "^4.2.2"
"text-cache": "github:gl-vis/text-cache#5369cdcfa5b94077f6be76b1dfa74d6ac87e76f3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

},
"devDependencies": {
"camera-2d": "^1.0.1",
Expand Down
9 changes: 8 additions & 1 deletion plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,16 @@ proto.update = function(options) {
labels: options.labels || ['x', 'y'],
labelSize: options.labelSize || [12,12],
labelFont: options.labelFont || ['sans-serif', 'sans-serif'],
labelFontStyle: options.labelFontStyle || ['normal', 'normal'],
labelFontWeight: options.labelFontWeight || ['normal', 'normal'],
labelFontVariant: options.labelFontVariant || ['normal', 'normal'],

title: options.title || '',
titleSize: options.titleSize || 18,
titleFont: options.titleFont || 'sans-serif'
titleFont: options.titleFont || 'sans-serif',
titleFontStyle: options.titleFontStyle || 'normal',
titleFontWeight: options.titleFontWeight || 'normal',
titleFontVariant: options.titleFontVariant || 'normal'
})

this.static = !!options.static;
Expand Down