diff --git a/lib/get-simple-string.js b/lib/get-simple-string.js new file mode 100644 index 0000000..dc48165 --- /dev/null +++ b/lib/get-simple-string.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function(a){ + return (!a && a !== 0) ? '' : a.toString(); +} diff --git a/lib/glyphs.js b/lib/glyphs.js index 575b435..f0513ad 100644 --- a/lib/glyphs.js +++ b/lib/glyphs.js @@ -21,14 +21,14 @@ function getGlyph(symbol, font) { textBaseline: "middle", lineHeight: 1.0, font: font - }) + }) var triSymbol = vectorizeText(symbol, { triangles: true, textAlign: "center", textBaseline: "middle", lineHeight: 1.0, font: font - }) + }) //Calculate bounding box var bounds = [[Infinity,Infinity], [-Infinity,-Infinity]] diff --git a/package-lock.json b/package-lock.json index d2cb521..3ba0150 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1443,6 +1443,11 @@ "integrity": "sha1-DR5tk+OAs1OG9HRUP//Jpm1Bgl4=", "dev": true }, + "is-string-blank": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-string-blank/-/is-string-blank-1.0.1.tgz", + "integrity": "sha512-9H+ZBCVs3L9OYqv8nuUAzpcT9OTgMD1yAWrG7ihlnibdkbtB850heAmYWxHuXc4CHy4lKeK69tN+ny1K7gBIrw==" + }, "is-symbol": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", diff --git a/package.json b/package.json index a2dad89..c46a0cb 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "gl-vao": "^1.1.2", "glslify": "^6.1.0", "glsl-out-of-range": "^1.0.2", + "is-string-blank": "^1.0.1", "typedarray-pool": "^1.0.2", "vectorize-text": "^3.0.0" }, diff --git a/pointcloud.js b/pointcloud.js index f6c144f..d004ced 100644 --- a/pointcloud.js +++ b/pointcloud.js @@ -1,11 +1,13 @@ 'use strict' -var createBuffer = require('gl-buffer') -var createVAO = require('gl-vao') -var pool = require('typedarray-pool') -var mat4mult = require('gl-mat4/multiply') -var shaders = require('./lib/shaders') -var getGlyph = require('./lib/glyphs') +var isAllBlank = require('is-string-blank') +var createBuffer = require('gl-buffer') +var createVAO = require('gl-vao') +var pool = require('typedarray-pool') +var mat4mult = require('gl-mat4/multiply') +var shaders = require('./lib/shaders') +var getGlyph = require('./lib/glyphs') +var getSimpleString = require('./lib/get-simple-string') var IDENTITY = [1,0,0,0, 0,1,0,0, @@ -389,6 +391,38 @@ proto.highlight = function(selection) { } } +function get_glyphData(glyphs, index, font) { + var str + + // use the data if presented in an array + if(Array.isArray(glyphs)) { + if(index < glyphs.length) { + str = glyphs[index] + } else { + str = undefined + } + } else { + str = glyphs + } + + str = getSimpleString(str) // this would handle undefined cases + + var visible = true + if(isAllBlank(str)) { + str = '▼' // Note: this special character may have minimum number of surfaces + visible = false + } + + var glyph = getGlyph(str, font) + + return { mesh:glyph[0], + lines:glyph[1], + bounds:glyph[2], + visible:visible }; +} + + + proto.update = function(options) { options = options || {} @@ -435,9 +469,6 @@ proto.update = function(options) { //Create new buffers var points = options.position - if(!points) { - return - } //Text font var font = options.font || 'normal' @@ -455,232 +486,253 @@ proto.update = function(options) { var lineColors = options.lineColor //Picking geometry - var pickCounter = 0 + var pickCounter = -1 //First do pass to compute buffer sizes - var triVertexCount = 0 + var triVertexCount = 0 var lineVertexCount = 0 - //Count number of points and buffer size - var numPoints = points.length + var numPoints = 0; -count_loop: - for(var i=0; i 0) { + var textOffset = [0,alignment[1]] - var triOffset = 0 - var lineOffset = triVertexCount - var color = [0,0,0,1] - var lineColor = [0,0,0,1] + var triOffset = 0 + var lineOffset = triVertexCount + var color = [0,0,0,1] + var lineColor = [0,0,0,1] - var isColorArray = Array.isArray(colors) && Array.isArray(colors[0]) - var isLineColorArray = Array.isArray(lineColors) && Array.isArray(lineColors[0]) + var isColorArray = Array.isArray(colors) && Array.isArray(colors[0]) + var isLineColorArray = Array.isArray(lineColors) && Array.isArray(lineColors[0]) -fill_loop: - for(var i=0; i 0) { - textOffset[0] = -alignment[0] * (1+glyphBounds[0][0]) - } + var angle = 0 + if(Array.isArray(angles)) { + if(i < angles.length) { + angle = +angles[i] + } else { + angle = 0 + } + } else if(angles) { + angle = +angles + } - //Write out inner marker - var cells = glyphMesh.cells - var verts = glyphMesh.positions + //Loop through markers and append to buffers + var cos = Math.cos(angle) + var sin = Math.sin(angle) - for(var j=0; j 0) { + textOffset[0] = -alignment[0] * (1+glyphBounds[0][0]) + } - for(var j=0; j