mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Updated the rxnpath1.py sample
This sample now uses a locally installed copy of Graphviz to produce an image, instead of relying on a public 'webdot' server which no longer exists.
This commit is contained in:
@@ -150,12 +150,9 @@ def write(g, el, file, d=None, format="dot"):
|
||||
b.build(element = el, diagram = d, dotfile = file, format = format)
|
||||
|
||||
|
||||
def view(url, ext = 'png'):
|
||||
if not ext in ['pdf', 'png', 'gif', 'jpg', 'svg']:
|
||||
raise 'fmt must be svg, pdf, png, gif, or jpg'
|
||||
def view(url):
|
||||
import webbrowser
|
||||
dot_server = 'http://webdot.graphviz.org/cgi-bin/webdot/'
|
||||
webbrowser.open(dot_server+url+'.dot.'+ext)
|
||||
webbrowser.open(url)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,33 +1,18 @@
|
||||
"""
|
||||
Viewing a reaction path diagram.
|
||||
|
||||
This script uses Graphviz to generate an image. You must have Graphviz installed
|
||||
and the program 'dot' must be on your path for this example to work.
|
||||
Graphviz can be obtained from http://www.graphviz.org/ or (possibly) installed
|
||||
using your operating system's package manager.
|
||||
"""
|
||||
|
||||
Viewing a reaction path diagram in a web browser.
|
||||
import os
|
||||
import sys
|
||||
|
||||
This script uses the public webdot server at webdot.graphviz.org to
|
||||
perform the rendering of the graph. You don't need to get the 'dot'
|
||||
program to use this script, but you do need to be able to put your
|
||||
output file where it can be served by your web server. You can either
|
||||
run a local server, or mount the remote directory where your web files
|
||||
are located. You could also modify this script to write the file
|
||||
locally, and then upload it to your web server.
|
||||
|
||||
"""
|
||||
|
||||
from os.path import join
|
||||
from Cantera import *
|
||||
from Cantera import rxnpath
|
||||
|
||||
import sys
|
||||
opts = sys.argv
|
||||
|
||||
#------------ site-specific configuration -----------------------------
|
||||
|
||||
# to view the diagram in a browser, set 'output_dir' to a directory that
|
||||
# is within the document tree of your web server, and set output_url to
|
||||
# the URL that accesses this directory.
|
||||
|
||||
output_dir = 'd:/www/docs'
|
||||
output_urldir = 'http://your.http.server/'
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# these lines can be replaced by any commands that generate
|
||||
# an object of a class derived from class Kinetics (such as IdealGasMix)
|
||||
@@ -43,12 +28,15 @@ d = rxnpath.PathDiagram(title = 'reaction path diagram following N',
|
||||
bold_color = 'green')
|
||||
|
||||
element = 'N'
|
||||
output_file = 'rxnpath2.dot'
|
||||
url = output_urldir+'/'+output_file
|
||||
dot_file = 'rxnpath2.dot'
|
||||
img_file = 'rxnpath2.png'
|
||||
img_path = os.path.join(os.getcwd(), img_file)
|
||||
|
||||
rxnpath.write(gas, element, join(output_dir, output_file), d)
|
||||
rxnpath.write(gas, element, dot_file, d)
|
||||
print "Wrote graphviz input file to '%s'." % os.path.join(os.getcwd(), dot_file)
|
||||
|
||||
if len(opts) > 1 and opts[1] == "-view":
|
||||
# graphics format. Must be one of png, svg, gif, or jpg
|
||||
fmt = 'svg'
|
||||
rxnpath.view(url, fmt)
|
||||
os.system('dot %s -Tpng -o%s -Gdpi=200' % (dot_file, img_file))
|
||||
print "Wrote graphviz output file to '%s'." % img_path
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "-view":
|
||||
rxnpath.view('file:///' + img_path)
|
||||
|
||||
Reference in New Issue
Block a user