Search in sources :

Example 11 with Item

use of com.vaadin.v7.data.Item in project charts by vaadin.

the class ChartWithExternalContainer method createContainerView1.

private ContainerDataSeries createContainerView1(Container vaadinContainer) {
    ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
    container.setName("Order item quantities");
    container.setPlotOptions(new PlotOptionsPie());
    container.setYPropertyId(ExampleUtil.ORDER_QUANTITY_PROPERTY_ID);
    container.setNamePropertyId(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID);
    return container;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) ContainerDataSeries(com.vaadin.v7.addon.charts.model.ContainerDataSeries)

Example 12 with Item

use of com.vaadin.v7.data.Item in project charts by vaadin.

the class ContainerWithLotsOfData method createContainer.

@SuppressWarnings("unchecked")
private ContainerDataSeries createContainer() {
    IndexedContainer vaadinContainer = new IndexedContainer();
    ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
    vaadinContainer.addContainerProperty("y", Number.class, null);
    for (int i = 0; i < getContainerData().length; i++) {
        Item item = vaadinContainer.addItem(i);
        item.getItemProperty("y").setValue(getContainerData()[i]);
    }
    container.setName("USD to EUR");
    container.setPlotOptions(new PlotOptionsArea());
    container.setYPropertyId("y");
    return container;
}
Also used : Item(com.vaadin.v7.data.Item) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) ContainerDataSeries(com.vaadin.v7.addon.charts.model.ContainerDataSeries)

Example 13 with Item

use of com.vaadin.v7.data.Item in project charts by vaadin.

the class ContainerDataSeriesBeanSerializer method createDataArray.

private ArrayNode createDataArray(Container container, Map<String, Object> pidMap) {
    ArrayNode data = JsonNodeFactory.instance.arrayNode();
    Mode mode = null;
    for (Object o : pidMap.keySet()) {
        if (!(o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1) || o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2))) {
            mode = Mode.OBJECT;
            break;
        }
    }
    Object xProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1);
    if (xProperty == null) {
        xProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1;
    }
    Object yProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2);
    if (yProperty == null) {
        yProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2;
    }
    checkRequiredProperties(container, pidMap, yProperty);
    if (mode != Mode.OBJECT) {
        if (container.getContainerPropertyIds().contains(xProperty)) {
            mode = Mode.XY;
        } else {
            mode = Mode.ONLY_Y;
        }
    }
    for (Object iid : container.getItemIds()) {
        Item item = container.getItem(iid);
        switch(mode) {
            case ONLY_Y:
                addValue(data, item.getItemProperty(yProperty));
                break;
            case XY:
                Property itemPropertyX = item.getItemProperty(xProperty);
                Property itemPropertyY = item.getItemProperty(yProperty);
                if (itemPropertyX.getValue() != null && itemPropertyY.getValue() != null) {
                    ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
                    data.add(entryArray);
                    addValue(entryArray, itemPropertyX);
                    addValue(entryArray, itemPropertyY);
                } else {
                    data.addNull();
                }
                break;
            default:
                // render as json object
                ObjectNode entryObject = JsonNodeFactory.instance.objectNode();
                Property<?> x = item.getItemProperty(xProperty);
                if (x != null) {
                    addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1, x);
                }
                Property<?> y = item.getItemProperty(yProperty);
                if (y != null) {
                    addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2, y);
                }
                Iterator<String> iter = pidMap.keySet().iterator();
                while (iter.hasNext()) {
                    String name = iter.next();
                    Object id = pidMap.get(name);
                    if (!id.equals(xProperty) && !id.equals(yProperty)) {
                        addNamedValue(entryObject, name, item.getItemProperty(id));
                    }
                }
                data.add(entryObject);
                break;
        }
    }
    return data;
}
Also used : Item(com.vaadin.v7.data.Item) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Property(com.vaadin.v7.data.Property)

Example 14 with Item

use of com.vaadin.v7.data.Item in project charts by vaadin.

the class ContainerSeriesJSONSerializationTest method serialize_ContainerWithLowAndHighValues_LowAndHighValuesSerialized.

@Test
public void serialize_ContainerWithLowAndHighValues_LowAndHighValuesSerialized() {
    containerSeries.setHighPropertyId("somehigh");
    containerSeries.setLowPropertyId("somelow");
    vaadinContainer.removeContainerProperty("y");
    vaadinContainer.addContainerProperty("somehigh", Number.class, null);
    vaadinContainer.addContainerProperty("somelow", Number.class, null);
    Item item = vaadinContainer.getItem(vaadinContainer.addItem());
    item.getItemProperty("somehigh").setValue(5);
    item.getItemProperty("somelow").setValue(-5);
    assertEquals("{\"data\":[{\"high\":5,\"low\":-5}]}", toJSON(containerSeries));
}
Also used : Item(com.vaadin.v7.data.Item) Test(org.junit.Test)

Aggregations

Item (com.vaadin.v7.data.Item)11 Test (org.junit.Test)5 ContainerDataSeries (com.vaadin.v7.addon.charts.model.ContainerDataSeries)4 AbstractVaadinChartExample (com.vaadin.addon.charts.examples.AbstractVaadinChartExample)2 Property (com.vaadin.v7.data.Property)2 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Chart (com.vaadin.addon.charts.Chart)1 Configuration (com.vaadin.addon.charts.model.Configuration)1 DataLabelsRange (com.vaadin.addon.charts.model.DataLabelsRange)1 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)1 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)1 PlotOptionsColumnrange (com.vaadin.addon.charts.model.PlotOptionsColumnrange)1 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)1 Tooltip (com.vaadin.addon.charts.model.Tooltip)1 XAxis (com.vaadin.addon.charts.model.XAxis)1 YAxis (com.vaadin.addon.charts.model.YAxis)1 HierarchicalContainer (com.vaadin.v7.data.util.HierarchicalContainer)1