[Bio] / FigWebServices / subsys_diagram.cgi Repository:
ViewVC logotype

View of /FigWebServices/subsys_diagram.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (annotate)
Tue Oct 17 18:45:13 2006 UTC (13 years, 3 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.7: +31 -21 lines
Fixed to work in Sprout.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

use HtmlPageParser;
use HTML;
use strict;
use CGI;
use Tracer;
use TemplateObject;
use SFXlate;
use FIG;

my $cgi = new CGI;
ETracing($cgi);
my $ssa = $cgi->param('ssa');
my $diagram_id = $cgi->param("diagram");

my $fig = ($cgi->param('SPROUT') ? SFXlate->new() : FIG->new());

if (!$ssa)
{
    &error("No subsystem name provided.\n");
}

if (!$diagram_id)
{
    &error("No diagram id provided.\n");
}

my $sub = $fig->get_subsystem($ssa);

$sub or &error("Subsystem $ssa not found.\n");

if ($cgi->param("image"))
{
    Trace("Image parameter specified.") if T(2);
    show_image($sub, $diagram_id);
    exit;
}

Trace("Creating template.") if T(3);
my $to = TemplateObject->new($cgi, php => 'SubsysDiagram');

my $name = $sub->get_name;

$name =~ s/_/ /g;

my($dname, $dlink, $img_link) = $sub->get_diagram($diagram_id);

#
# See if we have a html page.
#

my $diagram_html_file = $sub->get_diagram_html_file($diagram_id);
my($map, $map_name, $usemap);

if ($diagram_html_file)
{
    #
    # Parse the HTML to extract the map and map name.
    #

    my $parser = HtmlPageParser->new();
    $parser->parse_file($diagram_html_file);
    
    $map_name = $parser->{map_names}->[0];
    $map = $parser->{map}->{$map_name};
}

#
# If we have an image map, put an onload handler onto the body tag.
#

my $onload;

if ($map)
{
    $onload = qq(onload="onBodyLoad()");
}
if ($to->raw()) {
    $to->add(undef => "<html><head><title>Subsystem Diagram</title></head><body $onload>");
} else {
    Trace("Load handler is \"$onload\".") if T(3);
    $to->add(onload => $onload);
}
if ($map)
{
    my $js_url = "Html/css/coloring.js";

    $to->append(results => qq(<script src="$js_url" type="text/javascript"></script>));
    $to->append(results => &get_coloring_js($map_name, "map_div"));
}
    

$to->titles({fig_object => $fig, table_style => 'plain', fig_disk => "$FIG_Config::fig_disk/"});

$to->append(results => $cgi->h1("$name: Diagram $dname"));


if ($map)
{
    my $style = "position:relative; left:0px; top:0px;";
    $to->append(results => qq(<div id="map_div" style="$style">));
    $to->append(results => $map);
    $usemap = qq(usemap="#$map_name");
}

$to->append(results => qq(<img border="0" src="$img_link" $usemap>));

if ($map)
{
    $to->append(results => "</div>");
}

$to->append(results => "</body>");

print "CONTENT-TYPE: text/html\n\n";
print $to->finish();

exit;

sub show_image
{
    my($sub, $diagram_id) = @_;

    Trace("Opening diagram image.") if T(3);
    my($type, $fh) = $sub->open_diagram_image($diagram_id);
    Trace("Image type for $diagram_id is $type.") if T(3);
    $type or exit(0);

    binmode STDOUT;
    print $cgi->header($type);
    my $buf;

    while (read($fh, $buf, 4096))
    {
        print $buf;
    }
    close($fh);
    exit(0);
}


sub error
{
    my($err) = @_;
    my $html = [];

    push(@$html, $cgi->title("Error"));
    push(@$html, $cgi->h1("Page error"));
    push(@$html, $cgi->p($err));

    &HTML::show_page($cgi, $html, 1);
    exit;
}

sub get_coloring_js
{
    my($mapname, $divname) = @_;
    
    my $txt = <<'END';
<script language="JavaScript">
    
function onBodyLoad()
{
    colorEngine = new ActiveDiagram("%div%");
    colorEngine.load();
}

</script>

<style type="text/css">

.colored {
background-repeat:repeat;
border: 0;
border-style: solid;
margin: 0;
border: 0;
font-size: 8pt;
  /* Mozilla ignores crazy MS image filters, so it will skip the following */
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='%trans_png%');
}
/* IE ignores styles with [attributes], so it will skip the following. */
.colored[class] {
background-image: url(%trans_png%);
}}

.xcolored {
background-color: red
}

.transparent {
background-color: transparent
}
</style>
END
    $txt =~ s/%map%/$mapname/gm;
    $txt =~ s/%div%/$divname/gm;

    $txt =~ s,%trans_png%,Html/diagram_overlay.png,gm;

    return $txt;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3