Search in sources :

Example 1 with NumericalConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer in project tracecompass by tracecompass.

the class NumericalConsumerTest method testResolver.

/**
 * Test the numerical consumer with only the resolver. It should not accept
 * null values
 */
@Test
public void testResolver() {
    IDataChartDescriptor<StubObject, ?> descriptor = fProvider.getDataDescriptor(StubChartProvider.LONG_DESCRIPTOR);
    NumericalConsumer consumer = new NumericalConsumer(INumericalResolver.class.cast(descriptor.getResolver()));
    // Test with a first object
    StubObject obj = new StubObject("str", 1, 10L, 10.0);
    assertTrue(consumer.test(obj));
    consumer.accept(obj);
    assertEquals(Long.valueOf(10L), consumer.getData().get(0));
    // Test with a second object
    obj = new StubObject("str", 1, 20L, 10.0);
    assertTrue(consumer.test(obj));
    consumer.accept(obj);
    assertEquals(Long.valueOf(20L), consumer.getData().get(1));
    obj = new StubObject("str", 1, null, 10.0);
    assertFalse(consumer.test(obj));
    // Test eh minimum and maximum values
    assertEquals(Long.valueOf(10L), consumer.getMin());
    assertEquals(Long.valueOf(20L), consumer.getMax());
}
Also used : INumericalResolver(org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) StubObject(org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject) Test(org.junit.Test)

Example 2 with NumericalConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer in project tracecompass by tracecompass.

the class NumericalConsumerTest method testWithPredicate.

/**
 * Test the numerical consumer with only the resolver and predicate.
 */
@Test
public void testWithPredicate() {
    IDataChartDescriptor<StubObject, ?> descriptor = fProvider.getDataDescriptor(StubChartProvider.LONG_DESCRIPTOR);
    Predicate<@Nullable Number> predicate = d -> true;
    NumericalConsumer consumer = new NumericalConsumer(INumericalResolver.class.cast(descriptor.getResolver()), predicate);
    StubObject obj = new StubObject("str", 1, 10L, 10.0);
    assertTrue(consumer.test(obj));
    consumer.accept(obj);
    assertEquals(Long.valueOf(10L), consumer.getData().get(0));
    obj = new StubObject("str", 1, null, 10.0);
    assertTrue(consumer.test(obj));
    consumer.accept(obj);
    assertEquals(Long.valueOf(0L), consumer.getData().get(1));
}
Also used : INumericalResolver(org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) Nullable(org.eclipse.jdt.annotation.Nullable) StubChartProvider(org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProvider) Assert.assertFalse(org.junit.Assert.assertFalse) Predicate(java.util.function.Predicate) IDataChartDescriptor(org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) NonNull(org.eclipse.jdt.annotation.NonNull) StubObject(org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject) Assert.assertEquals(org.junit.Assert.assertEquals) INumericalResolver(org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) StubObject(org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject) Test(org.junit.Test)

Example 3 with NumericalConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer in project tracecompass by tracecompass.

the class SwtBarChart method configureSeries.

