Skip to content

Commit

Permalink
Use the new dot writer
Browse files Browse the repository at this point in the history
* removes the "preparedGraph" middle man between the parser and the dot
  writer
* delete the old code

refs #10
  • Loading branch information
ryepup committed Jan 16, 2017
1 parent 35c6670 commit ed2b9ae
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 346 deletions.
51 changes: 0 additions & 51 deletions src/core/codegen.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
import Viz from 'viz.js'
import lz from 'lz-string';
import dotExporter from './dot/dot'

/**
* resolve any links into a exporter-friendly format
*/
export const prepareForRendering = (graph, zoomNodeId) => {

const visibleIds = zoomNodeId
? graph.idMap[zoomNodeId]
.children
.map(x => x.id)
.concat(graph.roots)
: graph.roots

const isIdVisible = x => visibleIds.includes(x)
const toGraphableEdge = edge => {
const srcOk = isIdVisible(edge.sourceId)
const dstOk = isIdVisible(edge.destinationId)

const {type, id, description} = edge;

return {
type, id, description,
sourceId: srcOk
? edge.sourceId
: edge.sourceParentIds.find(isIdVisible),
destinationId: dstOk
? edge.destinationId
: edge.destinationParentIds.find(isIdVisible),
implicit: !(srcOk && dstOk)
}
}
const visibleEdges = graph.edges
.filter(x => isIdVisible(x.sourceId) || isIdVisible(x.destinationId))
.map(toGraphableEdge)

const toGraphableItem = id => {
const {type, name, description, tech, parentId} = graph.idMap[id]
return { type, id, name, description, tech, parentId }
}

return {
items: visibleIds.map(toGraphableItem),
edges: visibleEdges
};
}

/**
* convert a graph from DOT text to SVG
Expand Down Expand Up @@ -81,8 +35,3 @@ export const toPngDataUri = (dot, createElement) => {
img.setAttribute("src", "data:image/svg+xml," + encodeURIComponent(svg))
})
}

/**
* convert a graph to DOT
*/
export const toDot = dotExporter
37 changes: 0 additions & 37 deletions src/core/codegen.spec.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/dot/container.template.dot

This file was deleted.

122 changes: 0 additions & 122 deletions src/core/dot/dot.js

This file was deleted.

32 changes: 0 additions & 32 deletions src/core/dot/dot.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion src/core/dot/edge.template.dot

This file was deleted.

3 changes: 0 additions & 3 deletions src/core/dot/empty.dot

This file was deleted.

43 changes: 0 additions & 43 deletions src/core/dot/graph.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/dot/item.template.dot

This file was deleted.

10 changes: 0 additions & 10 deletions src/core/dot/simple.dot

This file was deleted.

17 changes: 0 additions & 17 deletions src/core/dot/two-actors.dot

This file was deleted.

5 changes: 0 additions & 5 deletions src/core/dot/zoomed.template.dot

This file was deleted.

5 changes: 3 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { parse, SyntaxError } from './parse'
export { uriEncode, uriDecode, prepareForRendering, toSvg, toDot } from './codegen'
export { uriEncode, uriDecode, toSvg } from './codegen'
export { Storage } from './storage'
export { Exporter, formats } from './exporter'
export { Exporter, formats } from './exporter'
export { toDot } from './dot-writer'
8 changes: 2 additions & 6 deletions src/shell/app.component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import template from './app.html'
import sample from './c4lab.sexp'

import { Storage, prepareForRendering, toSvg, Exporter, formats, toDot } from '../core'
import { Storage, toSvg, Exporter, formats, toDot } from '../core'

export class AppController {

Expand Down Expand Up @@ -37,11 +37,7 @@ export class AppController {

recalculate() {
this.log.debug('recalculate', this.graph)
this.preparedGraph = prepareForRendering(this.graph, this.selectedRoot)
this.dot = toDot(
() => null,
this.preparedGraph,
this.graph.idMap[this.selectedRoot])
this.dot = toDot(this.graph, this.selectedRoot)
this.svg = this.toSvg(this.dot)
}

Expand Down
5 changes: 0 additions & 5 deletions src/shell/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
<!-- TODO: a disabled text area -->
<pre>{{$ctrl.dot}}</pre>
</uib-tab>
<uib-tab heading="json">
<p>This is for debugging purposes</p>
<!-- TODO: a disabled text area -->
<pre>{{$ctrl.preparedGraph | json}}</pre>
</uib-tab>
</uib-tabset>
</div>
</div>
Expand Down

0 comments on commit ed2b9ae

Please sign in to comment.