Giter Club home page Giter Club logo

graphvizer's Introduction

Graphvizer

Graphvizer is a Graphviz plugin for Sublime Text 3. It can render an image automatically in real time while you edit a dot language file. All you need to do is edit your file at the speed of thought, and this plugin will do the rest for you. If your dot file has syntax errors, the plugin will display relevant messages.

Features

  • Real-time rendering
  • Real-time syntax checking
  • Error message prompting
  • Support specifying layout engine
  • Support specifying output format

Usage

Note: Please ensure the file syntax is set to Graphviz (DOT). You can do this with the View -> Syntax menu or clicking the bottom right corner of Sublime Text window.

Open image window

Ctrl+Shift+G or Tools -> Graphvizer -> Open Rendered Image

ctrl+shift+g to open the image window

Open Graphvizer panel

Ctrl+Shift+X or Tools -> Graphvizer -> Show Graphvizer Panel

ctrl+shift+x to open the Graphvizer panel

Specifying layout engine

The default layout engine is dot, which can be changed in settings. You can also change it for a specific file through Tools -> Graphvizer -> Layout Engine.

Specifying output format

The default output format is png, which can be changed in settings. You can also change it for a specific file through Tools -> Graphvizer -> Output Format.

Powerful image viewer

If you think viewing images in Sublime Text is very inconvenient because it doesn't support zooming or panning, you can try Graphvizer Viewer which is created as a supplement for Graphvizer.

GraphvizerViewer

Why did I create this plugin?

Graphviz is an awesome visualization tool, but it's very inconvenient to render images manually. I have to run dot file.dot -Tpng -o file.png again and again. Besides, I don't know whether the syntax is correct or not instantly. The Atom editor has an excellent plugin called "GraphViz preview+," but I can't find any plugins like this on packagecontrol.io. Finally, I created Graphvizer.

Installation

1. Prerequisites

I can't implement the Graphviz visualization algorithm from scratch, so this plugin needs the dot command to render the image. In other words, you need to install the official Graphviz on your system.

For Linux/Mac

Use your operating system package manager (e.g. dnf, apt-get, or brew) to install Graphviz.

On my Fedora 27 X86_64, the command is:

sudo dnf install graphviz

Use dot -V to make sure you have configured all things correctly and you should see the version info of Graphviz.

For Windows

Download from here: https://graphviz.gitlab.io/download/. The installation is very simple but you need additional configuration to tell the plugin where to find the dot command.

Method 1: Add the path of dot.exe (e.g. D:\Graphviz\bin) to the PATH environment variable of your system. Then the dot command can be accessed from the command prompt (a.k.a. cmd) and this plugin can also invoke it. If you don't know how to do this, this article may help you.

Type dot -V in a Windows cmd window and hit enter. If everything is OK, you will see the version info of Graphviz.

Method 2: Specify the path of dot explicitly in plugin settings. See the full details in Configurations part.

2. Installing Graphvizer

Using Package Control (Recommended)

The easiest way to install Graphvizer is through Package Control.

Bring up the Command Palette (Ctrl+Shift+P on Linux/Windows, Cmd+Shift+P on Mac). Select Package Control: Install Package and then search for Graphvizer to install it.

Manually

git clone this project to your system or just download the zip file from GitHub and decompress it. Now you have a Graphvizer directory.

Using the Sublime Text 3 menu Preferences -> Browse Packages... to find out your package directory path. On my Windows 7, the path is D:\Sublime Text 3\Data\Packages. Move or symlink the entire Graphvizer directory into the package directory. Press Ctrl+Shift+P in Sublime and run Satisfy Dependencies. Restart Sublime. Done!

3. Upgrade

I will release a new version if someone reports a bug or if I have a new idea. You can use Package Control to upgrade this package.


Configurations

The default configurations are as follows. If you want to change some configuration, open Preferences -> Package Settings -> Graphvizer -> Settings and add configuration in the right side content according to your needs. The meaning of each configuration is explained below.

