Ejemplo n.º 1
0
  public Chart createValueChart(String title) {
    Chart chart = createChart(title, "Count");
    chart.addSeries(
        chart.createSeries().setName("Count").setPoints(values.toArray(new Number[values.size()])));

    return chart;
  }
Ejemplo n.º 2
0
 public Chart createPercentageChart(String title) {
   Chart chart = createChart(title, "%");
   chart.addSeries(
       chart
           .createSeries()
           .setName("%")
           .setPoints(percentages.toArray(new Number[percentages.size()])));
   return chart;
 }
Ejemplo n.º 3
0
 private void initSplineChart(String title) {
   chart
       .setType(Series.Type.SPLINE) //
       .setChartTitleText(title) //
       .setSplinePlotOptions(
           new SplinePlotOptions() //
               .setDataLabels(new DataLabels().setEnabled(false)) //
               .setEnableMouseTracking(false) //
               .setMarker(new Marker().setEnabled(false)) //
           );
 }
Ejemplo n.º 4
0
  private void setDefaultChartOptions(String yTitle, String yOppositeTitle, String[] seriesName) {
    setDefaultChartOptions(yTitle, seriesName, true);

    chart
        .getYAxis(1)
        .setAxisTitle(
            new AxisTitle() //
                .setText(yOppositeTitle) //
                .setAlign(AxisTitle.Align.MIDDLE)) //
        .setOpposite(true) //
        .setAllowDecimals(false) //
        .setMin(0);
  }
Ejemplo n.º 5
0
  private Chart createChart(String title, String yaxisTitle) {
    Chart chart =
        new Chart()
            .setType(Series.Type.BAR)
            .setChartTitleText(title)
            .setBarPlotOptions(
                new BarPlotOptions()
                    .setAnimation(false)
                    .setDataLabels(new DataLabels().setEnabled(true)))
            .setLegend(new Legend().setEnabled(false))
            .setCredits(new Credits().setEnabled(false))
            .setHeight(categories.size() * 30 + 100);

    chart.getXAxis().setCategories(categories.toArray(new String[categories.size()]));

    chart
        .getYAxis()
        .setAxisTitle(new AxisTitle().setText(yaxisTitle).setAlign(AxisTitle.Align.HIGH));

    chart.setAnimation(false);

    return chart;
  }
Ejemplo n.º 6
0
  private void setDefaultChartOptions(
      String yTitle, String[] seriesName, boolean hasOppositeTitle) {
    chart
        .setToolTip(new ToolTip().setEnabled(false)) //
        .setLegend(new Legend().setEnabled(true)) //
        .setCredits(
            new Credits().setEnabled(false) //
            );

    chart
        .getYAxis(0)
        .setAxisTitle(new AxisTitle().setText(yTitle).setAlign(AxisTitle.Align.MIDDLE))
        .setAllowDecimals(false);

    chart
        .getXAxis() //
        .setType(Axis.Type.DATE_TIME) //
        .setLabels(
            new XAxisLabels() //
                .setRotation(-45) //
                .setAlign(Labels.Align.RIGHT)
                .setFormatter(
                    new AxisLabelsFormatter() {
                      @Override
                      public String format(AxisLabelsData axisLabelsData) {
                        if (axisLabelsData.getValueAsDouble() < 0) {
                          return "";
                        }
                        return DateTimeFormat.getFormat("mm:ss")
                            .format(new Date(axisLabelsData.getValueAsLong()));
                      }
                    }) //
            );

    for (int i = 0; i < seriesName.length; i++) {
      if (hasOppositeTitle) {
        chart.addSeries(chart.createSeries().setName(seriesName[i]).setYAxis(i));
      } else {
        chart.addSeries(chart.createSeries().setName(seriesName[i]));
      }
    }
  }
Ejemplo n.º 7
0
 public void updateChart(int yAxis, int serie, double x, double y) {
   chart.getXAxis().setExtremes(x - duration, x);
   chart.getSeries()[serie].setYAxis(yAxis).addPoint(x, y, true, false, true);
 }
