Search in sources :

Example 6 with ITitle

use of org.eclipse.swtchart.ITitle in project tracecompass by tracecompass.

the class CpuUsageXYViewer method setTitle.

/**
 * Update the {@link CpuUsageXYViewer} title to append the current cpu numbers
 */
protected void setTitle() {
    ITitle title = getSwtChart().getTitle();
    Set<Integer> cpus = CpuUsageView.getCpus(getTrace());
    if (cpus.isEmpty()) {
        title.setText(Messages.CpuUsageView_Title);
    } else {
        // $NON-NLS-1$
        title.setText(Messages.CpuUsageView_Title + ' ' + Joiner.on(", ").join(cpus));
    }
}
Also used : ITitle(org.eclipse.swtchart.ITitle)

Example 7 with ITitle

use of org.eclipse.swtchart.ITitle in project tracecompass by tracecompass.

the class SwtXYChartViewer method refreshDisplayTitles.

/**
 * Refresh the Chart, XAxis and YAxis titles to fit the current chart size.
 */
private void refreshDisplayTitles() {
    Rectangle chartRect = fChart.getClientArea();
    Rectangle plotRect = ((Composite) fChart.getPlotArea()).getClientArea();
    ITitle chartTitle = checkNotNull(fChart.getTitle());
    refreshDisplayTitle(chartTitle, getTitle(), chartRect.width);
    ITitle xTitle = checkNotNull(fChart.getAxisSet().getXAxis(0).getTitle());
    refreshDisplayTitle(xTitle, fXTitle, plotRect.width);
    ITitle yTitle = checkNotNull(fChart.getAxisSet().getYAxis(0).getTitle());
    refreshDisplayTitle(yTitle, fYTitle, plotRect.height);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Rectangle(org.eclipse.swt.graphics.Rectangle) ITitle(org.eclipse.swtchart.ITitle)

Example 8 with ITitle

use of org.eclipse.swtchart.ITitle in project org.eclipse.linuxtools by eclipse-linuxtools.

the class ChartFactory method produceBarChart.

/**
 * Produces a 2D bar chart from the input objects.
 *
 * @param objects
 *            the input data
 * @param nameField
 *            the field used to get the labels of the objects (the labels of the series groups).
 * @param valFields
 *            the fields providing the values for the different bars in a series group.
 * @param title Title of the chart.
 * @param horizontal
 *            if true the bars are displayed horizontally, else vertically.
 * @return a new 2D bar chart
 */
public static InteractiveChart produceBarChart(Object[] objects, final ISTDataViewersField nameField, List<IChartField> valFields, String title, boolean horizontal) {
    ChartView view;
    try {
        final Color WHITE = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE);
        final Color BLACK = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);
        final Color GRAD = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
        view = (ChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ChartView.VIEW_ID, String.valueOf(ChartView.getSecId()), IWorkbenchPage.VIEW_ACTIVATE);
        InteractiveChart chart = new InteractiveChart(view.getParent(), SWT.NONE);
        chart.setBackground(WHITE);
        chart.getPlotArea().setBackground(GRAD);
        chart.getTitle().setText(title);
        chart.getTitle().setForeground(BLACK);
        chart.setProposedSaveAsFilename(title.replace(' ', '_'));
        // this is correct (refers to orientation of x-axis, not bars)
        if (horizontal) {
            chart.setOrientation(SWT.VERTICAL);
        } else {
            chart.setOrientation(SWT.HORIZONTAL);
        }
        chart.getLegend().setPosition(SWT.RIGHT);
        String[] textLabels = new String[objects.length];
        for (int i = 0; i < objects.length; i++) {
            textLabels[i] = nameField.getValue(objects[i]);
        }
        // x-axis
        IAxis xAxis = chart.getAxisSet().getXAxis(0);
        xAxis.getGrid().setStyle(LineStyle.NONE);
        xAxis.getTick().setForeground(BLACK);
        ITitle xTitle = xAxis.getTitle();
        xTitle.setForeground(BLACK);
        xTitle.setText(nameField.getColumnHeaderText());
        xAxis.setCategorySeries(textLabels);
        xAxis.enableCategory(true);
        // y-axis
        IAxis yAxis = chart.getAxisSet().getYAxis(0);
        yAxis.getGrid().setStyle(LineStyle.NONE);
        yAxis.getTick().setForeground(BLACK);
        yAxis.getTitle().setVisible(false);
        // data
        for (IChartField field : valFields) {
            final IBarSeries bs = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, field.getColumnHeaderText());
            bs.setBarColor(new Color(Display.getDefault(), getRC(), getRC(), getRC()));
            double[] doubleValues = new double[objects.length];
            for (int i = 0; i < objects.length; i++) {
                Number num = field.getNumber(objects[i]);
                double longVal = num.doubleValue();
                doubleValues[i] = longVal;
            }
            bs.setYSeries(doubleValues);
        }
        chart.getAxisSet().adjustRange();
        return chart;
    } catch (PartInitException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
    return null;
}
Also used : Color(org.eclipse.swt.graphics.Color) ITitle(org.eclipse.swtchart.ITitle) InteractiveChart(org.eclipse.swtchart.extensions.charts.InteractiveChart) IAxis(org.eclipse.swtchart.IAxis) IBarSeries(org.eclipse.swtchart.IBarSeries) IChartField(org.eclipse.linuxtools.dataviewers.charts.provider.IChartField) PartInitException(org.eclipse.ui.PartInitException)