@Override
protected void configureSeries(Map<@NonNull ISeries, Object[]> mapper) {
    XYChartConsumer chartConsumer = getChartConsumer();
    NumericalConsumerAggregator aggregator = (NumericalConsumerAggregator) checkNotNull(chartConsumer.getYAggregator());
    /* Clamp the Y ranges */
    fYRanges = clampInputDataRange(checkNotNull(aggregator.getChartRanges()));
    /* Generate data for each SWT series */
    for (XYSeriesConsumer seriesConsumer : chartConsumer.getSeries()) {
        BarStringConsumer xconsumer = (BarStringConsumer) seriesConsumer.getXConsumer();
        NumericalConsumer yConsumer = (NumericalConsumer) seriesConsumer.getYConsumer();
        Object[] object = seriesConsumer.getConsumedElements().toArray();
        /* Generate categories for the X axis */
        Collection<@Nullable String> list = xconsumer.getList();
        /*
             * The categories are nullable, but swtchart does not support null
             * values, so we'll update the null values to an empty string
             */
        String @Nullable [] categories = list.toArray(new String[list.size()]);
        for (int i = 0; i < list.size(); i++) {
            if (categories[i] == null) {
                // $NON-NLS-1$
                categories[i] = "?";
            }
        }
        fCategories = categories;
        /* Generate numerical data for the Y axis */
        List<Number> data = yConsumer.getData();
        double[] xData = new double[data.size()];
        double[] yData = new double[data.size()];
        for (int i = 0; i < yData.length; i++) {
            Number number = checkNotNull(data.get(i));
            xData[i] = i;
            yData[i] = fYRanges.getInternalValue(number).doubleValue();
        }
        /* Set the data for the SWT series */
        ISeries<Integer> series = checkNotNull(getSeriesMap().get(seriesConsumer.getSeries()));
        series.setDataModel(new DoubleArraySeriesModel(xData, yData));
        /* Create a series mapper */
        mapper.put(series, checkNotNull(object));
    }
}
Also used : DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) XYSeriesConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer) BarStringConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer) XYChartConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer) Point(org.eclipse.swt.graphics.Point) NumericalConsumerAggregator(org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with NumericalConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer in project tracecompass by tracecompass.

the class SwtScatterChart method configureSeries.

@Override
protected void configureSeries(Map<@NonNull ISeries, Object[]> mapper) {
    XYChartConsumer chartConsumer = getChartConsumer();
    /* Obtain the X ranges if possible */
    NumericalConsumerAggregator xAggregator = (NumericalConsumerAggregator) chartConsumer.getXAggregator();
    if (xAggregator != null) {
        if (getModel().isXLogscale()) {
            fXRanges = clampInputDataRange(xAggregator.getChartRanges());
        } else {
            fXRanges = xAggregator.getChartRanges();
        }
    }
    /* Obtain the Y ranges if possible */
    NumericalConsumerAggregator yAggregator = (NumericalConsumerAggregator) chartConsumer.getYAggregator();
    if (yAggregator != null) {
        if (getModel().isYLogscale()) {
            fYRanges = clampInputDataRange(yAggregator.getChartRanges());
        } else {
            fYRanges = yAggregator.getChartRanges();
        }
    }
    /* Generate data for each SWT series */
    for (XYSeriesConsumer seriesConsumer : chartConsumer.getSeries()) {
        double[] xData;
        double[] yData;
        Object[] object = seriesConsumer.getConsumedElements().toArray();
        /* Generate data for the X axis */
        if (getXDescriptorsInfo().areNumerical()) {
            NumericalConsumer consumer = (NumericalConsumer) seriesConsumer.getXConsumer();
            List<Number> data = consumer.getData();
            int size = data.size();
            xData = new double[size];
            for (int i = 0; i < size; i++) {
                Number number = checkNotNull(data.get(i));
                xData[i] = fXRanges.getInternalValue(number).doubleValue();
            }
        } else {
            ScatterStringConsumer consumer = (ScatterStringConsumer) seriesConsumer.getXConsumer();
            List<String> list = consumer.getList();
            xData = new double[list.size()];
            for (int i = 0; i < xData.length; i++) {
                String str = list.get(i);
                xData[i] = checkNotNull(fXStringMap.get(str));
            }
        }
        /* Generate data for the Y axis */
        if (getYDescriptorsInfo().areNumerical()) {
            NumericalConsumer consumer = (NumericalConsumer) seriesConsumer.getYConsumer();
            List<Number> data = consumer.getData();
            yData = new double[data.size()];
            for (int i = 0; i < yData.length; i++) {
                Number number = checkNotNull(data.get(i));
                yData[i] = fYRanges.getInternalValue(number).doubleValue();
            }
        } else {
            ScatterStringConsumer consumer = (ScatterStringConsumer) seriesConsumer.getYConsumer();
            List<String> list = consumer.getList();
            yData = new double[list.size()];
            for (int i = 0; i < yData.length; i++) {
                String str = list.get(i);
                yData[i] = checkNotNull(fYStringMap.get(str));
            }
        }
        /* Set the data for the SWT series */
        ISeries<Integer> series = checkNotNull(getSeriesMap().get(seriesConsumer.getSeries()));
        series.setDataModel(new DoubleArraySeriesModel(xData, yData));
        /* Create a series mapper */
        mapper.put(series, checkNotNull(object));
    }
}
Also used : DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) XYSeriesConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer) XYChartConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer) Point(org.eclipse.swt.graphics.Point) NumericalConsumerAggregator(org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) ScatterStringConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.ScatterStringConsumer)

Example 5 with NumericalConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer in project tracecompass by tracecompass.

the class NumericalConsumerAggregator method accept.

// ------------------------------------------------------------------------
// Overriden Methods
// ------------------------------------------------------------------------
@Override
public void accept(IDataConsumer obj) {
    NumericalConsumer consumer = (NumericalConsumer) obj;
    BigDecimal nextMin = new BigDecimal(consumer.getMin().toString());
    BigDecimal nextMax = new BigDecimal(consumer.getMax().toString());
    BigDecimal min = fMinimum;
    BigDecimal max = fMaximum;
    /* Set initial min and max values */
    if (min == null || max == null) {
        fMinimum = nextMin;
        fMaximum = nextMax;
        return;
    }
    /* Update min and max values */
    fMinimum = min.min(nextMin);
    fMaximum = max.max(nextMax);
}
Also used : NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) BigDecimal(java.math.BigDecimal)

Aggregations

NumericalConsumer (org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer)5 Nullable (org.eclipse.jdt.annotation.Nullable)2 Point (org.eclipse.swt.graphics.Point)2 DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)2 INumericalResolver (org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver)2 NumericalConsumerAggregator (org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator)2 XYChartConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer)2 XYSeriesConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer)2 StubObject (org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 Predicate (java.util.function.Predicate)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 IDataChartDescriptor (org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor)1 BarStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer)1 ScatterStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.ScatterStringConsumer)1 StubChartProvider (org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProvider)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1