use of org.openremote.model.datapoint.DatapointInterval in project openremote by openremote.
the class DatapointBrowser method createChart.
protected void createChart() {
addLabel(environment.getMessages().historicalData());
Canvas canvas = Canvas.createIfSupported();
if (canvas == null) {
add(new Label(environment.getMessages().canvasNotSupported()));
return;
}
canvas.getCanvasElement().setWidth(width);
canvas.getCanvasElement().setHeight(height);
FlowPanel canvasContainer = new FlowPanel();
canvasContainer.setWidth(width + "px");
canvasContainer.setHeight(height + "px");
canvasContainer.getElement().getStyle().setProperty("margin", "0 auto");
canvasContainer.add(canvas);
add(canvasContainer);
Form controlForm = new Form();
controlForm.getElement().getStyle().setWidth(width, PX);
controlForm.getElement().getStyle().setMarginTop(0.4, EM);
controlForm.getElement().getStyle().setProperty("margin", "0 auto");
add(controlForm);
FormGroup controlFormGroup = new FormGroup();
controlForm.add(controlFormGroup);
FormLabel controlFormLabel = new FormLabel(environment.getMessages().showChartAggregatedFor());
controlFormLabel.addStyleName("end-justified");
controlFormGroup.setFormLabel(controlFormLabel);
FormField controlFormField = new FormField();
controlFormGroup.setFormField(controlFormField);
intervalListBox = new FormValueListBox<>(new AbstractRenderer<DatapointInterval>() {
@Override
public String render(DatapointInterval interval) {
return environment.getMessages().datapointInterval(interval.name());
}
});
intervalListBox.addValueChangeHandler(event -> refresh(timestamp));
intervalListBox.setValue(interval);
intervalListBox.setAcceptableValues(Arrays.asList(DatapointInterval.values()));
intervalListBox.setEnabled(true);
controlFormField.add(intervalListBox);
timeOutput = new FormOutputText();
timeOutput.addStyleName("flex");
timeOutput.getElement().getStyle().setFontSize(0.8, EM);
controlFormField.add(timeOutput);
FormGroupActions controlFormActions = new FormGroupActions();
controlFormGroup.setFormGroupActions(controlFormActions);
FormButton previousButton = new FormButton();
previousButton.setIcon("arrow-circle-left");
previousButton.setText(environment.getMessages().previous());
previousButton.addClickHandler(event -> refresh(calculateTimestamp(true)));
controlFormActions.add(previousButton);
nextButton = new FormButton();
nextButton.setIcon("arrow-circle-right");
nextButton.setText(environment.getMessages().next());
nextButton.addClickHandler(event -> refresh(calculateTimestamp(false)));
controlFormActions.add(nextButton);
chart = ChartUtil.createLineChart(canvas.getContext2d());
// TODO: Ugly, sometimes the chart is not ready (chart == undefined but !null in Java...) so we wait a bit
Browser.getWindow().setTimeout(() -> refresh(timestamp), 50);
}
Aggregations