code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function getNearestIndex(allPoints, intersectedIndexes, ray, maxDistanceFromRay) { if (intersectedIndexes.length === 0) return; // This is not necessary the fastest solution, but in practice it is very fast intersectedIndexes.sort(byProximityToRay); var candidate = intersectedIndexes[0]; if (getDistanceToRay(candidate) < maxDistanceFromRay) { return candidate; } // No point is closer than maxDistanceFromRay, return undefined answer return; function byProximityToRay(x, y) { var distX = getDistanceToRay(x); var distY = getDistanceToRay(y); return distX - distY; } function getDistanceToRay(idx) { var x = allPoints[idx]; var y = allPoints[idx + 1]; var z = allPoints[idx + 2]; var dx = ray.direction.x * (x - ray.origin.x); var dy = ray.direction.y * (y - ray.origin.y); var dz = ray.direction.z * (z - ray.origin.z); var directionDistance = dx + dy + dz; var vx = ray.direction.x * directionDistance + ray.origin.x; var vy = ray.direction.y * directionDistance + ray.origin.y; var vz = ray.direction.z * directionDistance + ray.origin.z; return (vx - x) * (vx - x) + (vy - y) * (vy - y) + (vz - z) * (vz - z); } }
Based on octree search results tries to find index of a point which is nearest to the ray in z-direction, and is closer than maxDistanceFromRay
getNearestIndex
javascript
anvaka/pm
src/galaxy/native/getNearestIndex.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/getNearestIndex.js
MIT
function byProximityToRay(x, y) { var distX = getDistanceToRay(x); var distY = getDistanceToRay(y); return distX - distY; }
Based on octree search results tries to find index of a point which is nearest to the ray in z-direction, and is closer than maxDistanceFromRay
byProximityToRay
javascript
anvaka/pm
src/galaxy/native/getNearestIndex.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/getNearestIndex.js
MIT
function getDistanceToRay(idx) { var x = allPoints[idx]; var y = allPoints[idx + 1]; var z = allPoints[idx + 2]; var dx = ray.direction.x * (x - ray.origin.x); var dy = ray.direction.y * (y - ray.origin.y); var dz = ray.direction.z * (z - ray.origin.z); var directionDistance = dx + dy + dz; var vx = ray.direction.x * directionDistance + ray.origin.x; var vy = ray.direction.y * directionDistance + ray.origin.y; var vz = ray.direction.z * directionDistance + ray.origin.z; return (vx - x) * (vx - x) + (vy - y) * (vy - y) + (vz - z) * (vz - z); }
Based on octree search results tries to find index of a point which is nearest to the ray in z-direction, and is closer than maxDistanceFromRay
getDistanceToRay
javascript
anvaka/pm
src/galaxy/native/getNearestIndex.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/getNearestIndex.js
MIT
function setOrGetLinksVisible(newValue) { if (newValue === undefined) { return linksVisible; } if (newValue) { scene.add(linkMesh); } else { scene.remove(linkMesh); } linksVisible = newValue; return linksVisible; }
Gets or sets links visibility. If you pass truthy argument sets visibility to that value. Otherwise returns current visibility
setOrGetLinksVisible
javascript
anvaka/pm
src/galaxy/native/lineView.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/lineView.js
MIT
function render(links, idxToPos, linksCount) { var jsPos = []; var jsColors = []; var r = 16000; var i = 0; var linkId = 0; var maxVisibleDistance = appConfig.getMaxVisibleEdgeLength(); for (i = 0; i < links.length; ++i) { var to = links[i]; if (to === undefined) continue; // no links for this node var fromX = idxToPos[i * 3]; var fromY = idxToPos[i * 3 + 1]; var fromZ = idxToPos[i * 3 + 2]; for (var j = 0; j < to.length; j++) { var toIdx = to[j]; var toX = idxToPos[toIdx * 3]; var toY = idxToPos[toIdx * 3 + 1]; var toZ = idxToPos[toIdx * 3 + 2]; var dist = distance(fromX, fromY, fromZ, toX, toY, toZ); if (maxVisibleDistance < dist) continue; jsPos.push(fromX, fromY, fromZ, toX, toY, toZ); jsColors.push(fromX / r + 0.5, fromY / r + 0.5, fromZ / r + 0.5, toX / r + 0.5, toY / r + 0.5, toZ / r + 0.5) } } var positions = new Float32Array(jsPos); var colors = new Float32Array(jsColors); var geometry = new THREE.BufferGeometry(); var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors, blending: THREE.AdditiveBlending, opacity:0.5, transparent: true }); geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3)); geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3)); geometry.computeBoundingSphere(); if (linkMesh) { scene.remove(linkMesh); } linkMesh = new THREE.Line(geometry, material, THREE.LinePieces); scene.add(linkMesh); }
Gets or sets links visibility. If you pass truthy argument sets visibility to that value. Otherwise returns current visibility
render
javascript
anvaka/pm
src/galaxy/native/lineView.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/lineView.js
MIT
function distance(x1, y1, z1, x2, y2, z2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2); }
Gets or sets links visibility. If you pass truthy argument sets visibility to that value. Otherwise returns current visibility
distance
javascript
anvaka/pm
src/galaxy/native/lineView.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/lineView.js
MIT
function sceneRenderer(container) { var renderer, positions, graphModel, touchControl; var hitTest, lastHighlight, lastHighlightSize, cameraPosition; var lineView, links, lineViewNeedsUpdate; var queryUpdateId = setInterval(updateQuery, 200); appEvents.positionsDownloaded.on(setPositions); appEvents.linksDownloaded.on(setLinks); appEvents.toggleSteering.on(toggleSteering); appEvents.focusOnNode.on(focusOnNode); appEvents.around.on(around); appEvents.highlightQuery.on(highlightQuery); appEvents.highlightLinks.on(highlightLinks); appEvents.accelerateNavigation.on(accelarate); appEvents.focusScene.on(focusScene); appEvents.cls.on(cls); appConfig.on('camera', moveCamera); appConfig.on('showLinks', toggleLinks); var api = { destroy: destroy }; eventify(api); return api; function accelarate(isPrecise) { var input = renderer.input(); if (isPrecise) { input.movementSpeed *= 4; input.rollSpeed *= 4; } else { input.movementSpeed /= 4; input.rollSpeed /= 4; } } function updateQuery() { if (!renderer) return; var camera = renderer.camera(); appConfig.setCameraConfig(camera.position, camera.quaternion); } function toggleSteering() { if (!renderer) return; var input = renderer.input(); var isDragToLookEnabled = input.toggleDragToLook(); // steering does not require "drag": var isSteering = !isDragToLookEnabled; appEvents.showSteeringMode.fire(isSteering); } function clearHover() { appEvents.nodeHover.fire({ nodeIndex: undefined, mouseInfo: undefined }); } function focusOnNode(nodeId) { if (!renderer) return; renderer.lookAt(nodeId * 3, highlightFocused); function highlightFocused() { appEvents.selectNode.fire(nodeId); } } function around(r, x, y, z) { renderer.around(r, x, y, z); } function setPositions(_positions) { destroyHitTest(); positions = _positions; focusScene(); if (!renderer) { renderer = unrender(container); touchControl = createTouchControl(renderer); moveCameraInternal(); var input = renderer.input(); input.on('move', clearHover); } renderer.particles(positions); hitTest = renderer.hitTest(); hitTest.on('over', handleOver); hitTest.on('click', handleClick); hitTest.on('dblclick', handleDblClick); hitTest.on('hitTestReady', adjustMovementSpeed); } function adjustMovementSpeed(tree) { var input = renderer.input(); if (tree) { var root = tree.getRoot(); input.movementSpeed = root.bounds.half * 0.02; } else { input.movementSpeed *= 2; } } function focusScene() { // need to be within timeout, in case if we are detached (e.g. // first load) setTimeout(function() { container.focus(); }, 30); } function setLinks(outLinks, inLinks) { links = outLinks; lineViewNeedsUpdate = true; updateSizes(outLinks, inLinks); renderLineViewIfNeeded(); } function updateSizes(outLinks, inLinks) { var maxInDegree = getMaxSize(inLinks); var view = renderer.getParticleView(); var sizes = view.sizes(); for (var i = 0; i < sizes.length; ++i) { var degree = inLinks[i]; if (degree) { sizes[i] = ((200 / maxInDegree) * degree.length + 15); } else { sizes[i] = 30; } } view.sizes(sizes); } function getMaxSize(sparseArray) { var maxSize = 0; for (var i = 0; i < sparseArray.length; ++i) { var item = sparseArray[i]; if (item && item.length > maxSize) maxSize = item.length; } return maxSize; } function renderLineViewIfNeeded() { if (!appConfig.getShowLinks()) return; if (!lineView) { lineView = createLineView(renderer.scene(), unrender.THREE); } lineView.render(links, positions); lineViewNeedsUpdate = false; } function toggleLinks() { if (lineView) { if (lineViewNeedsUpdate) renderLineViewIfNeeded(); lineView.toggleLinks(); } else { renderLineViewIfNeeded(); } } function moveCamera() { moveCameraInternal(); } function moveCameraInternal() { if (!renderer) return; var camera = renderer.camera(); var pos = appConfig.getCameraPosition(); if (pos) { camera.position.set(pos.x, pos.y, pos.z); } var lookAt = appConfig.getCameraLookAt(); if (lookAt) { camera.quaternion.set(lookAt.x, lookAt.y, lookAt.z, lookAt.w); } } function destroyHitTest() { if (!hitTest) return; // nothing to destroy hitTest.off('over', handleOver); hitTest.off('click', handleClick); hitTest.off('dblclick', handleDblClick); hitTest.off('hitTestReady', adjustMovementSpeed); } function handleClick(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); appEvents.selectNode.fire(getModelIndex(nearestIndex)); } function handleDblClick(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); if (nearestIndex !== undefined) { focusOnNode(nearestIndex/3); } } function handleOver(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); highlightNode(nearestIndex); appEvents.nodeHover.fire({ nodeIndex: getModelIndex(nearestIndex), mouseInfo: e }); } function highlightNode(nodeIndex) { var view = renderer.getParticleView(); var colors = view.colors(); var sizes = view.sizes(); if (lastHighlight !== undefined) { colorNode(lastHighlight, colors, defaultNodeColor); sizes[lastHighlight/3] = lastHighlightSize; } lastHighlight = nodeIndex; if (lastHighlight !== undefined) { colorNode(lastHighlight, colors, highlightNodeColor); lastHighlightSize = sizes[lastHighlight/3]; sizes[lastHighlight/3] *= 1.5; } view.colors(colors); view.sizes(sizes); } function highlightQuery(query, color, scale) { if (!renderer) return; var nodeIds = query.results.map(toNativeIndex); var view = renderer.getParticleView(); var colors = view.colors(); for (var i = 0; i < nodeIds.length; ++i) { colorNode(nodeIds[i], colors, color) } view.colors(colors); appEvents.queryHighlighted.fire(query, color); } function colorNode(nodeId, colors, color) { var colorOffset = (nodeId/3) * 4; colors[colorOffset + 0] = (color >> 24) & 0xff; colors[colorOffset + 1] = (color >> 16) & 0xff; colors[colorOffset + 2] = (color >> 8) & 0xff; colors[colorOffset + 3] = (color & 0xff); } function highlightLinks(links, color) { var lines = new Float32Array(links.length * 3); for (var i = 0; i < links.length; ++i) { var i3 = links[i] * 3; lines[i * 3] = positions[i3]; lines[i * 3 + 1] = positions[i3 + 1]; lines[i * 3 + 2] = positions[i3 + 2]; } renderer.lines(lines, color); } function cls() { var view = renderer.getParticleView(); var colors = view.colors(); for (var i = 0; i < colors.length/4; i++) { colorNode(i * 3, colors, 0xffffffff); } view.colors(colors); } function toNativeIndex(i) { return i.id * 3; } function getModelIndex(nearestIndex) { if (nearestIndex !== undefined) { // since each node represented as triplet we need to divide by 3 to // get actual index: return nearestIndex/3 } } function destroy() { var input = renderer.input(); if (input) input.off('move', clearHover); renderer.destroy(); appEvents.positionsDownloaded.off(setPositions); appEvents.linksDownloaded.off(setLinks); if (touchControl) touchControl.destroy(); renderer = null; clearInterval(queryUpdateId); appConfig.off('camera', moveCamera); appConfig.off('showLinks', toggleLinks); // todo: app events? } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
sceneRenderer
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function accelarate(isPrecise) { var input = renderer.input(); if (isPrecise) { input.movementSpeed *= 4; input.rollSpeed *= 4; } else { input.movementSpeed /= 4; input.rollSpeed /= 4; } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
accelarate
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function updateQuery() { if (!renderer) return; var camera = renderer.camera(); appConfig.setCameraConfig(camera.position, camera.quaternion); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
updateQuery
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function toggleSteering() { if (!renderer) return; var input = renderer.input(); var isDragToLookEnabled = input.toggleDragToLook(); // steering does not require "drag": var isSteering = !isDragToLookEnabled; appEvents.showSteeringMode.fire(isSteering); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
toggleSteering
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function clearHover() { appEvents.nodeHover.fire({ nodeIndex: undefined, mouseInfo: undefined }); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
clearHover
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function focusOnNode(nodeId) { if (!renderer) return; renderer.lookAt(nodeId * 3, highlightFocused); function highlightFocused() { appEvents.selectNode.fire(nodeId); } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
focusOnNode
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function around(r, x, y, z) { renderer.around(r, x, y, z); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
around
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function setPositions(_positions) { destroyHitTest(); positions = _positions; focusScene(); if (!renderer) { renderer = unrender(container); touchControl = createTouchControl(renderer); moveCameraInternal(); var input = renderer.input(); input.on('move', clearHover); } renderer.particles(positions); hitTest = renderer.hitTest(); hitTest.on('over', handleOver); hitTest.on('click', handleClick); hitTest.on('dblclick', handleDblClick); hitTest.on('hitTestReady', adjustMovementSpeed); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
setPositions
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function adjustMovementSpeed(tree) { var input = renderer.input(); if (tree) { var root = tree.getRoot(); input.movementSpeed = root.bounds.half * 0.02; } else { input.movementSpeed *= 2; } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
adjustMovementSpeed
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function focusScene() { // need to be within timeout, in case if we are detached (e.g. // first load) setTimeout(function() { container.focus(); }, 30); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
focusScene
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function setLinks(outLinks, inLinks) { links = outLinks; lineViewNeedsUpdate = true; updateSizes(outLinks, inLinks); renderLineViewIfNeeded(); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
setLinks
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function updateSizes(outLinks, inLinks) { var maxInDegree = getMaxSize(inLinks); var view = renderer.getParticleView(); var sizes = view.sizes(); for (var i = 0; i < sizes.length; ++i) { var degree = inLinks[i]; if (degree) { sizes[i] = ((200 / maxInDegree) * degree.length + 15); } else { sizes[i] = 30; } } view.sizes(sizes); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
updateSizes
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function getMaxSize(sparseArray) { var maxSize = 0; for (var i = 0; i < sparseArray.length; ++i) { var item = sparseArray[i]; if (item && item.length > maxSize) maxSize = item.length; } return maxSize; }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
getMaxSize
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function renderLineViewIfNeeded() { if (!appConfig.getShowLinks()) return; if (!lineView) { lineView = createLineView(renderer.scene(), unrender.THREE); } lineView.render(links, positions); lineViewNeedsUpdate = false; }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
renderLineViewIfNeeded
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function toggleLinks() { if (lineView) { if (lineViewNeedsUpdate) renderLineViewIfNeeded(); lineView.toggleLinks(); } else { renderLineViewIfNeeded(); } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
toggleLinks
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function moveCameraInternal() { if (!renderer) return; var camera = renderer.camera(); var pos = appConfig.getCameraPosition(); if (pos) { camera.position.set(pos.x, pos.y, pos.z); } var lookAt = appConfig.getCameraLookAt(); if (lookAt) { camera.quaternion.set(lookAt.x, lookAt.y, lookAt.z, lookAt.w); } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
moveCameraInternal
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function destroyHitTest() { if (!hitTest) return; // nothing to destroy hitTest.off('over', handleOver); hitTest.off('click', handleClick); hitTest.off('dblclick', handleDblClick); hitTest.off('hitTestReady', adjustMovementSpeed); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
destroyHitTest
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function handleClick(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); appEvents.selectNode.fire(getModelIndex(nearestIndex)); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
handleClick
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function handleDblClick(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); if (nearestIndex !== undefined) { focusOnNode(nearestIndex/3); } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
handleDblClick
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function handleOver(e) { var nearestIndex = getNearestIndex(positions, e.indexes, e.ray, 30); highlightNode(nearestIndex); appEvents.nodeHover.fire({ nodeIndex: getModelIndex(nearestIndex), mouseInfo: e }); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
handleOver
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function highlightNode(nodeIndex) { var view = renderer.getParticleView(); var colors = view.colors(); var sizes = view.sizes(); if (lastHighlight !== undefined) { colorNode(lastHighlight, colors, defaultNodeColor); sizes[lastHighlight/3] = lastHighlightSize; } lastHighlight = nodeIndex; if (lastHighlight !== undefined) { colorNode(lastHighlight, colors, highlightNodeColor); lastHighlightSize = sizes[lastHighlight/3]; sizes[lastHighlight/3] *= 1.5; } view.colors(colors); view.sizes(sizes); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
highlightNode
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function highlightQuery(query, color, scale) { if (!renderer) return; var nodeIds = query.results.map(toNativeIndex); var view = renderer.getParticleView(); var colors = view.colors(); for (var i = 0; i < nodeIds.length; ++i) { colorNode(nodeIds[i], colors, color) } view.colors(colors); appEvents.queryHighlighted.fire(query, color); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
highlightQuery
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function colorNode(nodeId, colors, color) { var colorOffset = (nodeId/3) * 4; colors[colorOffset + 0] = (color >> 24) & 0xff; colors[colorOffset + 1] = (color >> 16) & 0xff; colors[colorOffset + 2] = (color >> 8) & 0xff; colors[colorOffset + 3] = (color & 0xff); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
colorNode
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function highlightLinks(links, color) { var lines = new Float32Array(links.length * 3); for (var i = 0; i < links.length; ++i) { var i3 = links[i] * 3; lines[i * 3] = positions[i3]; lines[i * 3 + 1] = positions[i3 + 1]; lines[i * 3 + 2] = positions[i3 + 2]; } renderer.lines(lines, color); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
highlightLinks
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function cls() { var view = renderer.getParticleView(); var colors = view.colors(); for (var i = 0; i < colors.length/4; i++) { colorNode(i * 3, colors, 0xffffffff); } view.colors(colors); }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
cls
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function toNativeIndex(i) { return i.id * 3; }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
toNativeIndex
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function getModelIndex(nearestIndex) { if (nearestIndex !== undefined) { // since each node represented as triplet we need to divide by 3 to // get actual index: return nearestIndex/3 } }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
getModelIndex
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function destroy() { var input = renderer.input(); if (input) input.off('move', clearHover); renderer.destroy(); appEvents.positionsDownloaded.off(setPositions); appEvents.linksDownloaded.off(setLinks); if (touchControl) touchControl.destroy(); renderer = null; clearInterval(queryUpdateId); appConfig.off('camera', moveCamera); appConfig.off('showLinks', toggleLinks); // todo: app events? }
This is a bridge between ultrafast particle renderer and react world. It listens to graph loading events. Once graph positions are loaded it calls native renderer to show the positions. It also listens to native renderer for user interaction. When user hovers over a node or clicks on it - it reports user actions back to the global events bus. These events are later consumed by stores to show appropriate UI feedback
destroy
javascript
anvaka/pm
src/galaxy/native/renderer.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/renderer.js
MIT
function sceneKeyboardBinding(container) { var api = { destroy: destroy }; var lastShiftKey = false; container.addEventListener('keydown', keydown, false); container.addEventListener('keyup', keyup, false); return api; function destroy() { container.removeEventListener('keydown', keydown, false); container.removeEventListener('keyup', keyup, false); } function keydown(e) { if (e.which === Key.Space) { events.toggleSteering.fire(); } else if (e.which === Key.L) { // L - toggle links if (!e.ctrlKey && !e.metaKey) { events.toggleLinks.fire(); } } else if (e.which === Key.H || (e.which === Key['/'] && e.shiftKey)) { // 'h' or '?' key // Need to stop propagation, since help screen attempts to close itself // once user presses any key. We don't want that now, since this is // explicit request to render help e.stopPropagation(); events.toggleHelp.fire(); } if (e.shiftKey && !lastShiftKey) { lastShiftKey = true; events.accelerateNavigation.fire(true); } } function keyup(e) { if (lastShiftKey && !e.shiftKey) { lastShiftKey = false; events.accelerateNavigation.fire(false); } } }
This file defines special keyboard bindings for the scene. Most movement keyboard bindings are handled by `unrender` module (e.g. WASD). Here we handle additional keyboard shortcuts. For example toggle steering mode
sceneKeyboardBinding
javascript
anvaka/pm
src/galaxy/native/sceneKeyboardBinding.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/sceneKeyboardBinding.js
MIT
function destroy() { container.removeEventListener('keydown', keydown, false); container.removeEventListener('keyup', keyup, false); }
This file defines special keyboard bindings for the scene. Most movement keyboard bindings are handled by `unrender` module (e.g. WASD). Here we handle additional keyboard shortcuts. For example toggle steering mode
destroy
javascript
anvaka/pm
src/galaxy/native/sceneKeyboardBinding.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/sceneKeyboardBinding.js
MIT
function keydown(e) { if (e.which === Key.Space) { events.toggleSteering.fire(); } else if (e.which === Key.L) { // L - toggle links if (!e.ctrlKey && !e.metaKey) { events.toggleLinks.fire(); } } else if (e.which === Key.H || (e.which === Key['/'] && e.shiftKey)) { // 'h' or '?' key // Need to stop propagation, since help screen attempts to close itself // once user presses any key. We don't want that now, since this is // explicit request to render help e.stopPropagation(); events.toggleHelp.fire(); } if (e.shiftKey && !lastShiftKey) { lastShiftKey = true; events.accelerateNavigation.fire(true); } }
This file defines special keyboard bindings for the scene. Most movement keyboard bindings are handled by `unrender` module (e.g. WASD). Here we handle additional keyboard shortcuts. For example toggle steering mode
keydown
javascript
anvaka/pm
src/galaxy/native/sceneKeyboardBinding.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/sceneKeyboardBinding.js
MIT
function keyup(e) { if (lastShiftKey && !e.shiftKey) { lastShiftKey = false; events.accelerateNavigation.fire(false); } }
This file defines special keyboard bindings for the scene. Most movement keyboard bindings are handled by `unrender` module (e.g. WASD). Here we handle additional keyboard shortcuts. For example toggle steering mode
keyup
javascript
anvaka/pm
src/galaxy/native/sceneKeyboardBinding.js
https://github.com/anvaka/pm/blob/master/src/galaxy/native/sceneKeyboardBinding.js
MIT
function nodeDetailsStore() { var api = { getSelectedNode: getSelectedNode }; var currentNodeId, degreeVisible = false, currentConnectionType; appEvents.selectNode.on(updateDetails); appEvents.showDegree.on(updateDegreeDetails); eventify(api); return api; function updateDetails(nodeId) { currentNodeId = nodeId; updateDegreeDetails(currentNodeId, currentConnectionType); } function updateDegreeDetails(id, connectionType) { currentNodeId = id; degreeVisible = currentNodeId !== undefined; if (degreeVisible) { currentConnectionType = connectionType; var rootInfo = scene.getNodeInfo(id); var conenctions = scene.getConnected(id, connectionType); var viewModel = new DegreeWindowViewModel(rootInfo.name, conenctions, connectionType, id); appEvents.showNodeListWindow.fire(viewModel, 'degree'); } else { appEvents.hideNodeListWindow.fire('degree'); } api.fire('changed'); } function getSelectedNode() { if (currentNodeId === undefined) return; return getBaseNodeViewModel(currentNodeId); } }
Prepares data for selected node details
nodeDetailsStore
javascript
anvaka/pm
src/galaxy/nodeDetails/nodeDetailsStore.js
https://github.com/anvaka/pm/blob/master/src/galaxy/nodeDetails/nodeDetailsStore.js
MIT
function updateDetails(nodeId) { currentNodeId = nodeId; updateDegreeDetails(currentNodeId, currentConnectionType); }
Prepares data for selected node details
updateDetails
javascript
anvaka/pm
src/galaxy/nodeDetails/nodeDetailsStore.js
https://github.com/anvaka/pm/blob/master/src/galaxy/nodeDetails/nodeDetailsStore.js
MIT
function updateDegreeDetails(id, connectionType) { currentNodeId = id; degreeVisible = currentNodeId !== undefined; if (degreeVisible) { currentConnectionType = connectionType; var rootInfo = scene.getNodeInfo(id); var conenctions = scene.getConnected(id, connectionType); var viewModel = new DegreeWindowViewModel(rootInfo.name, conenctions, connectionType, id); appEvents.showNodeListWindow.fire(viewModel, 'degree'); } else { appEvents.hideNodeListWindow.fire('degree'); } api.fire('changed'); }
Prepares data for selected node details
updateDegreeDetails
javascript
anvaka/pm
src/galaxy/nodeDetails/nodeDetailsStore.js
https://github.com/anvaka/pm/blob/master/src/galaxy/nodeDetails/nodeDetailsStore.js
MIT
function getSelectedNode() { if (currentNodeId === undefined) return; return getBaseNodeViewModel(currentNodeId); }
Prepares data for selected node details
getSelectedNode
javascript
anvaka/pm
src/galaxy/nodeDetails/nodeDetailsStore.js
https://github.com/anvaka/pm/blob/master/src/galaxy/nodeDetails/nodeDetailsStore.js
MIT
function eventMirror(eventNames, eventBus) { var events = Object.create(null); eventNames.forEach(setActiveCommand); return events; function setActiveCommand(eventName, idx) { events[eventName] = { id: eventName, fire: fire(eventName), on: on(eventName), off: off(eventName) }; } function fire(name) { return function () { eventBus.fire.apply(this, [name].concat(Array.prototype.slice.call(arguments))); } } function on(name) { return function (callback) { eventBus.on(name, callback); } } function off(name) { return function (callback) { eventBus.off(name, callback); } } }
This is a syntax sugar wrapper which allows consumer to register events on a given event bus, later clients can have rich API to consume events. For example: // Create a simple event bus: var myBus = require('ngraph.events')({}); // Register several events on this bus: var events = eventMirror(['sayHi', 'sayBye'], myBus); // Now consumers can do: events.sayHi.fire('world'); // fire 'sayHi' event, and pass 'world' argument // this will listen to 'sayHi' event, and will print "Hello world" events.sayHi.on(function (name) { console.log('Hello ' + name); }) // it is also equivalent to myBus.fire('sayHi', 'world'); myBus.on('sayHi', function (name) { console.log('Hello ' + name); }); Why? I think having explicit place with all registered events can be beneficial for the reader. You can easily find and document all possible events in the system.
eventMirror
javascript
anvaka/pm
src/galaxy/service/eventMirror.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/eventMirror.js
MIT
function setActiveCommand(eventName, idx) { events[eventName] = { id: eventName, fire: fire(eventName), on: on(eventName), off: off(eventName) }; }
This is a syntax sugar wrapper which allows consumer to register events on a given event bus, later clients can have rich API to consume events. For example: // Create a simple event bus: var myBus = require('ngraph.events')({}); // Register several events on this bus: var events = eventMirror(['sayHi', 'sayBye'], myBus); // Now consumers can do: events.sayHi.fire('world'); // fire 'sayHi' event, and pass 'world' argument // this will listen to 'sayHi' event, and will print "Hello world" events.sayHi.on(function (name) { console.log('Hello ' + name); }) // it is also equivalent to myBus.fire('sayHi', 'world'); myBus.on('sayHi', function (name) { console.log('Hello ' + name); }); Why? I think having explicit place with all registered events can be beneficial for the reader. You can easily find and document all possible events in the system.
setActiveCommand
javascript
anvaka/pm
src/galaxy/service/eventMirror.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/eventMirror.js
MIT
function fire(name) { return function () { eventBus.fire.apply(this, [name].concat(Array.prototype.slice.call(arguments))); } }
This is a syntax sugar wrapper which allows consumer to register events on a given event bus, later clients can have rich API to consume events. For example: // Create a simple event bus: var myBus = require('ngraph.events')({}); // Register several events on this bus: var events = eventMirror(['sayHi', 'sayBye'], myBus); // Now consumers can do: events.sayHi.fire('world'); // fire 'sayHi' event, and pass 'world' argument // this will listen to 'sayHi' event, and will print "Hello world" events.sayHi.on(function (name) { console.log('Hello ' + name); }) // it is also equivalent to myBus.fire('sayHi', 'world'); myBus.on('sayHi', function (name) { console.log('Hello ' + name); }); Why? I think having explicit place with all registered events can be beneficial for the reader. You can easily find and document all possible events in the system.
fire
javascript
anvaka/pm
src/galaxy/service/eventMirror.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/eventMirror.js
MIT
function on(name) { return function (callback) { eventBus.on(name, callback); } }
This is a syntax sugar wrapper which allows consumer to register events on a given event bus, later clients can have rich API to consume events. For example: // Create a simple event bus: var myBus = require('ngraph.events')({}); // Register several events on this bus: var events = eventMirror(['sayHi', 'sayBye'], myBus); // Now consumers can do: events.sayHi.fire('world'); // fire 'sayHi' event, and pass 'world' argument // this will listen to 'sayHi' event, and will print "Hello world" events.sayHi.on(function (name) { console.log('Hello ' + name); }) // it is also equivalent to myBus.fire('sayHi', 'world'); myBus.on('sayHi', function (name) { console.log('Hello ' + name); }); Why? I think having explicit place with all registered events can be beneficial for the reader. You can easily find and document all possible events in the system.
on
javascript
anvaka/pm
src/galaxy/service/eventMirror.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/eventMirror.js
MIT
function off(name) { return function (callback) { eventBus.off(name, callback); } }
This is a syntax sugar wrapper which allows consumer to register events on a given event bus, later clients can have rich API to consume events. For example: // Create a simple event bus: var myBus = require('ngraph.events')({}); // Register several events on this bus: var events = eventMirror(['sayHi', 'sayBye'], myBus); // Now consumers can do: events.sayHi.fire('world'); // fire 'sayHi' event, and pass 'world' argument // this will listen to 'sayHi' event, and will print "Hello world" events.sayHi.on(function (name) { console.log('Hello ' + name); }) // it is also equivalent to myBus.fire('sayHi', 'world'); myBus.on('sayHi', function (name) { console.log('Hello ' + name); }); Why? I think having explicit place with all registered events can be beneficial for the reader. You can easily find and document all possible events in the system.
off
javascript
anvaka/pm
src/galaxy/service/eventMirror.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/eventMirror.js
MIT
function graph(rawGraphLoaderData) { var {labels, outLinks, inLinks, positions} = rawGraphLoaderData; var empty = []; var api = { getNodeInfo: getNodeInfo, getConnected: getConnected, find: find, findLinks: findLinks }; return api; function findLinks(from, to) { return linkFinder(from, to, outLinks, inLinks, labels); } function find(query) { var result = []; if (!labels) return result; if (typeof query === 'string') { // short circuit if it's blank string - no results if (!query) return result; query = regexMatcher(query); } for (var i = 0; i < labels.length; ++i) { if (query(i, labels, outLinks, inLinks, positions)) { result.push(getNodeInfo(i)); } } return result; } function regexMatcher(str) { var regex = compileRegex(str); if (!regex) return no; return function (i, labels, outLinks, inLinks, pos) { var label = labels[i]; if (typeof label === 'string') { return label.match(regex); } return label.toString().match(regex); } } function no() { return false; } function compileRegex(pattern) { try { return new RegExp(pattern, 'ig'); } catch (e) { // this cannot be compiled. Ignore it. } } function getConnected(startId, connectionType) { if (connectionType === 'out') { return outLinks[startId] || empty; } else if (connectionType === 'in') { return inLinks[startId] || empty; } return empty; } function getNodeInfo(id) { if (!labels) return; var outLinksCount = 0; if (outLinks[id]) { outLinksCount = outLinks[id].length; } var inLinksCount = 0; if (inLinks[id]) { inLinksCount = inLinks[id].length; } return { id: id, name: labels[id], out: outLinksCount, in : inLinksCount }; } function getName(id) { if (!labels) return ''; if (id < 0 || id > labels.length) { throw new Error(id + " is outside of labels range"); } return labels[id]; } function getPositions() { return positions; } function getLinks() { return links; } }
Wrapper on top of graph data. Not sure where it will go yet.
graph
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function findLinks(from, to) { return linkFinder(from, to, outLinks, inLinks, labels); }
Wrapper on top of graph data. Not sure where it will go yet.
findLinks
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function find(query) { var result = []; if (!labels) return result; if (typeof query === 'string') { // short circuit if it's blank string - no results if (!query) return result; query = regexMatcher(query); } for (var i = 0; i < labels.length; ++i) { if (query(i, labels, outLinks, inLinks, positions)) { result.push(getNodeInfo(i)); } } return result; }
Wrapper on top of graph data. Not sure where it will go yet.
find
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function regexMatcher(str) { var regex = compileRegex(str); if (!regex) return no; return function (i, labels, outLinks, inLinks, pos) { var label = labels[i]; if (typeof label === 'string') { return label.match(regex); } return label.toString().match(regex); } }
Wrapper on top of graph data. Not sure where it will go yet.
regexMatcher
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function compileRegex(pattern) { try { return new RegExp(pattern, 'ig'); } catch (e) { // this cannot be compiled. Ignore it. } }
Wrapper on top of graph data. Not sure where it will go yet.
compileRegex
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function getConnected(startId, connectionType) { if (connectionType === 'out') { return outLinks[startId] || empty; } else if (connectionType === 'in') { return inLinks[startId] || empty; } return empty; }
Wrapper on top of graph data. Not sure where it will go yet.
getConnected
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function getNodeInfo(id) { if (!labels) return; var outLinksCount = 0; if (outLinks[id]) { outLinksCount = outLinks[id].length; } var inLinksCount = 0; if (inLinks[id]) { inLinksCount = inLinks[id].length; } return { id: id, name: labels[id], out: outLinksCount, in : inLinksCount }; }
Wrapper on top of graph data. Not sure where it will go yet.
getNodeInfo
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function getName(id) { if (!labels) return ''; if (id < 0 || id > labels.length) { throw new Error(id + " is outside of labels range"); } return labels[id]; }
Wrapper on top of graph data. Not sure where it will go yet.
getName
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function getPositions() { return positions; }
Wrapper on top of graph data. Not sure where it will go yet.
getPositions
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function getLinks() { return links; }
Wrapper on top of graph data. Not sure where it will go yet.
getLinks
javascript
anvaka/pm
src/galaxy/service/graph.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graph.js
MIT
function loadGraph(name, progress) { var positions, labels; var outLinks = []; var inLinks = []; // todo: handle errors var manifestEndpoint = config.dataUrl + name; var galaxyEndpoint = manifestEndpoint; var manifest; return loadManifest() .then(loadPositions) .then(loadLinks) .then(loadLabels) .then(convertToGraph); function convertToGraph() { return createGraph({ positions: positions, labels: labels, outLinks: outLinks, inLinks: inLinks }); } function loadManifest() { return request(manifestEndpoint + '/manifest.json?nocache=' + (+new Date()), { responseType: 'json' }).then(setManifest); } function setManifest(response) { manifest = response; var version = getFromAppConfig(manifest) || manifest.last; if (manifest.endpoint) { // the endpoint is overridden. Since we trust manifest endpoint, we also // trust overridden endpoint: galaxyEndpoint = manifest.endpoint; } else { galaxyEndpoint = manifestEndpoint; } galaxyEndpoint += '/' + version; appConfig.setManifestVersion(version); } function getFromAppConfig(manifest) { var appConfigVersion = appConfig.getManifestVersion(); var approvedVersions = manifest && manifest.all; // default to the last version: if (!approvedVersions || !appConfigVersion) return; // If this version is whitelisted, let it through: if (approvedVersions.indexOf(appConfigVersion) >= 0) { return appConfigVersion; } } function loadPositions() { return request(galaxyEndpoint + '/positions.bin', { responseType: 'arraybuffer', progress: reportProgress(name, 'positions') }).then(setPositions); } function setPositions(buffer) { positions = new Int32Array(buffer); var scaleFactor = appConfig.getScaleFactor(); for (var i = 0; i < positions.length; ++i) { positions[i] *= scaleFactor; } appEvents.positionsDownloaded.fire(positions); } function loadLinks() { return request(galaxyEndpoint + '/links.bin', { responseType: 'arraybuffer', progress: reportProgress(name, 'links') }).then(setLinks); } function setLinks(buffer) { var links = new Int32Array(buffer); var lastArray = []; outLinks[0] = lastArray; var srcIndex; var processed = 0; var total = links.length; asyncFor(links, processLink, reportBack); var deffered = defer(); function processLink(link) { if (link < 0) { srcIndex = -link - 1; lastArray = outLinks[srcIndex] = []; } else { var toNode = link - 1; lastArray.push(toNode); if (inLinks[toNode] === undefined) { inLinks[toNode] = [srcIndex]; } else { inLinks[toNode].push(srcIndex); } } processed += 1; if (processed % 10000 === 0) { reportLinkProgress(processed / total); } } function reportLinkProgress(percent) { progress({ message: name + ': initializing edges ', completed: Math.round(percent * 100) + '%' }); } function reportBack() { appEvents.linksDownloaded.fire(outLinks, inLinks); deffered.resolve(); } return deffered.promise; } function loadLabels() { return request(galaxyEndpoint + '/labels.json', { responseType: 'json', progress: reportProgress(name, 'labels') }).then(setLabels); } function setLabels(data) { labels = data; appEvents.labelsDownloaded.fire(labels); } function reportProgress(name, file) { return function(e) { let progressInfo = { message: name + ': downloading ' + file, }; if (e.percent !== undefined) { progressInfo.completed = Math.round(e.percent * 100) + '%' } else { progressInfo.completed = Math.round(e.loaded) + ' bytes' } progress(progressInfo); }; } }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
loadGraph
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function convertToGraph() { return createGraph({ positions: positions, labels: labels, outLinks: outLinks, inLinks: inLinks }); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
convertToGraph
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function loadManifest() { return request(manifestEndpoint + '/manifest.json?nocache=' + (+new Date()), { responseType: 'json' }).then(setManifest); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
loadManifest
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function setManifest(response) { manifest = response; var version = getFromAppConfig(manifest) || manifest.last; if (manifest.endpoint) { // the endpoint is overridden. Since we trust manifest endpoint, we also // trust overridden endpoint: galaxyEndpoint = manifest.endpoint; } else { galaxyEndpoint = manifestEndpoint; } galaxyEndpoint += '/' + version; appConfig.setManifestVersion(version); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
setManifest
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function getFromAppConfig(manifest) { var appConfigVersion = appConfig.getManifestVersion(); var approvedVersions = manifest && manifest.all; // default to the last version: if (!approvedVersions || !appConfigVersion) return; // If this version is whitelisted, let it through: if (approvedVersions.indexOf(appConfigVersion) >= 0) { return appConfigVersion; } }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
getFromAppConfig
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function loadPositions() { return request(galaxyEndpoint + '/positions.bin', { responseType: 'arraybuffer', progress: reportProgress(name, 'positions') }).then(setPositions); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
loadPositions
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function setPositions(buffer) { positions = new Int32Array(buffer); var scaleFactor = appConfig.getScaleFactor(); for (var i = 0; i < positions.length; ++i) { positions[i] *= scaleFactor; } appEvents.positionsDownloaded.fire(positions); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
setPositions
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function loadLinks() { return request(galaxyEndpoint + '/links.bin', { responseType: 'arraybuffer', progress: reportProgress(name, 'links') }).then(setLinks); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
loadLinks
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function setLinks(buffer) { var links = new Int32Array(buffer); var lastArray = []; outLinks[0] = lastArray; var srcIndex; var processed = 0; var total = links.length; asyncFor(links, processLink, reportBack); var deffered = defer(); function processLink(link) { if (link < 0) { srcIndex = -link - 1; lastArray = outLinks[srcIndex] = []; } else { var toNode = link - 1; lastArray.push(toNode); if (inLinks[toNode] === undefined) { inLinks[toNode] = [srcIndex]; } else { inLinks[toNode].push(srcIndex); } } processed += 1; if (processed % 10000 === 0) { reportLinkProgress(processed / total); } } function reportLinkProgress(percent) { progress({ message: name + ': initializing edges ', completed: Math.round(percent * 100) + '%' }); } function reportBack() { appEvents.linksDownloaded.fire(outLinks, inLinks); deffered.resolve(); } return deffered.promise; }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
setLinks
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function processLink(link) { if (link < 0) { srcIndex = -link - 1; lastArray = outLinks[srcIndex] = []; } else { var toNode = link - 1; lastArray.push(toNode); if (inLinks[toNode] === undefined) { inLinks[toNode] = [srcIndex]; } else { inLinks[toNode].push(srcIndex); } } processed += 1; if (processed % 10000 === 0) { reportLinkProgress(processed / total); } }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
processLink
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function reportLinkProgress(percent) { progress({ message: name + ': initializing edges ', completed: Math.round(percent * 100) + '%' }); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
reportLinkProgress
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function reportBack() { appEvents.linksDownloaded.fire(outLinks, inLinks); deffered.resolve(); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
reportBack
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function loadLabels() { return request(galaxyEndpoint + '/labels.json', { responseType: 'json', progress: reportProgress(name, 'labels') }).then(setLabels); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
loadLabels
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function setLabels(data) { labels = data; appEvents.labelsDownloaded.fire(labels); }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
setLabels
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function reportProgress(name, file) { return function(e) { let progressInfo = { message: name + ': downloading ' + file, }; if (e.percent !== undefined) { progressInfo.completed = Math.round(e.percent * 100) + '%' } else { progressInfo.completed = Math.round(e.loaded) + ' bytes' } progress(progressInfo); }; }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
reportProgress
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function defer() { var resolve, reject; var promise = new Promise(function() { resolve = arguments[0]; reject = arguments[1]; }); return { resolve: resolve, reject: reject, promise: promise }; }
@param {string} name of the graph to be downloaded @param {progressCallback} progress notifies when download progress event is received @param {completeCallback} complete notifies when all graph files are downloaded
defer
javascript
anvaka/pm
src/galaxy/service/graphLoader.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/graphLoader.js
MIT
function request(url, options) { if (!options) options = {}; return new Promise(download); function download(resolve, reject) { var req = new XMLHttpRequest(); if (typeof options.progress === 'function') { req.addEventListener("progress", updateProgress, false); } req.addEventListener("load", transferComplete, false); req.addEventListener("error", transferFailed, false); req.addEventListener("abort", transferCanceled, false); req.open('GET', url); if (options.responseType) { req.responseType = options.responseType; } req.send(null); function updateProgress(e) { if (e.lengthComputable) { options.progress({ loaded: e.loaded, total: e.total, percent: e.loaded / e.total }); } else { options.progress({ loaded: e.loaded, }); } } function transferComplete() { if (req.status !== 200) { reject(`Unexpected status code ${req.status} when calling ${url}`); return; } var response = req.response; if (options.responseType === 'json' && typeof response === 'string') { // IE response = JSON.parse(response); } resolve(response); } function transferFailed() { reject(`Failed to download ${url}`); } function transferCanceled() { reject(`Cancelled download of ${url}`); } } }
A very basic ajax client with promises and progress reporting.
request
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function download(resolve, reject) { var req = new XMLHttpRequest(); if (typeof options.progress === 'function') { req.addEventListener("progress", updateProgress, false); } req.addEventListener("load", transferComplete, false); req.addEventListener("error", transferFailed, false); req.addEventListener("abort", transferCanceled, false); req.open('GET', url); if (options.responseType) { req.responseType = options.responseType; } req.send(null); function updateProgress(e) { if (e.lengthComputable) { options.progress({ loaded: e.loaded, total: e.total, percent: e.loaded / e.total }); } else { options.progress({ loaded: e.loaded, }); } } function transferComplete() { if (req.status !== 200) { reject(`Unexpected status code ${req.status} when calling ${url}`); return; } var response = req.response; if (options.responseType === 'json' && typeof response === 'string') { // IE response = JSON.parse(response); } resolve(response); } function transferFailed() { reject(`Failed to download ${url}`); } function transferCanceled() { reject(`Cancelled download of ${url}`); } }
A very basic ajax client with promises and progress reporting.
download
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function updateProgress(e) { if (e.lengthComputable) { options.progress({ loaded: e.loaded, total: e.total, percent: e.loaded / e.total }); } else { options.progress({ loaded: e.loaded, }); } }
A very basic ajax client with promises and progress reporting.
updateProgress
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function transferComplete() { if (req.status !== 200) { reject(`Unexpected status code ${req.status} when calling ${url}`); return; } var response = req.response; if (options.responseType === 'json' && typeof response === 'string') { // IE response = JSON.parse(response); } resolve(response); }
A very basic ajax client with promises and progress reporting.
transferComplete
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function transferFailed() { reject(`Failed to download ${url}`); }
A very basic ajax client with promises and progress reporting.
transferFailed
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function transferCanceled() { reject(`Cancelled download of ${url}`); }
A very basic ajax client with promises and progress reporting.
transferCanceled
javascript
anvaka/pm
src/galaxy/service/request.js
https://github.com/anvaka/pm/blob/master/src/galaxy/service/request.js
MIT
function sceneStore() { var loadInProgress = true; var currentGraphName; var unknownNodeInfo = { inDegree: '?', outDegree: '?' } var graph; var api = { isLoading: isLoading, getGraph: getGraph, getGraphName: getGraphName, getNodeInfo: getNodeInfo, getConnected: getConnected, find: find }; appEvents.downloadGraphRequested.on(downloadGraph); eventify(api); return api; function find(query) { return graph.find(query); } function isLoading() { return loadInProgress; } function downloadGraph(graphName) { if (graphName === currentGraphName) return; loadInProgress = true; currentGraphName = graphName; loadGraph(graphName, reportProgress).then(loadComplete); } function getGraph() { return graph; } function getGraphName() { return currentGraphName; } function getNodeInfo(nodeId) { if (!graph) { unknownNodeInfo.name = nodeId; return unknownNodeInfo; } var nodeInfo = graph.getNodeInfo(nodeId); // TODO: too tired, need to get this out from here if (currentGraphName === 'github') { nodeInfo.icon = 'https://avatars.githubusercontent.com/' + nodeInfo.name; } return nodeInfo; } function getConnected(nodeId, connectionType) { if (!graph) { return []; } return graph.getConnected(nodeId, connectionType).map(getNodeInfo); } function reportProgress(progress) { api.fire('loadProgress', progress); } function loadComplete(model) { loadInProgress = false; graph = model; api.fire('loadProgress', {}); appEvents.graphDownloaded.fire(); } }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
sceneStore
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function find(query) { return graph.find(query); }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
find
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function isLoading() { return loadInProgress; }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
isLoading
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function downloadGraph(graphName) { if (graphName === currentGraphName) return; loadInProgress = true; currentGraphName = graphName; loadGraph(graphName, reportProgress).then(loadComplete); }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
downloadGraph
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function getGraph() { return graph; }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
getGraph
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function getGraphName() { return currentGraphName; }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
getGraphName
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function getNodeInfo(nodeId) { if (!graph) { unknownNodeInfo.name = nodeId; return unknownNodeInfo; } var nodeInfo = graph.getNodeInfo(nodeId); // TODO: too tired, need to get this out from here if (currentGraphName === 'github') { nodeInfo.icon = 'https://avatars.githubusercontent.com/' + nodeInfo.name; } return nodeInfo; }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
getNodeInfo
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function getConnected(nodeId, connectionType) { if (!graph) { return []; } return graph.getConnected(nodeId, connectionType).map(getNodeInfo); }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
getConnected
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function reportProgress(progress) { api.fire('loadProgress', progress); }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
reportProgress
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function loadComplete(model) { loadInProgress = false; graph = model; api.fire('loadProgress', {}); appEvents.graphDownloaded.fire(); }
Manages graph model life cycle. The low-level rendering of the particles is handled by ../native/renderer.js
loadComplete
javascript
anvaka/pm
src/galaxy/store/scene.js
https://github.com/anvaka/pm/blob/master/src/galaxy/store/scene.js
MIT
function ProcessError(code, message) { const callee = arguments.callee; Error.apply(this, [message]); Error.captureStackTrace(this, callee); this.code = code; this.message = message; this.name = callee.name; }
@function Object() { [native code] } @param {number} code Error code. @param {string} message Error message.
ProcessError
javascript
tschaub/gh-pages
lib/git.js
https://github.com/tschaub/gh-pages/blob/master/lib/git.js
MIT
function spawn(exe, args, cwd) { return new Promise((resolve, reject) => { const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()}); const buffer = []; child.stderr.on('data', (chunk) => { buffer.push(chunk.toString()); }); child.stdout.on('data', (chunk) => { buffer.push(chunk.toString()); }); child.on('close', (code) => { const output = buffer.join(''); if (code) { const msg = output || 'Process failed: ' + code; reject(new ProcessError(code, msg)); } else { resolve(output); } }); }); }
Util function for handling spawned processes as promises. @param {string} exe Executable. @param {Array<string>} args Arguments. @param {string} cwd Working directory. @return {Promise} A promise.
spawn
javascript
tschaub/gh-pages
lib/git.js
https://github.com/tschaub/gh-pages/blob/master/lib/git.js
MIT
function Git(cwd, cmd) { this.cwd = cwd; this.cmd = cmd || 'git'; this.output = ''; }
Create an object for executing git commands. @param {string} cwd Repository directory. @param {string} cmd Git executable (full path if not already on path). @function Object() { [native code] }
Git
javascript
tschaub/gh-pages
lib/git.js
https://github.com/tschaub/gh-pages/blob/master/lib/git.js
MIT
function getCacheDir(optPath) { const dir = findCacheDir({name: 'gh-pages'}); if (!optPath) { return dir; } return path.join(dir, filenamify(optPath)); }
Get the cache directory. @param {string} [optPath] Optional path. @return {string} The full path to the cache directory.
getCacheDir
javascript
tschaub/gh-pages
lib/index.js
https://github.com/tschaub/gh-pages/blob/master/lib/index.js
MIT
function done(err) { try { callback(err); } catch (err2) { log('Publish callback threw: %s', err2.message); } }
Push a git branch to a remote (pushes gh-pages by default). @param {string} basePath The base path. @param {Object} config Publish options. @param {Function} callback Callback. @return {Promise} A promise.
done
javascript
tschaub/gh-pages
lib/index.js
https://github.com/tschaub/gh-pages/blob/master/lib/index.js
MIT
function uniqueDirs(files) { const dirs = new Set(); files.forEach((filepath) => { const parts = path.dirname(filepath).split(path.sep); let partial = parts[0] || '/'; dirs.add(partial); for (let i = 1, ii = parts.length; i < ii; ++i) { partial = path.join(partial, parts[i]); dirs.add(partial); } }); return Array.from(dirs); }
Generate a list of unique directory paths given a list of file paths. @param {Array<string>} files List of file paths. @return {Array<string>} List of directory paths.
uniqueDirs
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT
function byShortPath(a, b) { const aParts = a.split(path.sep); const bParts = b.split(path.sep); const aLength = aParts.length; const bLength = bParts.length; let cmp = 0; if (aLength < bLength) { cmp = -1; } else if (aLength > bLength) { cmp = 1; } else { let aPart, bPart; for (let i = 0; i < aLength; ++i) { aPart = aParts[i]; bPart = bParts[i]; if (aPart < bPart) { cmp = -1; break; } else if (aPart > bPart) { cmp = 1; break; } } } return cmp; }
Sort function for paths. Sorter paths come first. Paths of equal length are sorted alphanumerically in path segment order. @param {string} a First path. @param {string} b Second path. @return {number} Comparison.
byShortPath
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT
function dirsToCreate(files) { return uniqueDirs(files).sort(byShortPath); }
Generate a list of directories to create given a list of file paths. @param {Array<string>} files List of file paths. @return {Array<string>} List of directory paths ordered by path length.
dirsToCreate
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT
function copyFile(obj, callback) { let called = false; function done(err) { if (!called) { called = true; callback(err); } } const read = fs.createReadStream(obj.src); read.on('error', (err) => { done(err); }); const write = fs.createWriteStream(obj.dest); write.on('error', (err) => { done(err); }); write.on('close', () => { done(); }); read.pipe(write); }
Copy a file. @param {Object} obj Object with src and dest properties. @param {function(Error):void} callback Callback
copyFile
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT
function done(err) { if (!called) { called = true; callback(err); } }
Copy a file. @param {Object} obj Object with src and dest properties. @param {function(Error):void} callback Callback
done
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT
function makeDir(path, callback) { fs.mkdir(path, (err) => { if (err) { // check if directory exists fs.stat(path, (err2, stat) => { if (err2 || !stat.isDirectory()) { callback(err); } else { callback(); } }); } else { callback(); } }); }
Make directory, ignoring errors if directory already exists. @param {string} path Directory path. @param {function(Error):void} callback Callback.
makeDir
javascript
tschaub/gh-pages
lib/util.js
https://github.com/tschaub/gh-pages/blob/master/lib/util.js
MIT