{
	// "dot_cmd_path" is the path of dot command. Here are some examples.
	// For Windows: "D:\\Graphviz\\bin\\dot.exe"
	// For Linux: "/usr/bin/dot"
	// For OSX: "/usr/bin/dot"
	// If you have added this path to the PATH environment variable, you can
	// use "dot" instead of the full absolute path.
	"dot_cmd_path": "dot",
	// If the dot command takes more than `dot_timeout` seconds, it will be
	// terminated. The default value is 3 seconds.
	"dot_timeout": 3,
	// "show_image_with" controls how to show the image.
	// The default value is "layout", so the image will be shown in a separated
	// layout by default. If you want to show it in a new window instead,
	// change the following value to "window". If you just want to show the image
	// in a new tab, change the value to "tab".
	"show_image_with": "layout",
	// "image_dir" controls where the image is saved.
	// The default value is "same" which means the image will be saved in the same
	// directory as the dot file.
	// If the value is "tmp", system temporary directory is used.
	// You can also set it to an arbitrary directory according to your needs.
	// Example for Windows: "E:\\homework\\image\\"
	// Example for Linux/OSX: "/home/haolee/image/"
	"image_dir": "same",
	// The default behavior is rendering the image in real time.
	// If set to false, the image will only be rendered when the file is saved.
	"render_in_realtime": true,
	// Default layout engine. Valid values including dot, neato, fdp, sfdp, twopi and circo.
	"default_layout_engine": "dot",
	// Default output format. Valid values including png, jpg, svg, pdf, gif, bmp, ps, ps2 and psd.
	// NOTE: the dot command also supports many other formats as detailed in the below link.
	// https://graphviz.gitlab.io/_pages/doc/info/output.html
	// You can certainly use any of them as the value of default_output_format, but these formats
	// won't be shown in Tools->Graphvizer->Output Format menu.
	"default_output_format": "png"
}

Set dot path

If you want to specify the path of you dot command, please set "dot_cmd_path" according to your system. This configuration is useful on Windows.

Set timeout for dot command

If you are editing a very large graph, the dot command may need a long time to complete and your CPU may be exhausted. For this reason, I set a timeout for dot command and it will be terminated if it takes too long to complete. You can change the timeout by setting "dot_timeout" as needed. Generally, you don't need to change this configuration.

Show the image in a new window

By default, the plugin will show the image in a separated layout.

You can also use a new window to show the image. Just change the value of "show_image_with" from "layout" to "window" and save it. This is flexible in some cases, especially when you have two monitors.

If your monitor is small, you may want to show the image in a new tab to save space. To do this, change the value to "tab".

(You may need to restart Sublime Text 3 to take effect.)

Set the image directory

By default, the value of "image_dir" is "same" which means the generated image will be saved in the same directory as the dot file. If the value is "tmp", the image will be saved in system temporary directory. If you want to change the location to another directory, you can set "image_dir" to any path according to your needs.

Example for Windows: "E:\\homework\\image\\" Example for Linux/OSX: "/home/haolee/image/"

Render the image when the file is saved

By default, the image is rendered in real time. If you only want the image to be rendered when the file is saved, you can set "render_in_realtime" to false.

Set the default layout engine

By default, this plugin uses dot engine to render images just as you pass -Kdot argument to dot command. If you want to use other engines including neato, fdp, sfdp, twopi and circo, set "default_layout_engine" to the engine name.

Set the default output format

By default, the output format is png just as you pass -Tpng argument to dot command. If you want to use other formats including png, jpg, svg, pdf, gif, bmp, ps, ps2 and psd, set "default_output_format" to the format name.

Key Bindings

You can change the default key bindings through Preferences -> Package Settings -> Graphvizer -> Key Bindings. In the right side column of the opened window, set "keys" to other shortcuts according to your needs. The below example is for Windows.

[
	{
		"keys": ["ctrl+shift+g"],
		"command": "open_image",
		"context":
		[
			{"key": "selector", "operator": "equal", "operand": "source.dot"}
		]
	},
	{
		"keys": ["ctrl+shift+x"],
		"command": "show_panel",
		"args": {"panel": "output.graphvizer_panel"},
		"context":
		[
			{"key": "selector", "operator": "equal", "operand": "source.dot"}
		]
	}
]

