Skip to content

Commit

Permalink
draft visualization of dot
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 20, 2023
1 parent ea98c38 commit fcb2ff1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO list

- dot files visualization
- dot: select layout, save as png, save as file
- hot keys for InfoPage
- switch monaco themes
- nice css styles
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/pages-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const FORMATS = { // + Exports/Modules
html: {extension: '.html', language: 'html', type: 'text/html'}, // HTML
log: {extension: '.log', language: 'plaintext', type: 'text/plain'},

dot: {extension: '.dot', pageType: 'Viz', language: 'dot', type: 'text/plain'},
dot: {extension: '.dot', pageType: 'viz', language: 'dot', type: 'text/plain'},
xls: {extension: '.xls', pageType: 'info', type: 'application/vnd.ms-excel'},
};

Expand Down Expand Up @@ -85,13 +85,16 @@ export class PagesCollection {
let format = FORMATS[formatName];
if (format.pageType==='info') {
var page = new InfoPage(filepath, deleteBtn, rightSide, format.type)
.addTo(this);
.addTo(this);
} else if (format.pageType==='viz') {
page = new VizPage(filepath, deleteBtn, rightSide, format.type)
.addTo(this);
} else {
page = new EditorPage(filepath, {language: format.language, readOnly: readOnly}, deleteBtn, rightSide, format.type)
.addTo(this);
}

page.fromArrayBuffer(ab);
await page.fromArrayBuffer(ab);

return page;
}
Expand Down
26 changes: 26 additions & 0 deletions src/viz-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,31 @@ import { instance } from "@viz-js/viz";
import Page from './abstract-page';

export default class VizPage extends Page {
constructor(id, deleteBtn=true, rightSide=false, mimeType='application/octet-stream') {
super(id, deleteBtn, rightSide, mimeType);
}
async fromArrayBuffer(ab){
let text = new TextDecoder('utf-8').decode(ab);
this.text = text;

let viz = await instance();
console.log(viz.engines)
let svg = viz.renderSVGElement(text, { // https://viz-js.com/api/#viz.RenderOptions
//format: 'dot', // ignored
engine: 'dot', //'circo', 'dot', 'fdp', 'neato', 'nop', 'nop1', 'nop2', 'osage', 'patchwork', 'sfdp', 'twopi'
yInvert: true,
//reduce: false,
//graphAttributes:
//nodeAttributes:
//edgeAttributes:
});
this.editorContainer.appendChild(svg);

return this;
}
getArrayBuffer() {
let text = this.text;

return new TextEncoder().encode(text).buffer;
}
}

0 comments on commit fcb2ff1

Please sign in to comment.