@makechart/bubble.gl 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/index.html +37 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.2
|
|
4
|
+
|
|
5
|
+
- fix tooltip hover offset: map mouse into world coordinate by canvas rect ratio
|
|
6
|
+
( root padding / css transform make display size != world size ); position tooltip by root rect
|
|
7
|
+
- transparent background support: context alpha + premultiplied clear;
|
|
8
|
+
parseColor accepts #rrggbbaa / rgba() / transparent
|
|
9
|
+
- preserveDrawingBuffer: true so export ( e.g. png ) can read canvas anytime
|
|
10
|
+
- default background changed to white ( #ffffff )
|
|
11
|
+
|
|
3
12
|
## v0.0.1
|
|
4
13
|
|
|
5
14
|
- initial release: GPGPU force layout bubble chart
|
package/index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
var mod;
|
|
8
8
|
module.exports = {
|
|
9
9
|
pkg: {
|
|
10
|
-
name: '@makechart/bubble.gl', version: '0.0.
|
|
10
|
+
name: '@makechart/bubble.gl', version: '0.0.2',
|
|
11
11
|
syncInit: true,
|
|
12
12
|
extend: {ns: 'local', name: 'echarts', path: 'common', version: 'main'},
|
|
13
13
|
dependencies: [
|
|
@@ -177,21 +177,35 @@ mod = function(o) {
|
|
|
177
177
|
return [f(0), f(8), f(4)];
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if(typeof(
|
|
183
|
-
if(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
180
|
+
// 回傳 [r,g,b,a] ( 0~1 ); 支援 #rrggbb / #rrggbbaa / rgb() / rgba() / transparent
|
|
181
|
+
function parseWeb(c) {
|
|
182
|
+
if(typeof(c) != 'string') { return null; }
|
|
183
|
+
if(c == 'transparent') { return [0, 0, 0, 0]; }
|
|
184
|
+
var re = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?/i.exec(c);
|
|
185
|
+
if(re) {
|
|
186
|
+
return [
|
|
187
|
+
parseInt(re[1], 16) / 255, parseInt(re[2], 16) / 255, parseInt(re[3], 16) / 255,
|
|
188
|
+
re[4] != null ? parseInt(re[4], 16) / 255 : 1
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
re = /^rgba?\((\d+)[,\s]+(\d+)[,\s]+(\d+)([,\s/]+([\d.]+%?))?/.exec(c);
|
|
192
|
+
if(re) {
|
|
193
|
+
var a = 1;
|
|
194
|
+
if(re[5] != null) { a = /%$/.test(re[5]) ? parseFloat(re[5]) / 100 : parseFloat(re[5]); }
|
|
195
|
+
return [+re[1] / 255, +re[2] / 255, +re[3] / 255, a];
|
|
188
196
|
}
|
|
189
197
|
return null;
|
|
190
198
|
}
|
|
199
|
+
function parseColor(c) {
|
|
200
|
+
if(!c) { return null; }
|
|
201
|
+
var p = parseWeb(c);
|
|
202
|
+
if(!p && typeof(ldcolor) != 'undefined' && ldcolor.web) { p = parseWeb(ldcolor.web(c)); }
|
|
203
|
+
return p;
|
|
204
|
+
}
|
|
191
205
|
|
|
192
206
|
// 內部狀態 ( closure, 不放 chart context )
|
|
193
207
|
var dpr = window.devicePixelRatio || 1;
|
|
194
|
-
var bg = [
|
|
208
|
+
var bg = [1, 1, 1, 1]; // 背景色 rgba ( config: background, a=0 為透明 )
|
|
195
209
|
var pad = 8; // bubble 間距 ( config: bubble.padding )
|
|
196
210
|
var anchorMode = 'orbit'; // 群心佈局 ( config: dynamics.anchor )
|
|
197
211
|
var canvas = null, tip = null, gl = null;
|
|
@@ -388,7 +402,8 @@ mod = function(o) {
|
|
|
388
402
|
|
|
389
403
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
390
404
|
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
391
|
-
|
|
405
|
+
// canvas 為 premultiplied alpha, clear color 也要 premultiply
|
|
406
|
+
gl.clearColor(bg[0] * bg[3], bg[1] * bg[3], bg[2] * bg[3], bg[3]);
|
|
392
407
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
393
408
|
gl.enable(gl.BLEND);
|
|
394
409
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
@@ -420,7 +435,7 @@ mod = function(o) {
|
|
|
420
435
|
var px8 = new Uint8Array(4);
|
|
421
436
|
gl.readPixels(
|
|
422
437
|
Math.min(canvas.width - 1, Math.max(0, Math.round(mx * dpr))),
|
|
423
|
-
Math.min(canvas.height - 1, Math.max(0, Math.round(canvas.height - my * dpr))),
|
|
438
|
+
Math.min(canvas.height - 1, Math.max(0, Math.round(canvas.height - 1 - my * dpr))),
|
|
424
439
|
1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px8
|
|
425
440
|
);
|
|
426
441
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
@@ -428,9 +443,11 @@ mod = function(o) {
|
|
|
428
443
|
}
|
|
429
444
|
|
|
430
445
|
function onMove(e) {
|
|
446
|
+
// 世界座標 != canvas 顯示座標 ( root 可能有 padding, 或整體被 CSS transform 縮放 ),
|
|
447
|
+
// 以 rect 比例換算; tooltip 定位在 root 座標系, 用 root rect 換算
|
|
431
448
|
var rect = canvas.getBoundingClientRect();
|
|
432
|
-
mouse.x = e.clientX - rect.left;
|
|
433
|
-
mouse.y = e.clientY - rect.top;
|
|
449
|
+
mouse.x = (e.clientX - rect.left) * (Wc / (rect.width || Wc));
|
|
450
|
+
mouse.y = (e.clientY - rect.top) * (Hc / (rect.height || Hc));
|
|
434
451
|
mouse.over = true;
|
|
435
452
|
if(mouse.down || !parsed) { tip.style.display = 'none'; return; }
|
|
436
453
|
var now = performance.now();
|
|
@@ -438,10 +455,11 @@ mod = function(o) {
|
|
|
438
455
|
lastPick = now;
|
|
439
456
|
var id = doPick(mouse.x, mouse.y);
|
|
440
457
|
if(id >= 0 && id < parsed.names.length) {
|
|
458
|
+
var rrect = root.getBoundingClientRect();
|
|
441
459
|
tip.textContent = parsed.names[id] + '\ncategory: ' +
|
|
442
460
|
parsed.catNames[parsed.cats[id]] + '\nsize: ' + parsed.sizes[id];
|
|
443
|
-
tip.style.left = (
|
|
444
|
-
tip.style.top = (
|
|
461
|
+
tip.style.left = (e.clientX - rrect.left + 14) + 'px';
|
|
462
|
+
tip.style.top = (e.clientY - rrect.top + 14) + 'px';
|
|
445
463
|
tip.style.display = 'block';
|
|
446
464
|
} else {
|
|
447
465
|
tip.style.display = 'none';
|
|
@@ -470,7 +488,7 @@ mod = function(o) {
|
|
|
470
488
|
},
|
|
471
489
|
config: {
|
|
472
490
|
palette: {type: 'palette'},
|
|
473
|
-
background: {type: 'color', default: '#
|
|
491
|
+
background: {type: 'color', default: '#ffffff'},
|
|
474
492
|
bubble: {
|
|
475
493
|
padding: {name: "bubble padding", type: 'number', default: 8, min: 0, max: 40, step: 1}
|
|
476
494
|
},
|
|
@@ -505,7 +523,8 @@ mod = function(o) {
|
|
|
505
523
|
'font:12px/1.5 monospace', 'color:#dfe8f2', 'white-space:pre', 'z-index:10'
|
|
506
524
|
].join(';');
|
|
507
525
|
root.appendChild(tip);
|
|
508
|
-
|
|
526
|
+
// alpha: 支援透明背景; preserveDrawingBuffer: 讓 toDataURL/toBlob 匯出可隨時讀取
|
|
527
|
+
gl = canvas.getContext('webgl2', {antialias: false, alpha: true, preserveDrawingBuffer: true});
|
|
509
528
|
if(!gl) { throw new Error("bubble.gl: WebGL2 not supported"); }
|
|
510
529
|
if(!gl.getExtension('EXT_color_buffer_float')) {
|
|
511
530
|
throw new Error("bubble.gl: EXT_color_buffer_float not supported");
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@makechart/bubble.gl","version":"0.0.
|
|
1
|
+
{"name":"@makechart/bubble.gl","version":"0.0.2","description":"GPGPU force layout bubble chart - 100k+ points, WebGL2","scripts":{"build":"./build"},"keywords":[],"author":"zbryikt","license":"MIT","dependencies":{"@plotdb/srcbuild":"^0.0.70","fedep":"1.7.3","livescript":"^1.6.0"}}
|