use of org.swtchart.ISeries in project tdi-studio-se by Talend.
the class Marker method createHovers.
/**
* Creates the hovers.
*/
private void createHovers() {
// create hover keys
List<String> keys = new ArrayList<String>();
keys.add(TIME_KEY);
for (ISeries series : chart.getSeriesSet().getSeries()) {
keys.add(series.getId());
}
// create or reuse hovers
Map<String, Shell> newHovers = new HashMap<String, Shell>();
for (final String key : keys) {
Shell hover = hovers.get(key);
if (hover == null) {
hover = createHover(key);
}
newHovers.put(key, hover);
}
// dispose unused hovers
for (Entry<String, Shell> entrySet : hovers.entrySet()) {
if (!keys.contains(entrySet.getKey())) {
Shell hover = entrySet.getValue();
Region region = hover.getRegion();
if (region != null) {
region.dispose();
}
hover.dispose();
}
}
hovers = newHovers;
}
use of org.swtchart.ISeries in project tdi-studio-se by Talend.
the class Marker method createLineHover.
private void createLineHover(Integer invertedSeriesIndex) {
if (lineHover == null || lineHover.isDisposed() || !lineHover.isVisible()) {
lineHover = new Shell(chart.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL | SWT.NO_BACKGROUND);
lineHover.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.setLineStyle(SWT.LINE_DOT);
e.gc.setAntialias(SWT.ON);
e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
// e.gc.fillOval(2-1,150-1, 3, 3);
e.gc.drawLine(2, 0, 2, chart.getPlotArea().getSize().y);
}
});
lineHover.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
if (!isDisposed()) {
setPosition(mouseXPosition);
}
}
});
}
lineHover.setSize(4, chart.getPlotArea().getSize().y);
ISeries largestSeries = getLargestSeries();
Date[] dates = largestSeries.getXDateSeries();
long time = dates[dates.length - invertedSeriesIndex].getTime();
int timeInPixel = chart.getAxisSet().getXAxes()[0].getPixelCoordinate(time);
lineHover.setLocation(chart.getPlotArea().toDisplay(timeInPixel - 3, 0));
lineHover.redraw();
lineHover.setVisible(true);
}
use of org.swtchart.ISeries in project tdi-studio-se by Talend.
the class Marker method getInvertedSeriesIndex.
/**
* Gets the inverted series index that is the nearest to mouse position.
*
* @param desiredX The desired x pixel coordinate
* @return The inverted series index, or <tt>null</tt> if not found
*/
private Integer getInvertedSeriesIndex(int desiredX) {
long desiredTime = (long) chart.getAxisSet().getAxes()[0].getDataCoordinate(desiredX);
// find largest size of series
ISeries largestSeries = getLargestSeries();
if (largestSeries == null) {
return null;
}
// find the time series index
Date[] dates = largestSeries.getXDateSeries();
for (int i = 0; i < dates.length; i++) {
if (dates[i].getTime() < desiredTime && i != dates.length - 1) {
continue;
}
int nearestIndex;
if (i > 0 && dates[i].getTime() - desiredTime > desiredTime - dates[i - 1].getTime()) {
nearestIndex = i - 1;
} else {
nearestIndex = i;
}
return dates.length - nearestIndex;
}
return null;
}
use of org.swtchart.ISeries in project tdi-studio-se by Talend.
the class TimelineChart method deleteMonitoredSeries.
/**
* Delete series if not monitored any longer.
*/
private void deleteMonitoredSeries() {
ISeriesSet seriesSet = getSeriesSet();
List<IMonitoredMXBeanAttribute> attributes = attributeGroup.getAttributes();
for (ISeries series : seriesSet.getSeries()) {
String seriesId = series.getId();
boolean found = false;
for (IMonitoredMXBeanAttribute attribute : attributes) {
if (series.getId().equals(getSeriesId(attribute))) {
found = true;
}
}
if (!found) {
seriesSet.deleteSeries(seriesId);
}
}
}
use of org.swtchart.ISeries in project linuxtools by eclipse.
the class BarChartBuilder method buildXSeries.
@Override
protected void buildXSeries() {
Object[][] data = adapter.getData();
if (data == null || data.length == 0) {
return;
}
int start = 0, len = Math.min(this.maxItems, data.length), leny = data[0].length - 1;
if (this.maxItems < data.length) {
start = data.length - this.maxItems;
}
String[] allValx = new String[len];
Double[][] allValy = new Double[leny][len];
// Want to show x-axis if possible, so default max/min is 0.
double maxY = 0;
double minY = 0;
// If an x-axis category is empty, ignore the entire category.
for (int i = 0; i < len; i++) {
Object label = data[start + i][0];
if (label != null) {
allValx[i] = label.toString();
for (int j = 1; j < leny + 1; j++) {
Double val = getDoubleOrNullValue(data[start + i][j]);
if (val == null) {
val = 0.0;
}
allValy[j - 1][i] = val;
maxY = Math.max(val, maxY);
minY = Math.min(val, minY);
}
}
}
// Now create dense arrays of x/y values that exclude null values,
// and plot those values to the chart.
String[] valx = new String[len];
int lenTrim = 0;
for (int i = 0; i < len; i++) {
if (allValx[i] != null) {
valx[lenTrim] = allValx[i];
lenTrim++;
}
}
String[] valxTrim = new String[lenTrim];
System.arraycopy(valx, 0, valxTrim, 0, lenTrim);
ISeries[] allSeries = chart.getSeriesSet().getSeries();
for (int i = 0; i < leny; i++) {
ISeries series;
if (i >= allSeries.length) {
series = createChartISeries(i);
} else {
series = chart.getSeriesSet().getSeries()[i];
}
double[] valy = new double[len];
int lenyTrim = 0;
for (int j = 0; j < len; j++) {
if (allValy[i][j] != null) {
valy[lenyTrim] = allValy[i][j].doubleValue();
lenyTrim++;
}
}
double[] valyTrim = new double[lenyTrim];
System.arraycopy(valy, 0, valyTrim, 0, lenyTrim);
series.setYSeries(valyTrim);
}
((BarChart) chart).suspendUpdate(true);
((BarChart) chart).setCategorySeries(getUniqueNames(valxTrim));
applyCategoryRange(valxTrim.length);
applyRangeY(minY, maxY);
((BarChart) chart).suspendUpdate(false);
chart.redraw();
}
Aggregations