Exemplo n.º 1
0
  private void renderPlots(
      HTMLPanel panel,
      List<PlotSeriesDto> plotSeriesDtoList,
      String id,
      double yMinimum,
      boolean isMetric) {
    panel.add(loadIndicator);

    SimplePlot redrawingPlot = null;

    VerticalPanel plotGroupPanel = new VerticalPanel();
    plotGroupPanel.setWidth("100%");
    plotGroupPanel.getElement().setId(id);

    for (PlotSeriesDto plotSeriesDto : plotSeriesDtoList) {
      Markings markings = null;
      if (plotSeriesDto.getMarkingSeries() != null) {
        markings = new Markings();
        for (MarkingDto plotDatasetDto : plotSeriesDto.getMarkingSeries()) {
          double x = plotDatasetDto.getValue();
          markings.addMarking(
              new Marking()
                  .setX(new Range(x, x))
                  .setLineWidth(1)
                  .setColor(plotDatasetDto.getColor()));
        }

        markingsMap.put(id, new TreeSet<MarkingDto>(plotSeriesDto.getMarkingSeries()));
      }

      final SimplePlot plot =
          createPlot(id, markings, plotSeriesDto.getXAxisLabel(), yMinimum, isMetric);
      redrawingPlot = plot;
      PlotModel plotModel = plot.getModel();

      for (PlotDatasetDto plotDatasetDto : plotSeriesDto.getPlotSeries()) {
        SeriesHandler handler =
            plotModel.addSeries(plotDatasetDto.getLegend(), plotDatasetDto.getColor());

        // Populate plot with data
        for (PointDto pointDto : plotDatasetDto.getPlotData()) {
          handler.add(new DataPoint(pointDto.getX(), pointDto.getY()));
        }
      }

      // Add X axis label
      Label xLabel = new Label(plotSeriesDto.getXAxisLabel());
      xLabel.addStyleName(getResources().css().xAxisLabel());

      Label plotHeader = new Label(plotSeriesDto.getPlotHeader());
      plotHeader.addStyleName(getResources().css().plotHeader());

      Label plotLegend = new Label("PLOT LEGEND");
      plotLegend.addStyleName(getResources().css().plotLegend());

      VerticalPanel vp = new VerticalPanel();
      vp.setWidth("100%");

      Label panLeftLabel = new Label();
      panLeftLabel.addStyleName(getResources().css().panLabel());
      panLeftLabel.getElement().appendChild(new Image(getResources().getArrowLeft()).getElement());
      panLeftLabel.addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              plot.pan(new Pan().setLeft(-100));
            }
          });

      Label panRightLabel = new Label();
      panRightLabel.addStyleName(getResources().css().panLabel());
      panRightLabel
          .getElement()
          .appendChild(new Image(getResources().getArrowRight()).getElement());
      panRightLabel.addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              plot.pan(new Pan().setLeft(100));
            }
          });

      Label zoomInLabel = new Label("Zoom In");
      zoomInLabel.addStyleName(getResources().css().zoomLabel());
      zoomInLabel.addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              plot.zoom();
            }
          });

      Label zoomOutLabel = new Label("Zoom Out");
      zoomOutLabel.addStyleName(getResources().css().zoomLabel());
      zoomOutLabel.addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              plot.zoomOut();
            }
          });

      FlowPanel zoomPanel = new FlowPanel();
      zoomPanel.addStyleName(getResources().css().zoomPanel());
      zoomPanel.add(panLeftLabel);
      zoomPanel.add(panRightLabel);
      zoomPanel.add(zoomInLabel);
      zoomPanel.add(zoomOutLabel);

      vp.add(plotHeader);
      vp.add(zoomPanel);
      vp.add(plot);
      vp.add(xLabel);
      // Will be added if there is need it
      // vp.add(plotLegend);

      plotGroupPanel.add(vp);
    }
    int loadingId = panel.getWidgetCount() - 1;
    panel.remove(loadingId);
    panel.add(plotGroupPanel);

    // Redraw plot
    if (redrawingPlot != null) {
      redrawingPlot.redraw();
    }
  }
Exemplo n.º 2
0
  private SimplePlot createPlot(
      final String id, Markings markings, String xAxisLabel, double yMinimum, boolean isMetric) {
    PlotOptions plotOptions = new PlotOptions();
    plotOptions.setZoomOptions(new ZoomOptions().setAmount(1.02));
    plotOptions.setGlobalSeriesOptions(
        new GlobalSeriesOptions()
            .setLineSeriesOptions(
                new LineSeriesOptions().setLineWidth(1).setShow(true).setFill(0.1))
            .setPointsOptions(new PointsSeriesOptions().setRadius(1).setShow(true))
            .setShadowSize(0d));

    plotOptions.setPanOptions(new PanOptions().setInteractive(true));

    if (isMetric) {
      plotOptions.addXAxisOptions(
          new AxisOptions()
              .setZoomRange(true)
              .setTickDecimals(0)
              .setTickFormatter(
                  new TickFormatter() {
                    @Override
                    public String formatTickValue(double tickValue, Axis axis) {
                      if (tickValue >= 0 && tickValue < chosenSessions.size())
                        return chosenSessions.get((int) tickValue);
                      else return "";
                    }
                  }));
    } else {
      plotOptions.addXAxisOptions(new AxisOptions().setZoomRange(true).setMinimum(0));
    }

    plotOptions.addYAxisOptions(new AxisOptions().setZoomRange(false).setMinimum(yMinimum));

    plotOptions.setLegendOptions(new LegendOptions().setNumOfColumns(2));

    if (markings == null) {
      // Make the grid hoverable
      plotOptions.setGridOptions(new GridOptions().setHoverable(true));
    } else {
      // Make the grid hoverable and add  markings
      plotOptions.setGridOptions(
          new GridOptions().setHoverable(true).setMarkings(markings).setClickable(true));
    }

    // create the plot
    SimplePlot plot = new SimplePlot(plotOptions);
    plot.setHeight(200);
    plot.setWidth("100%");

    final PopupPanel popup = new PopupPanel();
    popup.addStyleName(getResources().css().infoPanel());
    final HTML popupPanelContent = new HTML();
    popup.add(popupPanelContent);

    // add hover listener
    if (isMetric) {
      plot.addHoverListener(
          new ShowCurrentValueHoverListener(popup, popupPanelContent, xAxisLabel, chosenSessions),
          false);
    } else {
      plot.addHoverListener(
          new ShowCurrentValueHoverListener(popup, popupPanelContent, xAxisLabel, null), false);
    }

    if (!isMetric && markings != null && !markingsMap.isEmpty()) {
      final PopupPanel taskInfoPanel = new PopupPanel();
      taskInfoPanel.setWidth("200px");
      taskInfoPanel.addStyleName(getResources().css().infoPanel());
      final HTML taskInfoPanelContent = new HTML();
      taskInfoPanel.add(taskInfoPanelContent);
      taskInfoPanel.setAutoHideEnabled(true);

      plot.addClickListener(
          new ShowTaskDetailsListener(id, markingsMap, taskInfoPanel, 200, taskInfoPanelContent),
          false);
    }

    return plot;
  }