## Modelica_LinearSystems2.Utilities.Plot

Functions for generation of 2D-plots

### Information

This package provides functions to plot curves in two dimensions. Here is a short overview:

A figure consists of a set of diagrams. Different functions are provided to either plot one diagram (Plot.diagram) to plot several diagrams under each other (Plot.vectorDiagrams) or to plot several diagrams in matrix layout (Plot.matrixDiagrams).

Every diagram can have a set of curves. Every diagram has the same width, defined by diagramWidth. The height of a diagram is defined by variable heightRatio (diagram height in row j = diagram[j].heightRatio*diagramWidth). Several curves can be displayed in one diagram.

### Package Content

Name | Description
--- | ---
Examples | Demonstrate the usage of the plot functions
diagram | Plot one diagram
diagramVector | Plot several diagrams in vector layout
diagramMatrix | Plot several diagrams in matrix layout
Types | Types used for the plotting functions
Records | Records used to define the function interfaces

## Modelica_LinearSystems2.Utilities.Plot.diagram

Plot one diagram

### Information

This function plots a set of 2-dimensional curves in a diagram. For an overview, see the documentation of package Modelica_LinearSystems2.Utilities.Plot.

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Diagram | diagram |  | Diagram to be shown
Device | device | Modelica_LinearSystems2.Util... | Properties of device where figure is shown

### Modelica definition

    function diagram "Plot one diagram"
        import Modelica_LinearSystems2.Utilities.Plot.Types;
        import Modelica.Utilities.Streams.*;
       input Modelica_LinearSystems2.Utilities.Plot.Records.Diagram diagram
        "Diagram to be shown";
       input Modelica_LinearSystems2.Utilities.Plot.Records.Device device=
          Modelica_LinearSystems2.Utilities.Plot.Records.Device()
        "Properties of device where figure is shown";
    protected
      Real mmToPixel= device.windowResolution/25.4;
      Real position[4];
      Integer style;
      Integer nCurves=size(diagram.curve,1);
      Boolean OK;
      Integer id;
    algorithm
       position := {device.xTopLeft,
                    device.yTopLeft,
                    device.diagramWidth,
                    diagram.heightRatio*device.diagramWidth}*mmToPixel;

       id:= createPlot(id=-1,
                       position=integer(position),
                       erase=true,
                       autoscale=true,
                       autoerase=false,
                       subPlot=1,
                       heading=diagram.heading,
                       grid=diagram.grid,
                       logX=diagram.logX,
                       logY=diagram.logY,
                       bottomTitle=diagram.xLabel,
                       leftTitle=diagram.yLabel,
                       color=device.autoLineColor,
                       legend=diagram.legend,
                       legendHorizontal=diagram.legendHorizontal,
                       legendFrame=diagram.legendFrame,
                       legendLocation=diagram.legendLocation);

       for i in 1:nCurves loop
           if diagram.curve[i].autoLine or
              diagram.curve[i].lineSymbol==Types.PointSymbol.None then
              style :=0;
           elseif diagram.curve[i].linePattern==Types.LinePattern.None then
              style :=-(diagram.curve[i].lineSymbol - 1);
           else
              style :=diagram.curve[i].lineSymbol - 1;
           end if;

           OK :=plotArray(diagram.curve[i].x,
                          diagram.curve[i].y,
                          legend=diagram.curve[i].legend,
                          style=style,
                          id=id);
        end for;

    end diagram;

## Modelica_LinearSystems2.Utilities.Plot.diagramVector

Plot several diagrams in vector layout

### Information

This function plots a set of 2-dimensional curves in a set of diagrams using a vector layout. For an overview, see the documentation of package Modelica_LinearSystems2.Utilities.Plot.

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Diagram | diagram[:] |  | Properties of a set of diagrams (vector layout)
Device | device | Modelica_LinearSystems2.Util... | Properties of device where figure is shown

