@gram-data/gram-d3
Advanced tools
Comparing version 0.1.2 to 0.1.5
@@ -6,5 +6,6 @@ 'use strict'; | ||
var gramFormat = require('@gram-data/gram-format'); | ||
var ast = require('@gram-data/gram-ast'); | ||
var literalToValue = function literalToValue(literal) { | ||
if (gramFormat.ast.isTaggedLiteral(literal)) { | ||
if (ast.isTaggedLiteral(literal)) { | ||
switch (literal.tag) { | ||
@@ -38,3 +39,3 @@ case 'date': | ||
}); | ||
} else if (gramFormat.ast.isLiteral(recordValue)) { | ||
} else if (ast.isLiteral(recordValue)) { | ||
return literalToValue(recordValue); | ||
@@ -62,2 +63,11 @@ } else { | ||
}; | ||
var gramLinkDatum = function gramLinkDatum(source, target, id, labels, record) { | ||
return { | ||
id: id || MISSING_ID, | ||
labels: labels || [], | ||
record: record ? recordToValue(record) : {}, | ||
source: source, | ||
target: target | ||
}; | ||
}; | ||
var nodeToD3 = function nodeToD3(node) { | ||
@@ -68,17 +78,13 @@ return gramNodeDatum(node.id, node.labels, node.record); | ||
var source = function source(edge) { | ||
if (edge.direction === 'left') return gramFormat.find.rightNodeOf(edge).id || MISSING_ID; | ||
return gramFormat.find.leftNodeOf(edge).id || MISSING_ID; | ||
if (edge.direction === 'left') return edge.children[1].id || MISSING_ID; | ||
return edge.children[0].id || MISSING_ID; | ||
}; | ||
var target = function target(edge) { | ||
if (edge.direction === 'left') return gramFormat.find.leftNodeOf(edge).id || MISSING_ID; | ||
return gramFormat.find.rightNodeOf(edge).id || MISSING_ID; | ||
if (edge.direction === 'left') return edge.children[0].id || MISSING_ID; | ||
return edge.children[1].id || MISSING_ID; | ||
}; | ||
var edgeToD3 = function edgeToD3(edge) { | ||
return { | ||
id: edge.id || MISSING_ID, | ||
source: source(edge), | ||
target: target(edge) | ||
}; | ||
return gramLinkDatum(source(edge), target(edge), edge.id, edge.labels, edge.record); | ||
}; | ||
@@ -96,2 +102,3 @@ var gramParse = function gramParse(src) { | ||
exports.edgeToD3 = edgeToD3; | ||
exports.gramLinkDatum = gramLinkDatum; | ||
exports.gramNodeDatum = gramNodeDatum; | ||
@@ -98,0 +105,0 @@ exports.gramParse = gramParse; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-format"),r=function r(t){return Array.isArray(t)?t.map((function(e){return r(e)})):e.ast.isLiteral(t)?function(r){if(e.ast.isTaggedLiteral(r))switch(r.tag){case"date":return new Date(r.value);default:return r.value}else switch(r.type){case"boolean":return JSON.parse(r.value);case"integer":return Number.parseInt(r.value);case"decimal":return Number.parseFloat(r.value);default:return r.value}}(t):Object.entries(t).reduce((function(e,t){return e[t[0]]=r(t[1]),e}),{})},t=function(e,t,i){return{id:e||"_missing_id",labels:t||[],record:i?r(i):{}}},i=function(e){return t(e.id,e.labels,e.record)},n=function(r){return"left"===r.direction?e.find.rightNodeOf(r).id||"_missing_id":e.find.leftNodeOf(r).id||"_missing_id"},a=function(r){return"left"===r.direction?e.find.leftNodeOf(r).id||"_missing_id":e.find.rightNodeOf(r).id||"_missing_id"},s=function(e){return{id:e.id||"_missing_id",source:n(e),target:a(e)}};exports.edgeToD3=s,exports.gramNodeDatum=t,exports.gramParse=function(r){var t=e.parse(r);return{nodes:e.transform.mergeNodes(t).map(i),links:e.transform.mergeEdges(t).map(s),paths:[]}},exports.isGramNodeDatum=function(e){return void 0!==e.id},exports.nodeToD3=i,exports.recordToValue=r; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-format"),r=require("@gram-data/gram-ast"),t=function e(t){return Array.isArray(t)?t.map((function(r){return e(r)})):r.isLiteral(t)?function(e){if(r.isTaggedLiteral(e))switch(e.tag){case"date":return new Date(e.value);default:return e.value}else switch(e.type){case"boolean":return JSON.parse(e.value);case"integer":return Number.parseInt(e.value);case"decimal":return Number.parseFloat(e.value);default:return e.value}}(t):Object.entries(t).reduce((function(r,t){return r[t[0]]=e(t[1]),r}),{})},i=function(e,r,i){return{id:e||"_missing_id",labels:r||[],record:i?t(i):{}}},n=function(e,r,i,n,a){return{id:i||"_missing_id",labels:n||[],record:a?t(a):{},source:e,target:r}},a=function(e){return i(e.id,e.labels,e.record)},s=function(e){return n(function(e){return"left"===e.direction?e.children[1].id||"_missing_id":e.children[0].id||"_missing_id"}(e),function(e){return"left"===e.direction?e.children[0].id||"_missing_id":e.children[1].id||"_missing_id"}(e),e.id,e.labels,e.record)};exports.edgeToD3=s,exports.gramLinkDatum=n,exports.gramNodeDatum=i,exports.gramParse=function(r){var t=e.parse(r);return{nodes:e.transform.mergeNodes(t).map(a),links:e.transform.mergeEdges(t).map(s),paths:[]}},exports.isGramNodeDatum=function(e){return void 0!==e.id},exports.nodeToD3=a,exports.recordToValue=t; | ||
//# sourceMappingURL=gram-d3.cjs.production.min.js.map |
@@ -1,5 +0,6 @@ | ||
import { ast, parse, transform, find } from '@gram-data/gram-format'; | ||
import { parse, transform } from '@gram-data/gram-format'; | ||
import { isLiteral, isTaggedLiteral } from '@gram-data/gram-ast'; | ||
var literalToValue = function literalToValue(literal) { | ||
if (ast.isTaggedLiteral(literal)) { | ||
if (isTaggedLiteral(literal)) { | ||
switch (literal.tag) { | ||
@@ -33,3 +34,3 @@ case 'date': | ||
}); | ||
} else if (ast.isLiteral(recordValue)) { | ||
} else if (isLiteral(recordValue)) { | ||
return literalToValue(recordValue); | ||
@@ -57,2 +58,11 @@ } else { | ||
}; | ||
var gramLinkDatum = function gramLinkDatum(source, target, id, labels, record) { | ||
return { | ||
id: id || MISSING_ID, | ||
labels: labels || [], | ||
record: record ? recordToValue(record) : {}, | ||
source: source, | ||
target: target | ||
}; | ||
}; | ||
var nodeToD3 = function nodeToD3(node) { | ||
@@ -63,17 +73,13 @@ return gramNodeDatum(node.id, node.labels, node.record); | ||
var source = function source(edge) { | ||
if (edge.direction === 'left') return find.rightNodeOf(edge).id || MISSING_ID; | ||
return find.leftNodeOf(edge).id || MISSING_ID; | ||
if (edge.direction === 'left') return edge.children[1].id || MISSING_ID; | ||
return edge.children[0].id || MISSING_ID; | ||
}; | ||
var target = function target(edge) { | ||
if (edge.direction === 'left') return find.leftNodeOf(edge).id || MISSING_ID; | ||
return find.rightNodeOf(edge).id || MISSING_ID; | ||
if (edge.direction === 'left') return edge.children[0].id || MISSING_ID; | ||
return edge.children[1].id || MISSING_ID; | ||
}; | ||
var edgeToD3 = function edgeToD3(edge) { | ||
return { | ||
id: edge.id || MISSING_ID, | ||
source: source(edge), | ||
target: target(edge) | ||
}; | ||
return gramLinkDatum(source(edge), target(edge), edge.id, edge.labels, edge.record); | ||
}; | ||
@@ -90,3 +96,3 @@ var gramParse = function gramParse(src) { | ||
export { edgeToD3, gramNodeDatum, gramParse, isGramNodeDatum, nodeToD3, recordToValue }; | ||
export { edgeToD3, gramLinkDatum, gramNodeDatum, gramParse, isGramNodeDatum, nodeToD3, recordToValue }; | ||
//# sourceMappingURL=gram-d3.esm.js.map |
@@ -9,8 +9,9 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.5", | ||
"author": "Andreas Kollegger", | ||
"module": "dist/gram-d3.esm.js", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"module": "dist/gram-d3.esm.js", | ||
"unpkg": "dist/gram-d3.umd.production.min.js", | ||
"types": "dist/index.d.ts", | ||
"publishConfig": { | ||
@@ -28,6 +29,7 @@ "access": "public" | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"build": "tsdx build --format umd,cjs,esm", | ||
"test": "tsdx test", | ||
"test:watch": "tsdx test --watch", | ||
"lint": "tsdx lint", | ||
"lint:fix": "tsdx lint --fix", | ||
"prepare": "tsdx build", | ||
@@ -50,2 +52,4 @@ "demo": "parcel public/index.html", | ||
"@types/d3": "^5.7.2", | ||
"@types/unist": "^2.0.3", | ||
"@typescript-eslint/parser": "^3.5.0", | ||
"d3": "^5.16.0", | ||
@@ -55,2 +59,4 @@ "d3-force": "^2.0.1", | ||
"np": "^6.2.3", | ||
"npm-run-all": "^4.1.5", | ||
"shx": "^0.3.2", | ||
"tsdx": "^0.13.2", | ||
@@ -61,5 +67,7 @@ "tslib": "^2.0.0", | ||
"dependencies": { | ||
"@gram-data/gram-format": "*", | ||
"@gram-data/gram-ast": "^0.1.3", | ||
"@gram-data/gram-parse": "^0.1.3", | ||
"d3": "^5.16.0" | ||
} | ||
}, | ||
"gitHead": "5d5fef22389a739e475e24e1d07cfc0b8929c1e5" | ||
} |
@@ -1,2 +0,3 @@ | ||
import { ast, parse, transform, find } from '@gram-data/gram-format'; | ||
import * as ast from '@gram-data/gram-ast'; | ||
import { parse, transform } from '@gram-data/gram-format'; | ||
import { SimulationNodeDatum, SimulationLinkDatum } from 'd3-force'; | ||
@@ -28,4 +29,21 @@ import { recordToValue } from './record-to-object'; | ||
export const gramLinkDatum = ( | ||
source: string, | ||
target: string, | ||
id?: string, | ||
labels?: string[], | ||
record?: { [key: string]: any } | ||
) => { | ||
return { | ||
id: id || MISSING_ID, | ||
labels: labels || [], | ||
record: record ? recordToValue(record) : {}, | ||
source, | ||
target | ||
}; | ||
} | ||
export interface GramLinkDatum extends SimulationLinkDatum<GramNodeDatum> { | ||
id: string; | ||
record: { [key: string]: any }; | ||
} | ||
@@ -43,22 +61,18 @@ | ||
export const nodeToD3 = (node: ast.Node): GramNodeDatum => { | ||
export const nodeToD3 = (node: ast.GramNode): GramNodeDatum => { | ||
return gramNodeDatum(node.id, node.labels, node.record); | ||
}; | ||
const source = (edge: ast.Edge): string => { | ||
if (edge.direction === 'left') return find.rightNodeOf(edge).id || MISSING_ID; | ||
return find.leftNodeOf(edge).id || MISSING_ID; | ||
const source = (edge: ast.GramEdge): string => { | ||
if (edge.direction === 'left') return edge.children[1].id || MISSING_ID; | ||
return edge.children[0].id || MISSING_ID; | ||
}; | ||
const target = (edge: ast.Edge): string => { | ||
if (edge.direction === 'left') return find.leftNodeOf(edge).id || MISSING_ID; | ||
return find.rightNodeOf(edge).id || MISSING_ID; | ||
const target = (edge: ast.GramEdge): string => { | ||
if (edge.direction === 'left') return edge.children[0].id || MISSING_ID; | ||
return edge.children[1].id || MISSING_ID; | ||
}; | ||
export const edgeToD3 = (edge: ast.Edge): GramLinkDatum => { | ||
return { | ||
id: edge.id || MISSING_ID, | ||
source: source(edge), | ||
target: target(edge), | ||
}; | ||
export const edgeToD3 = (edge: ast.GramEdge): GramLinkDatum => { | ||
return gramLinkDatum(source(edge), target(edge), edge.id,edge.labels, edge.record) | ||
}; | ||
@@ -65,0 +79,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ast } from '@gram-data/gram-format'; | ||
import * as ast from '@gram-data/gram-ast'; | ||
@@ -7,3 +7,3 @@ export const literalToDate = (literal: ast.DateLiteral) => { | ||
export const literalToValue = (literal: ast.Literal) => { | ||
export const literalToValue = (literal: ast.GramLiteral) => { | ||
if (ast.isTaggedLiteral(literal)) { | ||
@@ -30,3 +30,3 @@ switch (literal.tag) { | ||
export const recordToValue = (recordValue: ast.RecordValue): any => { | ||
export const recordToValue = (recordValue: ast.GramRecordValue): any => { | ||
if (Array.isArray(recordValue)) { | ||
@@ -33,0 +33,0 @@ return recordValue.map(v => recordToValue(v)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
34912
351
1
3
12
+ Added@gram-data/gram-ast@^0.1.3
+ Added@gram-data/gram-parse@^0.1.3
+ Added@gram-data/gram-ast@0.1.10(transitive)
+ Added@gram-data/gram-builder@0.1.10(transitive)
+ Added@gram-data/gram-parse@0.1.10(transitive)
- Removed@gram-data/gram-format@*
- Removed@gram-data/gram-format@2.0.1(transitive)
- Removed@types/nearley@2.11.5(transitive)
- Removedbase-x@3.0.10(transitive)
- Removedcommander@5.1.0(transitive)
- Removednanoid@2.1.11(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedshortid@2.2.16(transitive)
- Removedunist-builder@2.0.3(transitive)
- Removedunist-util-inspect@6.0.1(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-children@1.1.4(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)