001/* 002 Copyright (c) 2011-2014 The Regents of the University of California. 003 All rights reserved. 004 Permission is hereby granted, without written agreement and without 005 license or royalty fees, to use, copy, modify, and distribute this 006 software and its documentation for any purpose, provided that the above 007 copyright notice and the following two paragraphs appear in all copies 008 of this software. 009 010 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 011 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 012 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 013 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 014 SUCH DAMAGE. 015 016 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 017 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 019 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 020 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 021 ENHANCEMENTS, OR MODIFICATIONS. 022 023 PT_COPYRIGHT_VERSION_2 024 COPYRIGHTENDKEY 025 */ 026 027package ptolemy.plot; 028 029import java.io.IOException; 030import java.io.InputStream; 031import java.io.PrintWriter; 032import java.net.URL; 033 034/////////////////////////////////////////////////////////////////// 035//// PlotInterface 036 037/** 038 * Definitions for an object that plots data. 039 * @author ahuseyno 040 * @version $Id$ 041 * @since Ptolemy II 10.0 042 * @Pt.ProposedRating Red (cxh) 043 * @Pt.AcceptedRating Red (cxh) 044 */ 045public interface PlotInterface extends PlotBoxInterface { 046 @Override 047 public void addLegend(int dataset, String legend); 048 049 /** In the specified data set, add the specified x, y point to the 050 * plot. Data set indices begin with zero. If the data set 051 * does not exist, create it. The fourth argument indicates 052 * whether the point should be connected by a line to the previous 053 * point. Regardless of the value of this argument, a line will not 054 * drawn if either there has been no previous point for this dataset 055 * or setConnected() has been called with a false argument. 056 * <p> 057 * In order to work well with swing and be thread safe, this method 058 * actually defers execution to the event dispatch thread, where 059 * all user interface actions are performed. Thus, the point will 060 * not be added immediately (unless you call this method from within 061 * the event dispatch thread). All the methods that do this deferring 062 * coordinate so that they are executed in the order that you 063 * called them. 064 * 065 * @param dataset The data set index. 066 * @param x The X position of the new point. 067 * @param y The Y position of the new point. 068 * @param connected If true, a line is drawn to connect to the previous 069 * point. 070 */ 071 public default void addPoint(final int dataset, final double x, 072 final double y, final boolean connected) { 073 addPoint(dataset, x, y, null, connected); 074 } 075 076 /** In the specified data set, add the specified x, y point to the 077 * plot, with derivatives optionally provided for polynomial 078 * extrapolation. Data set indices begin with zero. If the data set 079 * does not exist, create it. The fourth argument indicates 080 * whether the point should be connected by a line to the previous 081 * point. Regardless of the value of this argument, a line will not 082 * drawn if either there has been no previous point for this dataset 083 * or setConnected() has been called with a false argument. 084 * <p> 085 * In order to work well with swing and be thread safe, this method 086 * actually defers execution to the event dispatch thread, where 087 * all user interface actions are performed. Thus, the point will 088 * not be added immediately (unless you call this method from within 089 * the event dispatch thread). All the methods that do this deferring 090 * coordinate so that they are executed in the order that you 091 * called them. 092 * 093 * @param dataset The data set index. 094 * @param x The X position of the new point. 095 * @param y The Y position of the new point. 096 * @param derivatives The derivatives at the new point (optional). 097 * (The array will be copied as needed.) 098 * @param connected If true, a line is drawn to connect to the previous 099 * point. 100 */ 101 public void addPoint(final int dataset, final double x, final double y, 102 final double[] derivatives, final boolean connected); 103 104 /** In the specified data set, add the specified x, y point to the 105 * plot with error bars. Data set indices begin with zero. If 106 * the dataset does not exist, create it. yLowEB and 107 * yHighEB are the lower and upper error bars. The sixth argument 108 * indicates whether the point should be connected by a line to 109 * the previous point. 110 * The new point will be made visible if the plot is visible 111 * on the screen. Otherwise, it will be drawn the next time the plot 112 * is drawn on the screen. 113 * This method is based on a suggestion by 114 * Michael Altmann (michael@email.labmed.umn.edu). 115 * <p> 116 * In order to work well with swing and be thread safe, this method 117 * actually defers execution to the event dispatch thread, where 118 * all user interface actions are performed. Thus, the point will 119 * not be added immediately (unless you call this method from within 120 * the event dispatch thread). All the methods that do this deferring 121 * coordinate so that they are executed in the order that you 122 * called them. 123 * 124 * @param dataset The data set index. 125 * @param x The X position of the new point. 126 * @param y The Y position of the new point. 127 * @param derivatives The derivatives at the new point. 128 * (The array will be copied as needed.) 129 * @param yLowEB The low point of the error bar. 130 * @param yHighEB The high point of the error bar. 131 * @param connected If true, a line is drawn to connect to the previous 132 * point. 133 */ 134 public void addPointWithErrorBars(final int dataset, final double x, 135 final double y, final double[] derivatives, final double yLowEB, 136 final double yHighEB, final boolean connected); 137 138 /** Clear the plot of all data points. If the argument is true, then 139 * reset all parameters to their initial conditions, including 140 * the persistence, plotting format, and axes formats. 141 * For the change to take effect, you must call repaint(). 142 * @param format If true, clear the format controls as well. 143 * <p> 144 * In order to work well with swing and be thread safe, this method 145 * actually defers execution to the event dispatch thread, where 146 * all user interface actions are performed. Thus, the clear will 147 * not be executed immediately (unless you call this method from within 148 * the event dispatch thread). All the methods that do this deferring 149 * coordinate so that they are executed in the order that you 150 * called them. 151 */ 152 @Override 153 public void clear(final boolean format); 154 155 /** Clear the plot of data points in the specified dataset. 156 * This calls repaint() to request an update of the display. 157 * <p> 158 * In order to work well with swing and be thread safe, this method 159 * actually defers execution to the event dispatch thread, where 160 * all user interface actions are performed. Thus, the point will 161 * not be added immediately (unless you call this method from within 162 * the event dispatch thread). If you call this method, the addPoint() 163 * method, and the erasePoint() method in any order, they are assured 164 * of being processed in the order that you called them. 165 * 166 * @param dataset The dataset to clear. 167 */ 168 public void clear(final int dataset); 169 170 /** Erase the point at the given index in the given dataset. If 171 * lines are being drawn, these lines are erased and if necessary new 172 * ones will be drawn. The point is not checked to 173 * see whether it is in range, so care must be taken by the caller 174 * to ensure that it is. 175 * <p> 176 * In order to work well with swing and be thread safe, this method 177 * actually defers execution to the event dispatch thread, where 178 * all user interface actions are performed. Thus, the point will 179 * not be erased immediately (unless you call this method from within 180 * the event dispatch thread). All the methods that do this deferring 181 * coordinate so that they are executed in the order that you 182 * called them. 183 * 184 * @param dataset The data set index. 185 * @param index The index of the point to erase. 186 */ 187 public void erasePoint(final int dataset, final int index); 188 189 /** Rescale so that the data that is currently plotted just fits. 190 * This overrides the base class method to ensure that the protected 191 * variables _xBottom, _xTop, _yBottom, and _yTop are valid. 192 * This method calls repaint(), which eventually causes the display 193 * to be updated. 194 * <p> 195 * In order to work well with swing and be thread safe, this method 196 * actually defers execution to the event dispatch thread, where 197 * all user interface actions are performed. Thus, the fill will 198 * not occur immediately (unless you call this method from within 199 * the event dispatch thread). All the methods that do this deferring 200 * coordinate so that they are executed in the order that you 201 * called them. 202 */ 203 @Override 204 public void fillPlot(); 205 206 /** Return whether the default is to connect 207 * subsequent points with a line. If the result is false, then 208 * points are not connected. When points are by default 209 * connected, individual points can be not connected by giving the 210 * appropriate argument to addPoint(). Also, a different default 211 * can be set for each dataset, overriding this global default. 212 * @return True if points will be connected by default 213 * @see #setConnected 214 */ 215 public boolean getConnected(); 216 217 /** Return whether a line will be drawn from any 218 * plotted point down to the x axis. 219 * A plot with such lines is also known as a stem plot. 220 * @return True if this is an impulse plot 221 * @see #setImpulses(boolean) 222 */ 223 public boolean getImpulses(); 224 225 /** Return false if setLineStyles() has not yet been called or if 226 * setLineStyles(false) has been called, which signifies that 227 * different line styles are not to be used. Otherwise, return true. 228 * @return True if line styles are to be used. 229 * @see #setLineStyles(boolean) 230 */ 231 public boolean getLineStyles(); 232 233 /** Get the marks style, which is one of 234 * "none", "points", "dots", or "various". 235 * @return A string specifying the style for points. 236 * @see #setMarksStyle 237 */ 238 public String getMarksStyle(); 239 240 /** Return the maximum number of data sets. 241 * This method is deprecated, since there is no longer an upper bound. 242 * @return The maximum number of data sets 243 * @deprecated 244 */ 245 @Deprecated 246 public int getMaxDataSets(); 247 248 /** Return the actual number of data sets. 249 * @return The number of data sets that have been created. 250 */ 251 public int getNumDataSets(); 252 253 /** Return false if setReuseDatasets() has not yet been called 254 * or if setReuseDatasets(false) has been called. 255 * @return false if setReuseDatasets() has not yet been called 256 * or if setReuseDatasets(false) has been called. 257 * @since Ptolemy II 10.0 258 * @see #setReuseDatasets(boolean) 259 */ 260 public boolean getReuseDatasets(); 261 262 /** Override the base class to indicate that a new data set is being read. 263 * This method is deprecated. Use read() instead (to read the old 264 * file format) or one of the classes in the plotml package to read 265 * the new (XML) file format. 266 * @deprecated 267 */ 268 @Override 269 @Deprecated 270 public void parseFile(String filespec, URL documentBase); 271 272 /** Mark the disconnections with a Dot in case value equals true, otherwise these 273 * points are not marked. 274 * @param value True when disconnections should be marked. 275 */ 276 public void markDisconnections(boolean value); 277 278 /** Read a file with the old syntax (non-XML). 279 * Override the base class to register that we are reading a new 280 * data set. 281 * @param inputStream The input stream. 282 * @exception IOException If the stream cannot be read. 283 */ 284 @Override 285 public void read(InputStream inputStream) throws IOException; 286 287 /** Create a sample plot. This is not actually done immediately 288 * unless the calling thread is the event dispatch thread. 289 * Instead, it is deferred to the event dispatch thread. 290 * It is important that the calling thread not hold a synchronize 291 * lock on the Plot object, or deadlock will result (unless the 292 * calling thread is the event dispatch thread). 293 */ 294 @Override 295 public void samplePlot(); 296 297 /** Turn bars on or off (for bar charts). Note that this is a global 298 * property, not per dataset. 299 * @param on If true, turn bars on. 300 */ 301 public void setBars(boolean on); 302 303 /** Turn bars on and set the width and offset. Both are specified 304 * in units of the x axis. The offset is the amount by which the 305 * i <sup>th</sup> data set is shifted to the right, so that it 306 * peeks out from behind the earlier data sets. 307 * @param width The width of the bars. 308 * @param offset The offset per data set. 309 */ 310 public void setBars(double width, double offset); 311 312 /** If the argument is true, then the default is to connect 313 * subsequent points with a line. If the argument is false, then 314 * points are not connected. When points are by default 315 * connected, individual points can be not connected by giving the 316 * appropriate argument to addPoint(). Also, a different default 317 * can be set for each dataset, overriding this global default. 318 * setConnected will also change the behavior of points that were 319 * already drawn if the graph is redrawn. If it isn't the points 320 * are not touched. If you change back the setConnected state, 321 * the again see what was visible before. 322 * @param on If true, draw lines between points. 323 * @see #setConnected(boolean, int) 324 * @see #getConnected 325 */ 326 public void setConnected(boolean on); 327 328 /** If the first argument is true, then by default for the specified 329 * dataset, points will be connected by a line. Otherwise, the 330 * points will not be connected. When points are by default 331 * connected, individual points can be not connected by giving the 332 * appropriate argument to addPoint(). 333 * Note that this method should be called before adding any points. 334 * Note further that this method should probably be called from 335 * the event thread. 336 * @param on If true, draw lines between points. 337 * @param dataset The dataset to which this should apply. 338 * @see #setConnected(boolean) 339 * @see #getConnected 340 */ 341 public void setConnected(boolean on, int dataset); 342 343 /** If the argument is true, then a line will be drawn from any 344 * plotted point down to the x axis. Otherwise, this feature is 345 * disabled. A plot with such lines is also known as a stem plot. 346 * @param on If true, draw a stem plot. 347 * @see #getImpulses() 348 */ 349 public void setImpulses(boolean on); 350 351 /** If the first argument is true, then a line will be drawn from any 352 * plotted point in the specified dataset down to the x axis. 353 * Otherwise, this feature is 354 * disabled. A plot with such lines is also known as a stem plot. 355 * @param on If true, draw a stem plot. 356 * @param dataset The dataset to which this should apply. 357 * @see #getImpulses() 358 */ 359 public void setImpulses(boolean on, int dataset); 360 361 /** Set the style of the lines joining marks. 362 * @param styleString A string specifying the color for points. 363 * The following styles are permitted: "solid", "dotted", 364 * "dashed", "dotdashed", "dotdotdashed". 365 * @param dataset The data set index. 366 */ 367 public void setLineStyle(String styleString, int dataset); 368 369 /** If the argument is true, draw the data sets with different line 370 * styles. Otherwise, use one line style. 371 * @param lineStyles True if the data sets are to be drawn in different 372 * line styles. 373 * @see #getLineStyles() 374 */ 375 public void setLineStyles(boolean lineStyles); 376 377 /** Set the marks style to "none", "points", "dots", or "various". 378 * In the last case, unique marks are used for the first ten data 379 * sets, then recycled. 380 * This method should be called only from the event dispatch thread. 381 * @param style A string specifying the style for points. 382 * @see #getMarksStyle 383 */ 384 public void setMarksStyle(String style); 385 386 /** Set the marks style to "none", "points", "dots", "various", 387 * or "pixels" for the specified dataset. 388 * In the last case, unique marks are used for the first ten data 389 * sets, then recycled. 390 * @param style A string specifying the style for points. 391 * @param dataset The dataset to which this should apply. 392 * @see #getMarksStyle 393 */ 394 public void setMarksStyle(String style, int dataset); 395 396 /** Specify the number of data sets to be plotted together. 397 * This method is deprecated, since it is no longer necessary to 398 * specify the number of data sets ahead of time. 399 * @param numSets The number of data sets. 400 * @deprecated 401 */ 402 @Deprecated 403 public void setNumSets(int numSets); 404 405 /** Calling this method with a positive argument sets the 406 * persistence of the plot to the given number of points. Calling 407 * with a zero argument turns off this feature, reverting to 408 * infinite memory (unless sweeps persistence is set). If both 409 * sweeps and points persistence are set then sweeps take 410 * precedence. 411 * <p> 412 * Setting the persistence greater than zero forces the plot to 413 * be drawn in XOR mode, which allows points to be quickly and 414 * efficiently erased. However, there is a bug in Java (as of 415 * version 1.3), where XOR mode does not work correctly with 416 * double buffering. Thus, if you call this with an argument 417 * greater than zero, then we turn off double buffering for this 418 * panel <i>and all of its parents</i>. This actually happens 419 * on the next call to addPoint(). 420 * @param persistence Number of points to persist for. 421 */ 422 public void setPointsPersistence(int persistence); 423 424 /** If the argument is true, then datasets with the same name 425 * are merged into a single dataset. 426 * @param on If true, then merge datasets. 427 * @see #getReuseDatasets() 428 */ 429 public void setReuseDatasets(boolean on); 430 431 /** Calling this method with a positive argument sets the 432 * persistence of the plot to the given width in units of the 433 * horizontal axis. Calling 434 * with a zero argument turns off this feature, reverting to 435 * infinite memory (unless points persistence is set). If both 436 * X and points persistence are set then both are applied, 437 * meaning that points that are old by either criterion will 438 * be erased. 439 * <p> 440 * Setting the X persistence greater than zero forces the plot to 441 * be drawn in XOR mode, which allows points to be quickly and 442 * efficiently erased. However, there is a bug in Java (as of 443 * version 1.3), where XOR mode does not work correctly with 444 * double buffering. Thus, if you call this with an argument 445 * greater than zero, then we turn off double buffering for this 446 * panel <i>and all of its parents</i>. This actually happens 447 * on the next call to addPoint(). 448 * @param persistence Persistence in units of the horizontal axis. 449 */ 450 public void setXPersistence(double persistence); 451 452 /** Write plot data information to the specified output stream in PlotML. 453 * @param output A buffered print writer. 454 */ 455 @Override 456 public void writeData(PrintWriter output); 457 458 /** Write plot format information to the specified output stream in 459 * PlotML, an XML scheme. 460 * @param output A buffered print writer. 461 */ 462 @Override 463 public void writeFormat(PrintWriter output); 464}