コード例 #1
0
ファイル: Trends.java プロジェクト: Gorbush/jagger
  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;
  }