added option to limit the number of displayed chart items
This commit is contained in:
parent
195062416e
commit
71c219f5fc
1 changed files with 73 additions and 9 deletions
|
@ -26,16 +26,16 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: TimeChartPanel.java,v 1.1 2008/07/09 23:18:07 nifi Exp $
|
* $Id: TimeChartPanel.java,v 1.2 2008/08/29 08:42:30 nifi Exp $
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------
|
* -----------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* PowerPanel
|
* TimeChartPanel
|
||||||
*
|
*
|
||||||
* Authors : Joakim Eriksson, Niclas Finne
|
* Authors : Joakim Eriksson, Niclas Finne
|
||||||
* Created : 3 jul 2008
|
* Created : 3 jul 2008
|
||||||
* Updated : $Date: 2008/07/09 23:18:07 $
|
* Updated : $Date: 2008/08/29 08:42:30 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.contiki.collect.gui;
|
package se.sics.contiki.collect.gui;
|
||||||
|
@ -74,6 +74,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
|
||||||
private double maxValue;
|
private double maxValue;
|
||||||
private int rangeTick = 0;
|
private int rangeTick = 0;
|
||||||
private boolean hasGlobalRange;
|
private boolean hasGlobalRange;
|
||||||
|
private int maxItemCount;
|
||||||
|
|
||||||
public TimeChartPanel(CollectServer server, String title,
|
public TimeChartPanel(CollectServer server, String title,
|
||||||
String chartTitle, String timeAxisLabel, String valueAxisLabel) {
|
String chartTitle, String timeAxisLabel, String valueAxisLabel) {
|
||||||
|
@ -141,7 +142,13 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
|
||||||
for (int i = 0, n = selectedNodes.length; i < n; i++) {
|
for (int i = 0, n = selectedNodes.length; i < n; i++) {
|
||||||
if (node == selectedNodes[i]) {
|
if (node == selectedNodes[i]) {
|
||||||
TimeSeries series = timeSeries.getSeries(i);
|
TimeSeries series = timeSeries.getSeries(i);
|
||||||
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data));
|
int groupSize = getGroupSize(node);
|
||||||
|
if (groupSize > 1) {
|
||||||
|
series.clear();
|
||||||
|
updateSeries(series, node, groupSize);
|
||||||
|
} else {
|
||||||
|
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data));
|
||||||
|
}
|
||||||
chartPanel.repaint();
|
chartPanel.repaint();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -161,15 +168,48 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
|
||||||
if (this.selectedNodes != null) {
|
if (this.selectedNodes != null) {
|
||||||
for(Node node: this.selectedNodes) {
|
for(Node node: this.selectedNodes) {
|
||||||
TimeSeries series = new TimeSeries(node.getName(), Second.class);
|
TimeSeries series = new TimeSeries(node.getName(), Second.class);
|
||||||
for (int i = 0, n = node.getSensorDataCount(); i < n; i++) {
|
// Reduce the number of items by grouping them and use the average for each group
|
||||||
SensorData data = node.getSensorData(i);
|
int groupSize = getGroupSize(node);
|
||||||
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data));
|
if (groupSize > 1) {
|
||||||
|
updateSeries(series, node, groupSize);
|
||||||
|
} else {
|
||||||
|
for (int i = 0, n = node.getSensorDataCount(); i < n; i++) {
|
||||||
|
SensorData data = node.getSensorData(i);
|
||||||
|
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
timeSeries.addSeries(series);
|
timeSeries.addSeries(series);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getGroupSize(Node node) {
|
||||||
|
if (maxItemCount > 0) {
|
||||||
|
int sensorDataCount = node.getSensorDataCount();
|
||||||
|
if (sensorDataCount > maxItemCount) {
|
||||||
|
int groupSize = sensorDataCount / maxItemCount;
|
||||||
|
if (sensorDataCount / groupSize > maxItemCount) {
|
||||||
|
groupSize++;
|
||||||
|
}
|
||||||
|
return groupSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateSeries(TimeSeries series, Node node, int groupSize) {
|
||||||
|
for (int i = 0, n = node.getSensorDataCount(); i < n; i += groupSize) {
|
||||||
|
double value = 0.0;
|
||||||
|
long time = 0L;
|
||||||
|
for (int j = 0; j < groupSize; j++) {
|
||||||
|
SensorData data = node.getSensorData(i);
|
||||||
|
value += getSensorDataValue(data);
|
||||||
|
time += data.getTime() / 1000L;
|
||||||
|
}
|
||||||
|
series.addOrUpdate(new Second(new Date((time / groupSize) * 1000L)), value / groupSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getRangeTick() {
|
public int getRangeTick() {
|
||||||
return rangeTick;
|
return rangeTick;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +272,29 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract double getSensorDataValue(SensorData data);
|
/**
|
||||||
|
* Returns the maximal number of chart items to display for each node.
|
||||||
|
*
|
||||||
|
* @return the maximal number of chart items to display for each node or <code>0</code>
|
||||||
|
* for unlimited number of chart items.
|
||||||
|
*/
|
||||||
|
public int getMaxItemCount() {
|
||||||
|
return maxItemCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximal number of chart items to display for each node. Items will be
|
||||||
|
* grouped and replaced by the average value when needed.
|
||||||
|
*
|
||||||
|
* @param maxItemCount - the maximal number of chart items to display for each node or
|
||||||
|
* <code>0</code> for unlimited number (default)
|
||||||
|
*/
|
||||||
|
public void setMaxItemCount(int maxItemCount) {
|
||||||
|
this.maxItemCount = maxItemCount;
|
||||||
|
if (isVisible()) {
|
||||||
|
updateCharts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
@ -244,4 +306,6 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
|
||||||
super.setVisible(visible);
|
super.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract double getSensorDataValue(SensorData data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue