Search in sources :

Example 1 with HighchartSeries

use of com.vaadin.addon.charts.client.ui.HighchartSeries in project charts by vaadin.

the class ChartConnector method onStateChanged.

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);
    final HighchartConfig cfg = HighchartConfig.createFromServerSideString(getState().confState, getState().jsonState);
    chartsRenderingObserver.startRendering();
    cfg.setChartsRenderingObserver(chartsRenderingObserver);
    if (hasEventListener(CHART_CLICK_EVENT_ID)) {
        cfg.setClickHandler(new ChartClickHandler() {

            @Override
            public void onClick(ChartClickEvent event) {
                MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event, getWidget());
                rpc.onChartClick(details);
            }
        });
    }
    cfg.setDrilldownHandler(new ChartDrilldownHandler() {

        @Override
        public void onDrilldown(ChartDrilldownEvent event) {
            if (!event.isCategory() && !event.hasDrilldownSeries()) {
                DrilldownEventDetails details = DrilldownEventDetailsBuilder.buildDrilldownEventDetails(event, getWidget());
                rpc.onChartDrilldown(details);
            }
        }

        @Override
        public void onDrillup() {
            rpc.onChartDrillup();
        }
    });
    if (hasEventListener(POINT_CLICK_EVENT_ID)) {
        cfg.setSeriesPointClickHandler(new PointClickHandler() {

            @Override
            public void onClick(PointClickEvent event) {
                MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event, getWidget());
                HighchartPoint point = event.getPoint();
                HighchartSeries series = point.getSeries();
                int seriesIndex = getWidget().getSeriesIndex(series);
                int pointIndex = series.indexOf(point);
                rpc.onPointClick(details, seriesIndex, event.getCategory(), pointIndex);
            }
        });
    }
    if (hasEventListener(CHART_SELECTION_EVENT_ID)) {
        cfg.setChartSelectionHandler(new ChartSelectionHandler() {

            @Override
            public void onSelection(ChartSelectionEvent event) {
                rpc.onSelection(event.getSelectionStart(), event.getSelectionEnd(), event.getValueStart(), event.getValueEnd());
                event.preventDefault();
            }
        });
    }
    // The legendItemClickHandler is always set so that series visibility
    // toggling can be disabled
    cfg.setLegendItemClickHandler(new LegendItemClickHandler() {

        @Override
        public boolean onClick(SeriesEvent event) {
            if (hasEventListener(LEGENDITEM_CLICK_EVENT_ID)) {
                int seriesIndex = getWidget().getSeriesIndex(event.getSeries());
                rpc.onLegendItemClick(seriesIndex, event.getSeriesItemIndex());
            }
            return !getState().seriesVisibilityTogglingDisabled;
        }
    });
    if (hasEventListener(CHECKBOX_CLICK_EVENT_ID)) {
        cfg.setCheckboxClickHandler(new CheckboxClickHandler() {

            @Override
            public void onClick(CheckboxClickEvent event) {
                int seriesIndex = getWidget().getSeriesIndex(event.getSeries());
                rpc.onCheckboxClick(event.isChecked(), seriesIndex, event.getSeriesItemIndex());
            }
        });
    }
    if (hasEventListener(HIDE_SERIES_EVENT_ID)) {
        cfg.setSeriesHideHandler(new SeriesHideHandler() {

            @Override
            public void onHide(SeriesEvent event) {
                int seriesIndex = getWidget().getSeriesIndex(event.getSeries());
                rpc.onSeriesHide(seriesIndex, event.getSeriesItemIndex());
            }
        });
    }
    if (hasEventListener(SHOW_SERIES_EVENT_ID)) {
        cfg.setSeriesShowHandler(new SeriesShowHandler() {

            @Override
            public void onShow(SeriesEvent event) {
                int seriesIndex = getWidget().getSeriesIndex(event.getSeries());
                rpc.onSeriesShow(seriesIndex, event.getSeriesItemIndex());
            }
        });
    }
    if (hasEventListener(X_AXES_EXTREMES_CHANGE_EVENT_ID)) {
        cfg.setXAxesAfterSetExtremeHandler(new AfterSetExtremeHandler() {

            @Override
            public void afterSetExtreme(SetExtremesEvent event) {
                int axisIndex = getWidget().getXAxisIndex(event.getAxis());
                double min = event.getMin();
                double max = event.getMax();
                rpc.onXAxesExtremesChange(axisIndex, min, max);
            }
        });
    }
    if (hasEventListener(Y_AXES_EXTREMES_CHANGE_EVENT_ID)) {
        cfg.setYAxesAfterSetExtremeHandler(new AfterSetExtremeHandler() {

            @Override
            public void afterSetExtreme(SetExtremesEvent event) {
                int axisIndex = getWidget().getYAxisIndex(event.getAxis());
                double min = event.getMin();
                double max = event.getMax();
                rpc.onYAxesExtremesChange(axisIndex, min, max);
            }
        });
    }
    if (hasEventListener(POINT_SELECT_EVENT_ID)) {
        cfg.setPointSelectHandler(new PointSelectHandler() {

            @Override
            public void onSelect(PointEvent event) {
                HighchartPoint point = event.getPoint();
                HighchartSeries series = point.getSeries();
                int seriesIndex = getWidget().getSeriesIndex(series);
                int pointIndex = series.indexOf(point);
                rpc.onPointSelect(seriesIndex, event.getCategory(), pointIndex);
            }
        });
    }
    if (hasEventListener(POINT_UNSELECT_EVENT_ID)) {
        cfg.setPointUnselectHandler(new PointUnselectHandler() {

            @Override
            public void onUnselect(PointEvent event) {
                HighchartPoint point = event.getPoint();
                HighchartSeries series = point.getSeries();
                int seriesIndex = getWidget().getSeriesIndex(series);
                int pointIndex = series.indexOf(point);
                rpc.onPointUnselect(seriesIndex, event.getCategory(), pointIndex);
            }
        });
    }
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            getWidget().init(cfg, getState().timeline);
            int numberOfSeries = getWidget().getNumberOfSeries();
            chartsRenderingObserver.setNumberOfSeries(numberOfSeries);
            // yet
            if (resizeListener == null) {
                resizeListener = new ElementResizeListener() {

                    @Override
                    public void onElementResize(ElementResizeEvent e) {
                        getWidget().updateSize();
                    }
                };
                getLayoutManager().addElementResizeListener(getWidget().getElement(), resizeListener);
            }
            if (BrowserInfo.get().isIE()) {
                // Workaround for Vaadin bug in IE (?), scrollbars...
                ServerConnector parent2 = getParent();
                if (parent2 instanceof WindowConnector) {
                    final WindowConnector w = (WindowConnector) parent2;
                    new Timer() {

                        @Override
                        public void run() {
                            VWindow widget2 = w.getWidget();
                            widget2.setWidth(widget2.getOffsetWidth() + "px");
                            widget2.setHeight(widget2.getOffsetHeight() + "px");
                        }
                    }.schedule(10);
                }
            }
        }
    });
}
Also used : PointClickHandler(com.vaadin.addon.charts.client.ui.PointClickHandler) SeriesHideHandler(com.vaadin.addon.charts.client.ui.SeriesHideHandler) ChartDrilldownHandler(com.vaadin.addon.charts.client.ui.ChartDrilldownHandler) PointClickEvent(com.vaadin.addon.charts.client.ui.PointClickEvent) SeriesEvent(com.vaadin.addon.charts.client.ui.SeriesEvent) SetExtremesEvent(com.vaadin.addon.charts.client.ui.SetExtremesEvent) HighchartPoint(com.vaadin.addon.charts.client.ui.HighchartPoint) LegendItemClickHandler(com.vaadin.addon.charts.client.ui.LegendItemClickHandler) ServerConnector(com.vaadin.client.ServerConnector) AfterSetExtremeHandler(com.vaadin.addon.charts.client.ui.AfterSetExtremeHandler) PointEvent(com.vaadin.addon.charts.client.ui.PointEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SeriesShowHandler(com.vaadin.addon.charts.client.ui.SeriesShowHandler) PointUnselectHandler(com.vaadin.addon.charts.client.ui.PointUnselectHandler) ElementResizeEvent(com.vaadin.client.ui.layout.ElementResizeEvent) ElementResizeListener(com.vaadin.client.ui.layout.ElementResizeListener) CheckboxClickHandler(com.vaadin.addon.charts.client.ui.CheckboxClickHandler) ChartClickHandler(com.vaadin.addon.charts.client.ui.ChartClickHandler) ChartClickEvent(com.vaadin.addon.charts.client.ui.ChartClickEvent) WindowConnector(com.vaadin.client.ui.window.WindowConnector) VWindow(com.vaadin.client.ui.VWindow) ChartDrilldownEvent(com.vaadin.addon.charts.client.ui.ChartDrilldownEvent) ChartSelectionHandler(com.vaadin.addon.charts.client.ui.ChartSelectionHandler) Timer(com.google.gwt.user.client.Timer) HighchartSeries(com.vaadin.addon.charts.client.ui.HighchartSeries) CheckboxClickEvent(com.vaadin.addon.charts.client.ui.CheckboxClickEvent) HighchartConfig(com.vaadin.addon.charts.client.ui.HighchartConfig) ChartSelectionEvent(com.vaadin.addon.charts.client.ui.ChartSelectionEvent) PointSelectHandler(com.vaadin.addon.charts.client.ui.PointSelectHandler)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Timer (com.google.gwt.user.client.Timer)1 AfterSetExtremeHandler (com.vaadin.addon.charts.client.ui.AfterSetExtremeHandler)1 ChartClickEvent (com.vaadin.addon.charts.client.ui.ChartClickEvent)1 ChartClickHandler (com.vaadin.addon.charts.client.ui.ChartClickHandler)1 ChartDrilldownEvent (com.vaadin.addon.charts.client.ui.ChartDrilldownEvent)1 ChartDrilldownHandler (com.vaadin.addon.charts.client.ui.ChartDrilldownHandler)1 ChartSelectionEvent (com.vaadin.addon.charts.client.ui.ChartSelectionEvent)1 ChartSelectionHandler (com.vaadin.addon.charts.client.ui.ChartSelectionHandler)1 CheckboxClickEvent (com.vaadin.addon.charts.client.ui.CheckboxClickEvent)1 CheckboxClickHandler (com.vaadin.addon.charts.client.ui.CheckboxClickHandler)1 HighchartConfig (com.vaadin.addon.charts.client.ui.HighchartConfig)1 HighchartPoint (com.vaadin.addon.charts.client.ui.HighchartPoint)1 HighchartSeries (com.vaadin.addon.charts.client.ui.HighchartSeries)1 LegendItemClickHandler (com.vaadin.addon.charts.client.ui.LegendItemClickHandler)1 PointClickEvent (com.vaadin.addon.charts.client.ui.PointClickEvent)1 PointClickHandler (com.vaadin.addon.charts.client.ui.PointClickHandler)1 PointEvent (com.vaadin.addon.charts.client.ui.PointEvent)1 PointSelectHandler (com.vaadin.addon.charts.client.ui.PointSelectHandler)1 PointUnselectHandler (com.vaadin.addon.charts.client.ui.PointUnselectHandler)1