001/* Plot bar graphs, given arrays of doubles as inputs.
002
003 @Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the
009 above copyright notice and the following two paragraphs appear in all
010 copies of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025 PT_COPYRIGHT_VERSION 2
026 COPYRIGHTENDKEY
027 */
028package ptolemy.actor.lib.gui;
029
030import ptolemy.kernel.CompositeEntity;
031import ptolemy.kernel.util.IllegalActionException;
032import ptolemy.kernel.util.NameDuplicationException;
033import ptolemy.plot.Plot;
034
035///////////////////////////////////////////////////////////////////
036//// BarGraph
037
038/**
039 <p>A bar graph plotter.  This plotter contains an instance of the Plot
040 class from the Ptolemy plot package as a public member. Data at
041 the input, which can consist of any number of channels, are plotted
042 on this instance.  Each input channel is plotted as a separate data set.
043 Each input token is an array of doubles.</p>
044 <p>
045 The <i>iterationsPerUpdate</i> parameter can be used to fine tune
046 the display.  It can be quite expensive to generate the display, and
047 by default, this actor generates it on every firing.  If
048 <i>iterationsPerUpdate</i> is set to some integer greater than
049 one, then it specifies how many iterations should be executed
050 between updates. Thus, if <i>iterationsPerUpdate</i> = 2, then every
051 second time this actor fires, it will update the display. That is,
052 it will update its display on the first firing, the third, the
053 fifth, etc. It will, however, consume its inputs on every firing.
054 The plot is always updated in the wrapup() method.</p>
055
056 @author  Edward A. Lee
057 @version $Id$
058 @since Ptolemy II 1.0
059 @Pt.ProposedRating Yellow (eal)
060 @Pt.AcceptedRating Red (cxh)
061 */
062public class BarGraph extends ArrayPlotter {
063    /** Construct an actor with the given container and name.
064     *  @param container The container.
065     *  @param name The name of this actor.
066     *  @exception IllegalActionException If the actor cannot be contained
067     *   by the proposed container.
068     *  @exception NameDuplicationException If the container already has an
069     *   actor with this name.
070     */
071    public BarGraph(CompositeEntity container, String name)
072            throws IllegalActionException, NameDuplicationException {
073        super(container, name);
074
075        _attachText("_iconDescription", "<svg>\n" + "<rect x=\"-20\" y=\"-20\" "
076                + "width=\"40\" height=\"40\" " + "style=\"fill:lightGrey\"/>\n"
077                + "<rect x=\"-12\" y=\"-12\" " + "width=\"24\" height=\"24\" "
078                + "style=\"fill:white\"/>\n" + "<rect x=\"2\" y=\"-18\" "
079                + "width=\"4\" height=\"4\" " + "style=\"fill:grey\"/>\n"
080                + "<rect x=\"8\" y=\"-18\" " + "width=\"4\" height=\"4\" "
081                + "style=\"fill:grey\"/>\n" + "<rect x=\"14\" y=\"-18\" "
082                + "width=\"4\" height=\"4\" " + "style=\"fill:grey\"/>\n"
083                + "<rect x=\"-8\" y=\"2\" " + "width=\"4\" height=\"10\" "
084                + "style=\"fill:red\"/>\n" + "<rect x=\"-2\" y=\"-8\" "
085                + "width=\"4\" height=\"20\" " + "style=\"fill:red\"/>\n"
086                + "<rect x=\"4\" y=\"-5\" " + "width=\"4\" height=\"17\" "
087                + "style=\"fill:red\"/>\n" + "</svg>\n");
088    }
089
090    ///////////////////////////////////////////////////////////////////
091    ////                         public methods                    ////
092
093    /** If the plot has not already been created, create it.
094     *  If configurations specified by a call to configure() have not yet
095     *  been processed, process them.  This overrides the base class to
096     *  also start counting iterations, so that the
097     *  <i>iterationsPerUpdate</i> parameter works.
098     *  @exception IllegalActionException If the parent class throws it.
099     */
100    @Override
101    public void initialize() throws IllegalActionException {
102        super.initialize();
103
104        // NOTE: We assume the superclass ensures this cast is safe.
105        ((Plot) plot).setBars(true);
106        ((Plot) plot).setConnected(false);
107    }
108}