This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathXYPlotActor.java
169 lines (152 loc) · 5.45 KB
/
XYPlotActor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
* Copyright (c) 2016,2019 iSencia Belgium NV.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Erwin De Ley - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.workflow.actor.plot;
import org.eclipse.nebula.visualization.xygraph.figures.Trace;
import org.eclipse.triquetrum.workflow.actor.plot.ui.XYPlot;
import ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.DoubleToken;
import ptolemy.data.expr.StringParameter;
import ptolemy.data.type.BaseType;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
/**
* This actor implements a an XY plot on Nebula's XYGraph visualization widget.
* <p>
* It is a simplified reimplementation of ptolemy.actor.lib.gui.XYPlotter :
* <ul>
* <li>Supports only one dataset, i.e. inputX and inputY are single-channel ports</li>
* <li>Creates an own plot widget, i.e. no shared plot across several plot actors</li>
* </ul>
* If the inputX is not connected, an iteration counter is passed as X value, i.e. the XYPlotActor behaves more-or-less like a sequence plotter.
* </p>
*/
public class XYPlotActor extends TypedAtomicActor {
/**
* The title to put on top. Note that the value of the title overrides the value of the name of the actor or the display name of the actor.
*/
public StringParameter title;
/**
* The name to be assigned to the X axis
*/
public StringParameter xName;
/**
* The name to be assigned to the Y axis
*/
public StringParameter yName;
/**
* The names to be assigned to the data series (comma-separated list of names)
*/
public StringParameter seriesNames;
/**
* Choices for plot styles, corresponding to org.eclipse.nebula.visualization.xygraph.figures.Trace.TraceType
*/
public StringParameter plotLineStyle;
/**
* Choices for plot styles, corresponding to org.eclipse.nebula.visualization.xygraph.figures.Trace.PointStyle
*/
public StringParameter plotPointStyle;
/**
* The input receiving the X double values
*/
public TypedIOPort inputX;
/**
* The input receiving the Y double values, paired to the X values received in the same iterations
*/
public TypedIOPort inputY;
/**
* An x counter that is used to generate x values i.c.o. an unconnected x port.
*/
private double xCounter;
/**
* The plot widget wrapper used by the actor instance.
*/
private XYPlot plot;
/**
* Construct an actor with the given container and name.
*
* @param container
* @param name
* @throws IllegalActionException
* @throws NameDuplicationException
*/
public XYPlotActor(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException {
super(container, name);
inputX = new TypedIOPort(this, "inputX", true, false);
inputX.setTypeEquals(BaseType.DOUBLE);
inputY = new TypedIOPort(this, "inputY", true, false);
inputY.setTypeEquals(BaseType.DOUBLE);
inputY.setMultiport(true);
title = new StringParameter(this, "title");
xName = new StringParameter(this, "X name");
xName.setExpression("X");
yName = new StringParameter(this, "Y name");
yName.setExpression("Y");
seriesNames = new StringParameter(this, "Series names");
seriesNames.setExpression("data1");
plotLineStyle = new StringParameter(this, "Line style");
plotLineStyle.setExpression(Trace.TraceType.SOLID_LINE.name());
plotLineStyle.addChoice(Trace.TraceType.SOLID_LINE.name());
plotLineStyle.addChoice(Trace.TraceType.DASH_LINE.name());
plotLineStyle.addChoice(Trace.TraceType.DASHDOT_LINE.name());
plotLineStyle.addChoice(Trace.TraceType.POINT.name());
plotPointStyle = new StringParameter(this, "Point style");
plotPointStyle.setExpression(Trace.PointStyle.POINT.name());
plotPointStyle.addChoice(Trace.PointStyle.NONE.name());
plotPointStyle.addChoice(Trace.PointStyle.POINT.name());
plotPointStyle.addChoice(Trace.PointStyle.XCROSS.name());
plotPointStyle.addChoice(Trace.PointStyle.DIAMOND.name());
}
@Override
public void initialize() throws IllegalActionException {
super.initialize();
xCounter = 0d;
plot = new XYPlot();
try {
plot.init(this);
plot.openWindow();
} catch (Exception e) {
throw new IllegalActionException(this, e, "error initialising XYPlot");
}
}
@Override
public boolean postfire() throws IllegalActionException {
boolean hasX = false;
boolean hasY = false;
double xValue = 0.0;
if (inputX.getWidth() > 0) {
if (inputX.hasToken(0)) {
xValue = ((DoubleToken) inputX.get(0)).doubleValue();
hasX = true;
}
} else {
xValue = xCounter++;
hasX = true;
}
if (hasX) {
int yWidth = inputY.getWidth();
for (int i = 0; i < yWidth; ++i) {
double yValue = 0.0;
if (inputY.hasToken(i)) {
yValue = ((DoubleToken) inputY.get(i)).doubleValue();
hasY = true;
}
if (hasY) {
plot.addPoint(i, xValue, yValue);
}
}
}
return super.postfire();
}
}