Example 9 with ITitle

use of org.eclipse.swtchart.ITitle in project org.eclipse.linuxtools by eclipse-linuxtools.

the class PieChartPaintListener method adjustTitle.

// Adjust the title with trailing blanks so it centers in the plot area
// rather than for the entire chart view which looks odd when not
// centered above the pie-charts themselves.
private void adjustTitle(PaintEvent pe) {
    ITitle title = chart.getTitle();
    Font font = title.getFont();
    Font oldFont = pe.gc.getFont();
    pe.gc.setFont(font);
    Control legend = (Control) chart.getLegend();
    Rectangle legendBounds = legend.getBounds();
    int adjustment = legendBounds.width - 15;
    // $NON-NLS-1$
    Point blankSize = pe.gc.textExtent(" ");
    int numBlanks = ((adjustment / blankSize.x) >> 1) << 1;
    String text = origTitleText;
    for (int i = 0; i < numBlanks; ++i) // $NON-NLS-1$
    text += " ";
    pe.gc.setFont(oldFont);
    title.setText(text);
}
Also used : Control(org.eclipse.swt.widgets.Control) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ITitle(org.eclipse.swtchart.ITitle) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 10 with ITitle

use of org.eclipse.swtchart.ITitle in project org.eclipse.linuxtools by eclipse-linuxtools.

the class AbstractChartWithAxisBuilder method buildXAxis.

/**
 * Builds X axis.
 */
@Override
protected void buildXAxis() {
    String[] labels = adapter.getLabels();
    IAxis xAxis = this.chart.getAxisSet().getXAxis(0);
    if (xLineGrid) {
        xAxis.getGrid().setStyle(LineStyle.SOLID);
    } else {
        xAxis.getGrid().setStyle(LineStyle.NONE);
    }
    xAxis.getTick().setForeground(BLACK);
    xAxis.getTick().setTickMarkStepHint(xSeriesTicks);
    ITitle xTitle = xAxis.getTitle();
    xTitle.setForeground(BLACK);
    if (labels.length > 0) {
        xTitle.setText(labels[0]);
    } else {
        // $NON-NLS-1$
        xTitle.setText("");
    }
}
Also used : ITitle(org.eclipse.swtchart.ITitle) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

ITitle (org.eclipse.swtchart.ITitle)13 Font (org.eclipse.swt.graphics.Font)5 Color (org.eclipse.swt.graphics.Color)4 Point (org.eclipse.swt.graphics.Point)4 Rectangle (org.eclipse.swt.graphics.Rectangle)3 IAxis (org.eclipse.swtchart.IAxis)3 FontData (org.eclipse.swt.graphics.FontData)2 Control (org.eclipse.swt.widgets.Control)2 InteractiveChart (org.eclipse.swtchart.extensions.charts.InteractiveChart)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 IChartField (org.eclipse.linuxtools.dataviewers.charts.provider.IChartField)1 MassifSnapshot (org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 IAxisSet (org.eclipse.swtchart.IAxisSet)1 IAxisTick (org.eclipse.swtchart.IAxisTick)1 IBarSeries (org.eclipse.swtchart.IBarSeries)1