This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int_sqrt = Module.cwrap('int_sqrt', 'number', ['number']) | |
| int_sqrt(12) | |
| int_sqrt(28) | |
| var result = Module.ccall('int_sqrt', // name of C function | |
| 'number', // return type | |
| ['number'], // argument types | |
| [28]); // arguments | |
| var result = Module._int_sqrt(28); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| root = d3.hierarchy({children}) | |
| //Value becomes the retainedSize of each node | |
| .sum(node => node.retainedSize); | |
| const layout = d3.pack() | |
| .size([d.width, d.width]) | |
| .padding(1.5); | |
| //Apply the layout to our root, then return all leaf nodes | |
| const nodes = layout(root).leaves() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fr = new FileReader(); | |
| fr.readAsArrayBuffer(file); | |
| fr.onloadend = heap => this.worker.postMessage({ | |
| command: 'TransferProfile', | |
| data: { | |
| heap | |
| } | |
| }, [heap]); //Passing [heap] as a 2nd parameter flags it as Transferable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //To receive | |
| function fromHeap(heap: ArrayBufferView) { | |
| const decoder = new TextDecoder(); | |
| const file = decoder.decode(heap); | |
| const profile = new HeapProfile(JSON.parse(file), dispatcher); | |
| return profile; | |
| } | |
| //To serialize and send | |
| function serializeResponse(nodes: Array<WireNode>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //To serialize and send | |
| function serializeResponse(nodes: Array<WireNode>) { | |
| const te = new TextEncoder(); | |
| return te.encode(JSON.stringify(nodes)).buffer; | |
| } | |
| function transferNodes(children: Array<Node>, nodes: any) { | |
| let node:WireNode; | |
| const wireNodes:WireNode[] = []; | |
| for (var i = 0; i < nodes.size(); i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Vert | |
| precision mediump float; | |
| attribute vec2 aPosition; | |
| uniform mat4 uModelView; | |
| uniform mat4 uProjection; | |
| void main() { | |
| gl_Position = uProjection * uModelView * vec4(aPosition, 0.0, 1.0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as glBuffer from 'gl-buffer'; | |
| import * as glClear from 'gl-clear'; | |
| import * as context from 'gl-context'; | |
| import * as glShader from 'gl-shader'; | |
| import * as frag from 'raw!./shader.frag'; | |
| import * as vert from 'raw!./shader.vert' | |
| import * as create from 'gl-mat4/create'; | |
| import * as identity from 'gl-mat4/identity'; | |
| import * as translate from 'gl-mat4/translate'; | |
| import * as scale from 'gl-mat4/scale'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| batchRender() | |
| let i = this._start; | |
| let startTime = Date.now(); | |
| let timeDiff = 0; | |
| while (i < nodes.length && timeDiff < 10) { | |
| const node = nodes[i]; | |
| const circle = new NodeCircle({ node, texture: texture(node.t) }); | |
| this.stage.addChild(circle.retainedSize); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Generate our basic textures | |
| function generateTextures(width, height, renderer) { | |
| scheme.forEach(hex => { | |
| const color = hexColor(hex); | |
| const size = nearestPow2(width < height ? width / 2 : height / 2); | |
| textures[color] = createTexture(color, size, renderer); | |
| }); | |
| } | |
| function createTexture(hex, size, renderer) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| import _ from 'lodash'; | |
| import { schemeCategory20 as scheme, scaleOrdinal as scale } from 'd3-scale'; | |
| import { hierarchy, pack } from 'd3-hierarchy'; | |
| import PIXI from 'pixi'; | |
| import PixiCanvas from 'ember-cli-pixijs/components/pixi-canvas'; | |
| const {inject: {service}, computed: {alias}} = Ember; | |
| const MAX_NODES = 100000; | |
| let hexColor; |