To-Do List

  • Configure the dot command path in Settings.
  • Key Bindings for Window/Linux/OSX separately.
  • Add Preferences -> Package Settings menu items to custom user settings.
  • Being able to show the image in a separated layout.
  • Set timeout for dot command.
  • Being able to set the image directory.
  • Render the image when the file is saved.
  • Support specifying image output format
  • Supporting specifying layout engine
  • Introduce Graphvizer Viewer
  • Save the image in the same directory as the dot file by default
  • Set cwd for dot command to support shapefile attribute
  • Integrate GraphvizerViewer with Graphvizer
  • Extend dot language grammar to support variable definition, loop and if-else statements.
  • For other features, please open an issue.

LICENSE

GNU GENERAL PUBLIC LICENSE Version 2 (GPLv2)

graphvizer's People

Contributors

hao-lee avatar michaelblyons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

graphvizer's Issues

'Loading image...' gets displayed but no image gets displayed Mac OS High Sierra

Hi hao-lee,

Excellent initiative! I've been dreaming of something like this for ages. I tried to install it on my Mac (High Sierra 10.13.6). The Graph does not get displayed.

I though it might be a permissions issue for the temporary folder, so I created a specific temp folder in the user settings, but Graphvizer is still trying to access the system temp folder.

my 'dot' is on the path, I can type 'dot - v' in the Terminal and I get a version.

Would love to get this working on my machine.

Thanks,
Andrew Magerman

screen shot 2019-02-04 at 11 01 43
screen shot 2019-02-04 at 11 01 28

Does not work on windows 10

  1. cmd dot -V shows 2.38 version.
  2. Graphvizer installed manually.
  3. Syntax is set to Graphviz (DOT).

Graphvizer -> Open Rendered Image
is not availiable.

Graphvizer -> Show Graphvizer Panel
shows empty window.

image

Ability to generate on save

I have pretty big graph and it took much time to generate image. The ability to generate only on save or on another event may be pretty helpful.

UTF8 text is not supported?

It seems that UTF8 text is not supported.

graph {
	图
}

and the error in console:

[2020-03-24 11:56:51] - Lexical Error: line 2, column 1: token recognition error at: '图'

Feature Request: Display Custom Images

Hi,

Thank you so much for this wonderful plugin! :-)

I have a feature request, that hopefully would add value.

Would it be possible to also render custom images? I think the screen shot below describe it best, but at a high level, I have some custom images I like to use for nodes, and it would be helpful if they also rendered in the previewer.

digraph G {

    compound = true;

    label = "Machine Architecture";
    labelloc = "t";
    fontsize = 30;

    {
        node [shape=box];
        Machine0 [label = "", penwidth=0, shapefile="pc.png", width=0.5, height=0.5, fixedsize="true"];
        MachineX [label = "MachineX"];
        MachineY [label = "MachineY"];
    }

    {
        rank = same;
        MachineX MachineY;
    }

   Machine0 -> MachineX -> MachineY;

}


Previewer

image



dot -Tpng dummy-file.dot -o sample-diagram.png

image

TimeoutExpired exception not found

Hi!
Plugin often crashes lately with the following output in the console:

indexing [job 63]: no files were indexed out of the 54 queued, abandoning crawl
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Users/***/Library/Application Support/Sublime Text 3/Packages/Graphvizer/graphvizer.py", line 72, in dot_thread
    stdout, stderr = process.communicate(timeout=self.dot_timeout)
  File "./python3.3/subprocess.py", line 920, in communicate
  File "./python3.3/subprocess.py", line 1556, in _communicate
  File "./python3.3/subprocess.py", line 1644, in _communicate_with_poll
  File "./python3.3/subprocess.py", line 946, in _check_timeout