### Modelica definition

    function diagramVector "Plot several diagrams in vector layout"
       input Modelica_LinearSystems2.Utilities.Plot.Records.Diagram diagram[:]
        "Properties of a set of diagrams (vector layout)";
       input Modelica_LinearSystems2.Utilities.Plot.Records.Device device=
          Modelica_LinearSystems2.Utilities.Plot.Records.Device()
        "Properties of device where figure is shown";

    protected
      Real mmToPixel= device.windowResolution/25.4;
      Integer position[4];
      Integer style;
      Integer nDiagrams=size(diagram,1);
      Integer figureHeight;
      Integer height[nDiagrams];
      Boolean OK;
      Integer id;

      function round "Round to nearest Integer"
         input Real r;
         output Integer i;
      algorithm
         i :=if r > 0 then integer(floor(r + 0.5)) else integer(ceil(r - 0.5));
      end round;
    algorithm
        id := -1;

        // Determine total size of window
        figureHeight := 0;
        for i in 1:nDiagrams loop
           height[i]    := round(diagram[i].heightRatio*device.diagramWidth*mmToPixel);
           figureHeight := figureHeight + height[i];
        end for;

        position := {round(device.xTopLeft*mmToPixel),
                     round(device.yTopLeft*mmToPixel),
                     round(device.diagramWidth*mmToPixel),
                     figureHeight};

        // Determine position and size of sub-figures
        for i in 1:nDiagrams loop
           if i > 1 then
              position[4] := height[i];
           end if;

           id:= createPlot(id=id,
                       position=position,
                       erase=true,
                       autoscale=true,
                       autoerase=false,
                       subPlot=i,
                       heading=diagram[i].heading,
                       grid=diagram[i].grid,
                       logX=diagram[i].logX,
                       logY=diagram[i].logY,
                       bottomTitle=diagram[i].xLabel,
                       leftTitle=diagram[i].yLabel,
                       color=device.autoLineColor,
                       legend=diagram[i].legend,
                       legendHorizontal=diagram[i].legendHorizontal,
                       legendFrame=diagram[i].legendFrame,
                       legendLocation=diagram[i].legendLocation);

           for j in 1:size(diagram[i].curve,1) loop
              if diagram[i].curve[j].autoLine or
                 diagram[i].curve[j].lineSymbol==Types.PointSymbol.None then
                 style :=0;
              elseif diagram[i].curve[j].linePattern==Types.LinePattern.None then
                 style :=-(diagram[i].curve[j].lineSymbol - 1);
              else
                 style :=diagram[i].curve[j].lineSymbol - 1;
              end if;

              OK :=plotArray(diagram[i].curve[j].x,
                             diagram[i].curve[j].y,
                             legend=diagram[i].curve[j].legend,
                             style=style,
                             id=id);
           end for;
        end for;

    end diagramVector;

## Modelica_LinearSystems2.Utilities.Plot.diagramMatrix

Plot several diagrams in matrix layout

### Information

This function plots a set of 2-dimensional curves in a set of diagrams using a matrix layout. For an overview, see the documentation of package Modelica_LinearSystems2.Utilities.Plot.

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Diagram | diagram[:, :] |  | Properties of a set of diagrams (matrix layout)
Device | device | Modelica_LinearSystems2.Util... | Properties of device where figure is shown

### Modelica definition

    function diagramMatrix "Plot several diagrams in matrix layout"
       input Modelica_LinearSystems2.Utilities.Plot.Records.Diagram diagram[:,:]
        "Properties of a set of diagrams (matrix layout)";
       input Modelica_LinearSystems2.Utilities.Plot.Records.Device device=
          Modelica_LinearSystems2.Utilities.Plot.Records.Device()
        "Properties of device where figure is shown";
    protected
      Modelica_LinearSystems2.Utilities.Plot.Records.Device device2=device;

    algorithm
       for i in 1:size(diagram,2) loop
          device2.xTopLeft :=device.xTopLeft + (i - 1)*device.diagramWidth;
        Modelica_LinearSystems2.Utilities.Plot.diagramVector(diagram[:, i], device2);
       end for;

    end diagramMatrix;