Search in sources :

Example 1 with ISeries

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Region(org.eclipse.swt.graphics.Region) ISeries(org.swtchart.ISeries)

Example 2 with ISeries

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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ISeries(org.swtchart.ISeries) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point)

Example 3 with ISeries

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;
}
Also used : ISeries(org.swtchart.ISeries) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point)

Example 4 with ISeries

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);
        }
    }
}
Also used : ISeriesSet(org.swtchart.ISeriesSet) IMonitoredMXBeanAttribute(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanAttribute) ISeries(org.swtchart.ISeries)

Example 5 with ISeries

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();
}
Also used : ISeries(org.swtchart.ISeries)

Aggregations

ISeries (org.swtchart.ISeries)43 Point (org.eclipse.swt.graphics.Point)16 Date (java.util.Date)9 IAxis (org.swtchart.IAxis)9 Range (org.swtchart.Range)7 LocalDate (java.time.LocalDate)4 ArrayList (java.util.ArrayList)4 ILineSeries (org.swtchart.ILineSeries)4 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 CSVPrinter (org.apache.commons.csv.CSVPrinter)2 Color (org.eclipse.swt.graphics.Color)2 GC (org.eclipse.swt.graphics.GC)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 Shell (org.eclipse.swt.widgets.Shell)2 DataPoint (org.netxms.ui.eclipse.charts.api.DataPoint)2 IBarSeries (org.swtchart.IBarSeries)2 Axis (org.swtchart.internal.axis.Axis)2