1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
package Graphviz;
CREDIT graphviz
Graph Visualization Software, originally developed by AT&T.
http://www.graphviz.org/
# path to the dot program
custom $dot;
# path to the neato program
custom $neato;
CONFIGURE {
find_program($dot, "dot", { prompt => "the `dot' program from the graphviz package" })
and
$neato= $dot =~ s/\bdot$/neato/r;
}
use Graphviz;
use BackgroundViewer;
# @category Visualization
# Use [[wiki:external_software#graphviz|graphviz]] to draw graphs and face lattices.
label graphviz
package Graphviz::Viewer;
use Polymake::Struct [ '@ISA' => 'SimpleViewer' ];
sub file_suffix { ".dot" }
sub command {
my ($self, $dotfile)=@_;
(my $psfile=$dotfile) =~ s/\.dot/.ps/;
$self->graphics->command . " -Tps -o$psfile $dotfile; $Postscript::viewer $psfile"
}
global_method graphviz.graph: draw(Visual::Graph) {
my ($self, $Graph)=@_;
$self->graphics->addGraph($Graph);
}
global_method graphviz.lattice: draw(Visual::Lattice) {
my ($self, $Lattice)=@_;
$self->graphics->addLattice($Lattice);
}
prefer graphviz.lattice
# Writes to a dot file without Postscript conversion
package Graphviz::File::Writer;
import Visual::FileWriter;
###########################################################################################
package application;
# @category Visualization
# Draw the given graph or face lattice object using [[wiki:external_software#graphviz|graphviz]] program
# ''neato'' or ''dot'' respectively.
# The output is rendered in PostScript format and fed into a viewer program, if one is configured.
# If you prefer to produce another output format, please use the //File// option and call the ''neato''
# or ''dot'' program manually.
#
# @param Visual::Object vis_obj ... objects to display
#
# @option [complete file] String File "filename" or "AUTO"
# Store the graph description in a DOT source file without starting the interactive GUI.
# The ''.dot'' suffix is automatically added to the file name.
#
# Specify //AUTO// if you want the filename be automatically derived
# from the drawing title.
#
# You can also use any expression allowed for the ''open'' function,
# including "-" for terminal output, "&HANDLE" for an already opened file handle,
# or "| program" for a pipe.
#
# @example [notest] The following creates a star graph with 4 nodes and visualizes it via graphviz with default options:
# > $g = new Graph<Undirected>(ADJACENCY=>[[],[0],[0],[0]]);
# > graphviz($g->VISUAL);
# The following shows some modified visualization style of the same graph:
# > $g = new Graph<Undirected>(ADJACENCY=>[[],[0],[0],[0]]);
# > graphviz($g->VISUAL(NodeColor=>"green",EdgeColor=>"purple",EdgeThickness=>5));
user_function graphviz(Visual::Object+, { File => undef }) {
visualize_explicit(@_, "Graphviz");
}
# Local Variables:
# mode: perl
# cperl-indent-level:3
# End:
|