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
| //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
| //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
| //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
| 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
| 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
| 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
| interface Paint { }; | |
| interface SolidColor : Paint { | |
| attribute double red; | |
| attribute double green; | |
| attribute double blue; | |
| }; | |
| interface Pattern : Paint { | |
| attribute DOMString imageURL; |
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
| EMSCRIPTEN_BINDINGS(hierarchy) { | |
| register_vector<HNode*>("VectorHNode"); | |
| class_<HBasis>("HBasis") | |
| .property("x", &HBasis::x) | |
| .property("y", &HBasis::y) | |
| .property("r", &HBasis::r); | |
| class_<HNode, base<HBasis>>("HNode") | |
| .constructor<emscripten::val>() |
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
| function generateLayout(children: Node[], width: number) { | |
| const root = new Module.Hierarchy({ | |
| size: [width, width], | |
| padding: 1.5 | |
| }, { value: 0, children}); | |
| return root.pack().leaves(); | |
| } |