subprocess.TimeoutExpired: Command '['dot', '/var/folders/0y/m29sdh053119js5w5rtg58740000gn/T/graphvizer.dot', '-Tpng', '-o', '/var/folders/0y/m29sdh053119js5w5rtg58740000gn/T/graphvizer.png']' timed out after 3 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./python3.3/threading.py", line 901, in _bootstrap_inner
  File "./python3.3/threading.py", line 858, in run
  File "/Users/***/Library/Application Support/Sublime Text 3/Packages/Graphvizer/graphvizer.py", line 73, in dot_thread
    except TimeoutExpired:
NameError: global name 'TimeoutExpired' is not defined

I guess changing except TimeoutExpired: to except subprocess.TimeoutExpired: will fix the issue

Image has not been rendered

Graphvizer Installation? Done!
Set the language to Graphviz(dot)? Done!

Digraph G {
123
}

CTRL+SHIFT+G

"Image has not been rendered" WHY?

"Open Rendered Image" greyed out & inactive Graphvizer panel

Hello,
Thank you for developing this plug-in which i believe can be super helpful!
I've been going through all the steps you wrote to install and run it. Unfortunately, even though I installed it, it seems that its main functionalities do not work properly for me.
The "Open Rendered Image" command is greyed out (so I cannot run it), and the Graphvizer panel does not react to the code I write above. Any idea what I should do to fix it?
I'm running on windows 10.
Best
Paul

bugs

Queue being overflowed on frequent changes in source

Hello!
Thank you for great package, it's very convenient and really saves a lot of time for me!

There's one problem though: if you make a lot of frequent changes the rendering queue is being overflowed because package tends to render EACH of the intermediate changes. You can easily simulate this issue by adding a node with label and starting furiously clapping on random keys adding symbols to label. At some moment sublime text starts responding very slowly (see attached gif). I can live with ST being a bit slow but if the diagram is big, it just freezes and I have to restart it.

I've provided a simple solution below. Adding these two lines of code we tell rendering thread to only process the most recent change, skipping all the intermediate ones (which is exactly what we expect from it). It works for me, ST no longer freezes.

I don't mind if you find another solution, it's the solving of the issue what I am concerned about.

Thank you!

gr

Same situation after this fix applied:

gr2

Solution:

def dot_thread(self):
	while True:
		while self.queue_rendering.qsize() > 1:  # added line 1
			self.queue_rendering.get()  # added line 2
		contents = self.queue_rendering.get(block=True, timeout=None)

'dot' is not recognized as an internal or external command

I don't have the dot.exe location in my path, so I set the setting dot_cmd_path to the full path of dot.exe.

{
	"dot_cmd_path": "C:\\Graphviz\\bin\\dot.exe"
}

When I build, it seems the path from settings is not used. It is just calling dot.

Output:

'dot' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 57ms with exit code 1]
[shell_cmd: dot "C:\Whatever\TheName.dot" -O -Tpng]

Sublime Text 4166
Windows 10

Navigating in image

It would be nice to navigate from one part of the graph to another holding left mouse button (like in Photoshop space button) and zoom-in zoom-out holding right mouse button (like in Photoshop z button). Using SVG would be more useful for zooming instead of PNG.

Image not displaying when viewing HTML document in Chrome

Hi there

I am very new to HTML (have only been learning for a day or so) I watched a youtube tutorial and followed every step but the result is not the same so I guess I need someone who know a lot more about HTML than me to have a look.
Screenshot 2021-10-11 at 22 14 06
.
See the screen shot attached, all i am trying to do is place an image in a table row but each time input the attached code I just get the 'loading image' icon rather than the image itself: please help.

Unable to render images, Python and Permission errors?

Problem: Graphvizer does not render new images on edit, save, or build on a fresh installation.
Sublime Console Output on Startup:

