@atjson/renderer-graphviz
Advanced tools
Comparing version 0.9.0 to 0.11.0
@@ -6,2 +6,29 @@ # Change Log | ||
## [0.11.0](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-graphviz@0.9.0...@atjson/renderer-graphviz@0.11.0) (2018-10-22) | ||
### ✨ New Features | ||
* ✨👑✨ Make Annotations classes instead of JS objects ([#57](https://github.com/CondeNast-Copilot/atjson/issues/57)) | ||
### 🚨 Breaking Changes | ||
* This introduces a bunch of breaking changes to AtJSON. The major change is that Annotations are now described as classes instead of a loose schema. | ||
A summary of changes are the following: | ||
⚠️ `@atjson/schema` is now deprecated. Instead of using the schema, instead use `@atjson/offset-annotations`, which provides a library of annotations that closely resemble those provided by `@atjson/schema` | ||
🃏 Schemas are now defined on a document subclass. The schema is a list of annotation classes that are used to identify annotations in the document. | ||
🛸 Any annotations not found in the schema are identified as `unknown` annotations. These annotations are available to be read and updated like any other annotation, but may have incorrect transform behavior because the text transform behavior is undefined. The default behavior should be acceptable for most cases. | ||
🕵🏾♀️ `id`s are required property on Annotations. This is used to identify annotations for speedy updating for Offset | ||
🖍 Annotations are now prefixed at rest. For the CommonMark Link annotation, it will be stored as `-commonmark-link` as the `type` and the attributes will be prefixed with `-commonmark` as well, meaning that instead of seeing `href` in the `attributes`, you will see `-commonmark-href`. When the annotation JSON is hydrated into an annotation class, prefixes are automatically removed. This prevents any collisions that may (and will) happen when converting between document types. | ||
🎨 Renderers now take `Annotation`s instead of the `attributes`. When additional context is required to render an annotation, a `context` object is passed as the second argument, which provides references to the `parent`, `next`, `previous`, and `children` annotations to the current annotation. | ||
## [0.9.0](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-graphviz@0.8.11...@atjson/renderer-graphviz@0.9.0) (2018-10-10) | ||
@@ -8,0 +35,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const hir_1 = require("@atjson/hir"); | ||
function getColor(annotation) { | ||
if (annotation.rank === -Infinity) { | ||
return 'style=filled fillcolor="#000000" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 0) { | ||
return 'style=filled fillcolor="#222222" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 10) { | ||
return 'style=filled fillcolor="#444444" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 50) { | ||
return 'style=filled fillcolor="#666666" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 100) { | ||
return 'style=filled fillcolor="#888888" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 1000) { | ||
return 'style=filled fillcolor="#AAAAAA" fontcolor="#000000"'; | ||
} | ||
else if (annotation.rank <= Number.MAX_SAFE_INTEGER) { | ||
return 'style=filled fillcolor="#CCCCCC" fontcolor="#000000"'; | ||
} | ||
else { | ||
return 'style=filled fillcolor="#FFFFFF" fontcolor="#000000"'; | ||
} | ||
} | ||
function generateGraph(hirNode, edges, nodes) { | ||
let children = hirNode.children(); | ||
let children = hirNode.children({ includeParseTokens: true }); | ||
let text = hirNode.type; | ||
if (hirNode.type === 'text' && hirNode.text != null) { | ||
text = hirNode.text; | ||
if (hirNode.type === 'text' && hirNode.attributes.text != null) { | ||
text = hirNode.annotation.attributes.text; | ||
} | ||
@@ -14,4 +40,5 @@ else { | ||
let node = { | ||
id: `${hirNode.type}${nodes.length + 1}`, | ||
id: `${hirNode.type.replace('-', '_')}${nodes.length + 1}`, | ||
label: hirNode.type, | ||
color: getColor(hirNode.annotation), | ||
text | ||
@@ -32,7 +59,7 @@ }; | ||
if (options.shape === 'record' || options.shape === 'Mrecord') { | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
} | ||
else { | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
@@ -47,2 +74,2 @@ } | ||
exports.default = GraphvizRenderer; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxxQ0FBMkM7QUFRM0MsU0FBUyxhQUFhLENBQUMsT0FBZ0IsRUFBRSxLQUEwQixFQUFFLEtBQWE7SUFDaEYsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQ2xDLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUM7SUFDeEIsSUFBSSxPQUFPLENBQUMsSUFBSSxLQUFLLE1BQU0sSUFBSSxPQUFPLENBQUMsSUFBSSxJQUFJLElBQUksRUFBRTtRQUNuRCxJQUFJLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQztLQUNyQjtTQUFNO1FBQ0wsSUFBSSxHQUFHLElBQUksQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0tBQzNDO0lBRUQsSUFBSSxJQUFJLEdBQUc7UUFDVCxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsSUFBSSxHQUFHLEtBQUssQ0FBQyxNQUFNLEdBQUcsQ0FBQyxFQUFFO1FBQ3hDLEtBQUssRUFBRSxPQUFPLENBQUMsSUFBSTtRQUNuQixJQUFJO0tBQ0wsQ0FBQztJQUNGLEtBQUssQ0FBQyx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Us7RUFDM0IsR0FBRztFQUNILENBQUM7SUFDRCxDQUFDO0NBQ0Y7QUFwQkQsbUNBb0JDIn0= |
import { HIR } from '@atjson/hir'; | ||
function getColor(annotation) { | ||
if (annotation.rank === -Infinity) { | ||
return 'style=filled fillcolor="#000000" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 0) { | ||
return 'style=filled fillcolor="#222222" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 10) { | ||
return 'style=filled fillcolor="#444444" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 50) { | ||
return 'style=filled fillcolor="#666666" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 100) { | ||
return 'style=filled fillcolor="#888888" fontcolor="#FFFFFF"'; | ||
} | ||
else if (annotation.rank <= 1000) { | ||
return 'style=filled fillcolor="#AAAAAA" fontcolor="#000000"'; | ||
} | ||
else if (annotation.rank <= Number.MAX_SAFE_INTEGER) { | ||
return 'style=filled fillcolor="#CCCCCC" fontcolor="#000000"'; | ||
} | ||
else { | ||
return 'style=filled fillcolor="#FFFFFF" fontcolor="#000000"'; | ||
} | ||
} | ||
function generateGraph(hirNode, edges, nodes) { | ||
let children = hirNode.children(); | ||
let children = hirNode.children({ includeParseTokens: true }); | ||
let text = hirNode.type; | ||
if (hirNode.type === 'text' && hirNode.text != null) { | ||
text = hirNode.text; | ||
if (hirNode.type === 'text' && hirNode.attributes.text != null) { | ||
text = hirNode.annotation.attributes.text; | ||
} | ||
@@ -12,4 +38,5 @@ else { | ||
let node = { | ||
id: `${hirNode.type}${nodes.length + 1}`, | ||
id: `${hirNode.type.replace('-', '_')}${nodes.length + 1}`, | ||
label: hirNode.type, | ||
color: getColor(hirNode.annotation), | ||
text | ||
@@ -30,7 +57,7 @@ }; | ||
if (options.shape === 'record' || options.shape === 'Mrecord') { | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
} | ||
else { | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
@@ -44,2 +71,2 @@ } | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEdBQUcsRUFBVyxNQUFNLGFBQWEsQ0FBQztBQVEzQyxTQUFTLGFBQWEsQ0FBQyxPQUFnQixFQUFFLEtBQTBCLEVBQUUsS0FBYTtJQUNoRixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDbEMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQztJQUN4QixJQUFJLE9BQU8sQ0FBQyxJQUFJLEtBQUssTUFBTSxJQUFJLE9BQU8sQ0FBQyxJQUFJLElBQUksSUFBSSxFQUFFO1FBQ25ELElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDO0tBQ3JCO1NBQU07UUFDTCxJQUFJLEdBQUcsSUFBSSxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7S0FDM0M7SUFFRCxJQUFJLElBQUksR0FBRztRQUNULEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQ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DLENBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQyxFQUFFLEVBQUUsQ0FBQyxLQUFLLE1BQU0sQ0FBQyxFQUFFLE9BQU8sS0FBSyxDQUFDLEVBQUUsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDO1NBQ25GO1FBRUQsT0FBTztnQkFDSyxPQUFPLENBQUMsS0FBSztFQUMzQixHQUFHO0VBQ0gsQ0FBQztJQUNELENBQUM7Q0FDRiJ9 |
{ | ||
"name": "@atjson/renderer-graphviz", | ||
"version": "0.9.0", | ||
"version": "0.11.0", | ||
"description": "Render documents into graphs to help with debugging", | ||
@@ -19,6 +19,6 @@ "main": "dist/commonjs/index.js", | ||
"dependencies": { | ||
"@atjson/document": "0.9.0", | ||
"@atjson/hir": "0.9.0" | ||
"@atjson/document": "0.11.0", | ||
"@atjson/hir": "0.11.0" | ||
}, | ||
"gitHead": "8d0640410453bbfc1495644c346145b502cc7400" | ||
"gitHead": "36b48214b21591d09269f01d351d805a02447369" | ||
} |
@@ -1,2 +0,2 @@ | ||
import Document from '@atjson/document'; | ||
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR, HIRNode } from '@atjson/hir'; | ||
@@ -7,10 +7,31 @@ | ||
label: string; | ||
color: string; | ||
text: string; | ||
} | ||
function getColor(annotation: Annotation) { | ||
if (annotation.rank === -Infinity) { | ||
return 'style=filled fillcolor="#000000" fontcolor="#FFFFFF"'; | ||
} else if (annotation.rank <= 0) { | ||
return 'style=filled fillcolor="#222222" fontcolor="#FFFFFF"'; | ||
} else if (annotation.rank <= 10) { | ||
return 'style=filled fillcolor="#444444" fontcolor="#FFFFFF"'; | ||
} else if (annotation.rank <= 50) { | ||
return 'style=filled fillcolor="#666666" fontcolor="#FFFFFF"'; | ||
} else if (annotation.rank <= 100) { | ||
return 'style=filled fillcolor="#888888" fontcolor="#FFFFFF"'; | ||
} else if (annotation.rank <= 1000) { | ||
return 'style=filled fillcolor="#AAAAAA" fontcolor="#000000"'; | ||
} else if (annotation.rank <= Number.MAX_SAFE_INTEGER) { | ||
return 'style=filled fillcolor="#CCCCCC" fontcolor="#000000"'; | ||
} else { | ||
return 'style=filled fillcolor="#FFFFFF" fontcolor="#000000"'; | ||
} | ||
} | ||
function generateGraph(hirNode: HIRNode, edges: Array<[Node, Node]>, nodes: Node[]): Node { | ||
let children = hirNode.children(); | ||
let children = hirNode.children({ includeParseTokens: true }); | ||
let text = hirNode.type; | ||
if (hirNode.type === 'text' && hirNode.text != null) { | ||
text = hirNode.text; | ||
if (hirNode.type === 'text' && hirNode.attributes.text != null) { | ||
text = hirNode.annotation.attributes.text; | ||
} else { | ||
@@ -21,4 +42,5 @@ text = JSON.stringify(hirNode.attributes); | ||
let node = { | ||
id: `${hirNode.type}${nodes.length + 1}`, | ||
id: `${hirNode.type.replace('-', '_')}${nodes.length + 1}`, | ||
label: hirNode.type, | ||
color: getColor(hirNode.annotation), | ||
text | ||
@@ -47,6 +69,6 @@ }; | ||
if (options.shape === 'record' || options.shape === 'Mrecord') { | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="{${node.label}|${node.text.replace(/"/g, '\\"')}}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
} else { | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}"];`).join('\n') + '\n' + | ||
dot = nodes.map(node => ` ${node.id} [label="${node.label}\\n${node.text.replace(/"/g, '\\"')}" ${node.color}];`).join('\n') + '\n' + | ||
edges.map(([parent, child]) => ` ${parent.id} -> ${child.id};`).join('\n'); | ||
@@ -53,0 +75,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59171
252
+ Added@atjson/document@0.11.0(transitive)
+ Added@atjson/hir@0.11.0(transitive)
+ Added@types/uuid@3.4.13(transitive)
+ Addeduuid@3.4.0(transitive)
- Removed@atjson/document@0.9.0(transitive)
- Removed@atjson/hir@0.9.0(transitive)
Updated@atjson/document@0.11.0
Updated@atjson/hir@0.11.0