use of com.vaadin.client.ui.layout.ElementResizeListener 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);
}
}
}
});
}
Aggregations