DPI mode: per-monitor v2
startup, version: 3211 windows x64 channel: stable
executable: /C/Program Files/Sublime Text 3/sublime_text.exe
working dir: /C/Program Files/Sublime Text 3
packages path: /C/Users/../AppData/Roaming/Sublime Text 3/Packages
state path: /C/Users/../AppData/Roaming/Sublime Text 3/Local
zip path: /C/Program Files/Sublime Text 3/Packages
zip path: /C/Users/../AppData/Roaming/Sublime Text 3/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.098884
startup time: 0.143884
first paint time: 0.145884
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.detect_indentation
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.install_package_control
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin ShellScript.ShellScript
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.50-enum
reloading plugin 0_package_control_loader.50-typing
reloading plugin Graphvizer.graphvizer
reloading plugin Graphvizer.syntaxchecker
reloading plugin Package Control.1_reloader
reloading plugin Package Control.2_bootstrap
reloading plugin Package Control.Package Control
plugins loaded
Exception in thread Thread-1:
Traceback (most recent call last):
  File "./python3.3/subprocess.py", line 1104, in _execute_child
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./python3.3/threading.py", line 901, in _bootstrap_inner
  File "./python3.3/threading.py", line 858, in run
  File "C:\Users\..\AppData\Roaming\Sublime Text 3\Installed Packages\Graphvizer.sublime-package\graphvizer.py", line 112, in dot_thread
    cwd=self.get_cwd(view))
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1110, in _execute_child
PermissionError: [WinError 5] Access is denied

Package Control: Skipping automatic upgrade, last run at 2020-09-30 14:01:13, next run at 2020-09-30 15:01:13 or after

Procedure followed

Versions
Windows 10 x64 (1903)
Sublime V3.2.2 (3211)
Python3 V3.8.6
Graphviz V2.44.1 (20200629.0800)

Process
0. A recent copy of Python3 and GraphViz are installed and were previously added to my system path.

  1. I installed Graphvizer on a fresh installation of Sublime via the Package Manager.
  2. I opened the settings config via Preferences -> Package Settings -> Graphizer -> Settings.
  3. Added dot path and changed display setting (see attachments).
    Graphvizer:sublime-settings -- User

// Settings in here override those in the left side

{
"dot_cmd_path": "C:\Program Files (x86)\GraphViz\bin",
"show_image_with": "tab",
}

  1. Began a new file, set the syntax to "Graphviz (DOT)" via View -> Syntax.
  2. Created a new file, Edited, Saved, Deleted, and repeat for the following code:
    example.dot
digraph example {
	node1 [
		shape=record,
		label="<f0> test"
	];
	node1:f0->a;
	a->b->c;
	b->e;
}
  1. Manually generated the image from command prompt.
    image
  2. Edited, saved, example.dot. No render occurred.
  3. Ran sublime with and without administrative permissions (steps 3-6).
    image

Saving the image

Hi,

I don't know if I am just blind but I would really enjoy being able to set where the resulting image is saved.
I am having problems running my dot script in the Terminal. But Sublime + Graphvizer work perfectly, so it would be great to not have to deal with the tmp-directory or the Terminal but just save it where I need it.

Thank you for the great package!

v3 is not live

Did you forget to git push --tags, or are you still getting more stuff ready? 😉

实时渲染时,日志输出的字符串有问题

系统:win10
版本:st3

如果输入一个错误的属性值,日志输出面板打印的错误信息是字节数组,而非字符串。

例如:

[2020-03-04 20:37:59] - [87, 97, 114, 110, 105, 110, 103, 58, 32, 65, 114, 114, 111, 119, 32, 116, 121, 112, 101, 32, 34, 115, 34, 32, 117, 110, 107, 110, 111, 119, 110, 32, 45, 32, 105, 103, 110, 111, 114, 105, 110, 103, 13, 10]

我尝试解决了一下,应该跟 subprocess 库的 communicate 函数返回值处理有关。
我改了下面的代码:

if len(stdout) != 0:
	self.print(stdout.decode().strip())
if len(stderr) != 0:
	self.print(stderr.decode().strip())

修改之后,日志打印正常:

[2020-03-04 21:25:43] - Warning: Arrow type "s" unknown - ignoring

Execution limits would be very helpful

Basically, I'm working on a graph with ~2000 nodes and ~3000 edges.

Feeding this to graphvis natively makes it completely poop itself. dot.exe spun using all of a core for about 10 minutes before I killed it.

Right now, every time I save the file in the editor, it re-spawns dot.

It'd be nice if there was a way to say "if dot takes more then n seconds, just kill it".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.