1 package org.jgnuplot;
    2 
    3 /**
    4  * This class provides the samefunctionality as gnuplot fillstyle.dem.
    5  *
    6  * Demo for revised fillstyle code selected by ./configure --enable-filledboxes
    7  * --enable-relative-boxwidth
    8  *
    9  * @author Pander
   10  */
   11 public final class FillStyleDem {
   12    private FillStyleDem() {
   13    }
   14 
   15    public static void gnuplot() {
   16       Plot.setGnuplotExecutable("gnuplot");
   17       Plot.setPlotDirectory("/tmp");
   18 
   19       Plot aPlot = new Plot();
   20       aPlot.setSamples("25");
   21       aPlot.unsetXTics();
   22       aPlot.unsetYTics();
   23       aPlot.setYRange("0", "120");
   24       aPlot.setTitle("A demonstration of boxes with default properties");
   25       aPlot.setRanges("[-10:10]");
   26       Graph aGraph = new Graph("100/(1.0+x*x)", Axes.NOT_SPECIFIED,
   27             "distribution", Style.BOXES);
   28       aPlot.pushGraph(aGraph);
   29       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-01.png");
   30       try {
   31          aPlot.plot();
   32       }
   33       catch (Exception e) {
   34          System.err.println(e);
   35          System.exit(1);
   36       }
   37 
   38       // Now draw the boxes with a black border
   39       aPlot.clear();
   40       aPlot.setTitle("A demonstration of boxes with style fill solid 1.0");
   41       aPlot.addExtra("set style fill solid 1.0");
   42       aPlot.pushGraph(aGraph);
   43       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-02.png");
   44       try {
   45          aPlot.plot();
   46       }
   47       catch (Exception e) {
   48          System.err.println(e);
   49          System.exit(1);
   50       }
   51 
   52       // Now draw the boxes with a black border
   53       aPlot.clear();
   54       aPlot.setTitle("A demonstration of boxes with style fill solid border -1");
   55       aPlot.addExtra("set style fill solid border -1");
   56       aPlot.pushGraph(aGraph);
   57       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-03.png");
   58       try {
   59          aPlot.plot();
   60       }
   61       catch (Exception e) {
   62          System.err.println(e);
   63          System.exit(1);
   64       }
   65 
   66       // Now make the boxes a little less wide
   67       aPlot.clear();
   68       aPlot.setTitle("Filled boxes of reduced width");
   69       aPlot.addExtra("set boxwidth 0.5");
   70       aPlot.pushGraph(aGraph);
   71       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-04.png");
   72       try {
   73          aPlot.plot();
   74       }
   75       catch (Exception e) {
   76          System.err.println(e);
   77          System.exit(1);
   78       }
   79 
   80       // And now let's try a different fill density
   81       aPlot.clear();
   82       aPlot.setTitle("Filled boxes at 50% fill density");
   83       aPlot.addExtra("set style fill solid 0.25 border");
   84       aPlot.pushGraph(aGraph);
   85       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-05.png");
   86       try {
   87          aPlot.plot();
   88       }
   89       catch (Exception e) {
   90          System.err.println(e);
   91          System.exit(1);
   92       }
   93 
   94       // Now draw the boxes with no border
   95       aPlot.clear();
   96       aPlot.setTitle("A demonstration of boxes with style fill solid 0.25 noborder");
   97       aPlot.addExtra("set style fill solid 0.25 noborder");
   98       aPlot.pushGraph(aGraph);
   99       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-06.png");
  100       try {
  101          aPlot.plot();
  102       }
  103       catch (Exception e) {
  104          System.err.println(e);
  105          System.exit(1);
  106       }
  107 
  108       // Or maybe a pattern fill, instead?
  109       aPlot.clear();
  110       aPlot.setTitle("A demonstration of boxes in mono with style fill pattern");
  111       aPlot.setSamples("11");
  112       aPlot.addExtra("set boxwidth 0.5");
  113       aPlot.addExtra("set style fill pattern border");
  114       aPlot.setRanges("[-2.5:4.5]");
  115       aPlot.pushGraph(new Graph("100/(1.0+x*x)", Axes.NOT_SPECIFIED,
  116             "pattern 0", Style.BOXES, LineType.SCREEN_BLACK_SOLID_BOLD,
  117             PointType.NOT_SPECIFIED));
  118       aPlot.pushGraph(new Graph("80/(1.0+x*x)", Axes.NOT_SPECIFIED,
  119             "pattern 0", Style.BOXES, LineType.SCREEN_BLACK_SOLID_BOLD,
  120             PointType.NOT_SPECIFIED));
  121       aPlot.pushGraph(new Graph("40/(1.0+x*x)", Axes.NOT_SPECIFIED,
  122             "pattern 0", Style.BOXES, LineType.SCREEN_BLACK_SOLID_BOLD,
  123             PointType.NOT_SPECIFIED));
  124       aPlot.pushGraph(new Graph("20/(1.0+x*x)", Axes.NOT_SPECIFIED,
  125             "pattern 0", Style.BOXES, LineType.SCREEN_BLACK_SOLID_BOLD,
  126             PointType.NOT_SPECIFIED));
  127       aPlot.setOutput(Terminal.PNG, "test/out/fillstyle-07.png");
  128       try {
  129          aPlot.plot();
  130       }
  131       catch (Exception e) {
  132          System.err.println(e);
  133          System.exit(1);
  134       }
  135    }
  136 }