Ejemplo n.º 8
0
  /** This is the entry point method. */
  public void onModuleLoad() {

    final VerticalPanel progressBarPanel = new VerticalPanel();

    final Map<String, ProgressBar> progressBars = new LinkedHashMap<String, ProgressBar>();
    final Map<String, Image> cancelButtons = new LinkedHashMap<String, Image>();
    final Map<String, Image> extensionsImages = new LinkedHashMap<String, Image>();
    final Map<String, Point> pointsByFile = new LinkedHashMap<>();

    final Chart chart = new Chart().setType(Series.Type.PIE).setMarginRight(0);

    chart.setToolTip(
        new ToolTip()
            .setFormatter(
                new ToolTipFormatter() {
                  public String format(ToolTipData toolTipData) {
                    return "<b>"
                        + toolTipData.getSeriesName()
                        + "</b><br/>"
                        + toolTipData.getPointName()
                        + ": "
                        + toolTipData.getYAsDouble()
                        + " %";
                  }
                }));

    ChartTitle chartTitle = new ChartTitle();
    chartTitle.setText("Progress");
    ChartSubtitle subTitle = new ChartSubtitle();
    subTitle.setText(null);
    chart.setTitle(chartTitle, subTitle);
    chart.setPlotBackgroundColor("none");
    chart.setPlotBorderWidth(0);
    chart.setPlotShadow(false);
    chart.setSizeToMatchContainer();
    chart.setTitle("Progress");
    chart.setWidth("300px");
    chart.setHeight("300px");

    final Series localSeries = chart.createSeries();
    localSeries.setPlotOptions(
        new PiePlotOptions()
            .setSize(100)
            .setInnerSize(.0)
            .setDataLabels(new DataLabels().setEnabled(true)));

    final Series globalSeries = chart.createSeries();
    globalSeries.setPlotOptions(
        new PiePlotOptions()
            .setSize(.45)
            .setInnerSize(.20)
            .setDataLabels(new DataLabels().setEnabled(true)));

    chart.addSeries(localSeries, true, true);
    chart.addSeries(globalSeries, false, true);
    final Point localPoint = new Point("initial file", 0);
    localPoint.setColor("#2d4b6d");
    final Uploader uploader = new Uploader();
    uploader
        .setUploadURL("/FileServletUpload")
        .setButtonWidth(133)
        .setButtonHeight(22)
        .setFileSizeLimit("50 MB")
        .setAjaxUploadEnabled(true)
        .setButtonCursor(Uploader.Cursor.HAND)
        .setButtonAction(Uploader.ButtonAction.SELECT_FILES)
        .setFileQueuedHandler(
            new FileQueuedHandler() {
              public boolean onFileQueued(final FileQueuedEvent fileQueuedEvent) {
                File file = fileQueuedEvent.getFile();
                // Create a Progress Bar for this file
                final ProgressBar progressBar =
                    new ProgressBar(0.0, 1.0, 0.0, new CancelProgressBarTextFormatter());
                progressBar.setTextVisible(true);
                progressBar.setTitle(file.getName());
                progressBar.setHeight("20px");
                progressBar.setWidth("200px");
                progressBars.put(file.getId(), progressBar);
                // Add Cancel Button Image
                final Image cancelButton = new Image(resources.cancelButton());
                cancelButton.setStyleName("cancelButton");
                cancelButton.addClickHandler(
                    new ClickHandler() {
                      public void onClick(ClickEvent event) {
                        File file = fileQueuedEvent.getFile();
                        uploader.cancelUpload(file.getId(), false);
                        progressBars.get(file.getId()).setProgress(-1.0d);
                        cancelButton.removeFromParent();
                      }
                    });
                cancelButtons.put(file.getId(), cancelButton);
                final Image image = new Image(ResourceUtils.getResource(file.getType()));
                image.setWidth("32px");
                image.setHeight("32px");
                extensionsImages.put(file.getId(), image);
                localPoint.update(new Point(file.getType(), file.getTimeRemaining()));
                pointsByFile.put(file.getId(), localPoint);
                localSeries.addPoint(localPoint);
                // Add the Bar and Button to the interface
                HorizontalPanel progressBarAndButtonPanel = new HorizontalPanel();
                progressBarAndButtonPanel.add(progressBar);
                progressBarAndButtonPanel.add(cancelButton);
                progressBarAndButtonPanel.add(image);
                progressBarPanel.add(progressBarAndButtonPanel);
                return true;
              }
            })
        .setUploadProgressHandler(
            new UploadProgressHandler() {
              public boolean onUploadProgress(UploadProgressEvent uploadProgressEvent) {
                File file = uploadProgressEvent.getFile();
                String fileName = file.getName();
                ProgressBar progressBar = progressBars.get(file.getId());
                double value =
                    (double) uploadProgressEvent.getBytesComplete()
                        / uploadProgressEvent.getBytesTotal();
                progressBar.setProgress(value);
                Point point = pointsByFile.get(file.getId());
                point.update(new Point(fileName, file.getPercentUploaded()));
                globalSeries.addPoint(new Point(fileName, file.getPercentUploaded()));
                return true;
              }
            })
        .setUploadCompleteHandler(
            new UploadCompleteHandler() {
              public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
                File file = uploadCompleteEvent.getFile();
                cancelButtons.get(file.getId()).removeFromParent();
                Point point = pointsByFile.get(file.getId());
                point.update(new Point(file.getName(), file.getPercentUploaded()));
                localSeries.removePoint(point);
                uploader.startUpload();
                return true;
              }
            })
        .setFileDialogStartHandler(
            new FileDialogStartHandler() {
              public boolean onFileDialogStartEvent(FileDialogStartEvent fileDialogStartEvent) {
                if (uploader.getStats().getUploadsInProgress() <= 0) {
                  // Clear the uploads that have completed, if none
                  // are in process
                  progressBarPanel.clear();
                  progressBars.clear();
                  cancelButtons.clear();
                  pointsByFile.clear();
                  extensionsImages.clear();
                }
                return true;
              }
            })
        .setFileDialogCompleteHandler(
            new FileDialogCompleteHandler() {
              public boolean onFileDialogComplete(FileDialogCompleteEvent fileDialogCompleteEvent) {
                if (fileDialogCompleteEvent.getTotalFilesInQueue() > 0) {

                  if (uploader.getStats().getUploadsInProgress() <= 0) {
                    uploader.startUpload();
                  }
                }
                return true;
              }
            })
        .setFileQueueErrorHandler(
            new FileQueueErrorHandler() {
              public boolean onFileQueueError(FileQueueErrorEvent fileQueueErrorEvent) {
                Window.alert(
                    "Upload of file "
                        + fileQueueErrorEvent.getFile().getName()
                        + " failed due to ["
                        + fileQueueErrorEvent.getErrorCode().toString()
                        + "]: "
                        + fileQueueErrorEvent.getMessage());
                return true;
              }
            })
        .setUploadErrorHandler(
            new UploadErrorHandler() {
              public boolean onUploadError(UploadErrorEvent uploadErrorEvent) {
                cancelButtons.get(uploadErrorEvent.getFile().getId()).removeFromParent();
                Window.alert(
                    "Upload of file "
                        + uploadErrorEvent.getFile().getName()
                        + " failed due to ["
                        + uploadErrorEvent.getErrorCode().toString()
                        + "]: "
                        + uploadErrorEvent.getMessage());
                return true;
              }
            });

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(uploader);
    if (Uploader.isAjaxUploadWithProgressEventsSupported()) {
      final Label dropFilesLabel = new Label("Drop Files Here");
      dropFilesLabel.setStyleName("dropFilesLabel");
      dropFilesLabel.addDragOverHandler(
          new DragOverHandler() {
            public void onDragOver(DragOverEvent event) {
              if (!uploader.getButtonDisabled()) {
                dropFilesLabel.addStyleName("dropFilesLabelHover");
              }
            }
          });
      dropFilesLabel.addDragLeaveHandler(
          new DragLeaveHandler() {
            public void onDragLeave(DragLeaveEvent event) {
              dropFilesLabel.removeStyleName("dropFilesLabelHover");
            }
          });
      dropFilesLabel.addDropHandler(
          new DropHandler() {
            public void onDrop(DropEvent event) {
              dropFilesLabel.removeStyleName("dropFilesLabelHover");

              if (uploader.getStats().getUploadsInProgress() <= 0) {
                progressBarPanel.clear();
                progressBars.clear();
                cancelButtons.clear();
              }

              uploader.addFilesToQueue(Uploader.getDroppedFiles(event.getNativeEvent()));
              event.preventDefault();
            }
          });
      verticalPanel.add(dropFilesLabel);
    }

    // noinspection GwtToHtmlReferences
    RootPanel.get("uploaderContainer").add(verticalPanel);
    RootPanel.get("progressContainer").add(progressBarPanel);
    RootPanel.get("chartContainer").add(chart);
  }