Example usage for com.google.gwt.visualization.client DataTable getNumberOfRows

List of usage examples for com.google.gwt.visualization.client DataTable getNumberOfRows

Introduction

In this page you can find the example usage for com.google.gwt.visualization.client DataTable getNumberOfRows.

Prototype

public final native int getNumberOfRows() ;

Source Link

Usage

From source file:com.google.gwt.visualization.sample.hellovisualization.client.VisualizationDemo.java

License:Apache License

/**
 * Creates a table and a view and shows both next to each other.
 *
 * @return a panel with two tables./*w w  w  .  jav a  2 s. c o m*/
 */
private Widget createDataView() {
    Panel panel = new HorizontalPanel();
    DataTable table = DataTable.create();

    /* create a table with 3 columns */
    table.addColumn(ColumnType.NUMBER, "x");
    table.addColumn(ColumnType.NUMBER, "x * x");
    table.addColumn(ColumnType.NUMBER, "sqrt(x)");
    table.addRows(10);
    for (int i = 0; i < table.getNumberOfRows(); i++) {
        table.setValue(i, 0, i);
        table.setValue(i, 1, i * i);
        table.setValue(i, 2, Math.sqrt(i));
    }
    /* Add original table */
    Panel flowPanel = new FlowPanel();
    panel.add(flowPanel);
    flowPanel.add(new Label("Original DataTable:"));
    Table chart = new Table();
    flowPanel.add(chart);
    chart.draw(table);

    flowPanel = new FlowPanel();
    flowPanel.add(new Label("DataView with columns 2 and 1:"));
    /* create a view on this table, with columns 2 and 1 */
    Table viewChart = new Table();
    DataView view = DataView.create(table);
    view.setColumns(new int[] { 2, 1 });
    flowPanel.add(viewChart);
    panel.add(flowPanel);
    viewChart.draw(view);

    return panel;
}

From source file:com.google.speedtracer.latencydashboard.client.RightPieChart.java

License:Apache License

public void draw(DataTable data, Options options) {
    if (options == null) {
        options = createOptions();//from  w w  w .  ja  va  2 s . c  o m
    }

    // If a datapoint is 0, then it won't consume a color which causes the chart
    // and the legend to get out of sync, so we need to remove the corresponding
    // color before drawing.
    int numRemoved = 0;
    for (int i = 0, n = data.getNumberOfRows(); i < n; i++) {
        if (data.getValueDouble(i, 1) == 0) {
            legendColors.remove(i - numRemoved++);
        }
    }
    String[] colors = new String[legendColors.size()];
    options.setColors(legendColors.toArray(colors));
    pieChart.draw(data, options);
}

From source file:com.square.composant.contrat.square.client.presenter.ContratsPresenter.java

License:Open Source License

/**
 * Construit les donnes de la jauge Banco.
 * @param reserveBanco l'objet contenant les infos de la rserve banco
 * @return les donnes//from w  ww . java2s .  c  o m
 */
private DataTable construireDonneesJaugeBanco(ReserveBancoModel reserveBanco) {
    // Calcul des pourcentages
    if (reserveBanco.getReserveAnnuelle() != 0) {
        final double cent = 100d;
        final double pourcentageReserveConsomme = reserveBanco.getReserveConsommee() * cent
                / reserveBanco.getReserveAnnuelle();
        final double pourcentageReserveRestante = cent - pourcentageReserveConsomme;
        // Cration des donnes
        final DataTable donnees = DataTable.create();
        donnees.addColumn(AbstractDataTable.ColumnType.STRING,
                view.getViewConstants().libelleLegendeJaugeBancoDescription());
        donnees.addColumn(AbstractDataTable.ColumnType.NUMBER,
                view.getViewConstants().libelleLegendeJaugeBancoPourcentage());
        donnees.removeRows(0, donnees.getNumberOfRows());
        donnees.addRows(2);
        donnees.setValue(0, 0, view.getViewConstants().libelleLegendeJaugeBancoConsomme());
        donnees.setValue(0, 1, pourcentageReserveConsomme);
        donnees.setFormattedValue(0, 1, "");
        donnees.setValue(1, 0, view.getViewConstants().libelleLegendeJaugeBancoRestant());
        donnees.setValue(1, 1, pourcentageReserveRestante);
        donnees.setFormattedValue(1, 1, "");
        return donnees;
    } else {
        return null;
    }
}

From source file:com.square.composant.contrat.square.client.presenter.ContratsPresenter.java

License:Open Source License

/**
 * Construit les donnes de statistique Prestations/Cotisations.
 * @param reserveBanco l'objet contenant les infos de la rserve banco
 * @return les donnes/*from ww  w . java  2s.c o m*/
 */
private DataTable construireDonneesStatistiquePC(
        List<RatioPrestationCotisationModel> listeRatiosPrestationCotisation) {
    if (listeRatiosPrestationCotisation != null && listeRatiosPrestationCotisation.size() > 0) {
        // Rcupration de la liste ordonnes des annes et la liste des identifiants de personnes
        final Set<Integer> setAnnees = new TreeSet<Integer>();
        final Set<Long> setIdsPersonnes = new HashSet<Long>();
        final Map<Long, String> mapLibellesPersonnes = new HashMap<Long, String>();
        for (RatioPrestationCotisationModel ratio : listeRatiosPrestationCotisation) {
            setAnnees.add(Integer.valueOf(ratio.getAnnee()));
            setIdsPersonnes.add(ratio.getPersonne().getIdentifiant());
            mapLibellesPersonnes.put(ratio.getPersonne().getIdentifiant(), ratio.getPersonne().getLibelle());
        }
        // Cration de liste  partir des sets
        final Iterator<Integer> iteratorAnnees = setAnnees.iterator();
        final Iterator<Long> iteratorIdsPersonne = setIdsPersonnes.iterator();
        final List<Integer> listeAnnees = new ArrayList<Integer>();
        final List<Long> listeIdsPersonnes = new ArrayList<Long>();
        while (iteratorAnnees.hasNext()) {
            listeAnnees.add(iteratorAnnees.next());
        }
        while (iteratorIdsPersonne.hasNext()) {
            listeIdsPersonnes.add(iteratorIdsPersonne.next());
        }
        // Cration du tableau des ratios
        final double[][] ratios = new double[listeAnnees.size()][listeIdsPersonnes.size()];
        for (RatioPrestationCotisationModel ratio : listeRatiosPrestationCotisation) {
            ratios[listeAnnees.indexOf(Integer.valueOf(ratio.getAnnee()))][listeIdsPersonnes
                    .indexOf(ratio.getPersonne().getIdentifiant())] = ratio.getRatioPrestationCotisation();
        }

        // Cration des donnes
        final DataTable donnees = DataTable.create();
        donnees.addColumn(AbstractDataTable.ColumnType.STRING,
                view.getViewConstants().libelleLegendeStatPCAnnee());
        // Une colonne pour chaque personne
        for (Long identifiantPersonne : listeIdsPersonnes) {
            donnees.addColumn(AbstractDataTable.ColumnType.NUMBER,
                    mapLibellesPersonnes.get(identifiantPersonne));
        }
        donnees.removeRows(0, donnees.getNumberOfRows());
        donnees.addRows(listeAnnees.size());
        // Remplissage des donnes par anne
        for (int idxAnnee = 0; idxAnnee < listeAnnees.size(); idxAnnee++) {
            donnees.setValue(idxAnnee, 0, listeAnnees.get(idxAnnee).toString());
            // Remplissage des donnes par personne
            for (int idxPersonne = 0; idxPersonne < listeIdsPersonnes.size(); idxPersonne++) {
                donnees.setValue(idxAnnee, idxPersonne + 1, ratios[idxAnnee][idxPersonne]);
            }
        }
        return donnees;
    } else {
        return null;
    }
}

From source file:edu.cudenver.bios.glimmpse.client.panels.guided.MeanDifferencesIndependentMeasuresPanel.java

License:Open Source License

@Override
public void onPredictors(HashMap<String, ArrayList<String>> predictorMap, DataTable groups) {
    numGroups = groups.getNumberOfRows();
}

From source file:edu.cudenver.bios.glimmpse.client.panels.guided.RelativeGroupSizePanel.java

License:Open Source License

@Override
public void onPredictors(HashMap<String, ArrayList<String>> predictorMap, DataTable groups) {
    reset();/*ww  w.  j  ava 2s . co  m*/
    if (predictorMap.size() > 0) {
        groupSizesTable.getRowFormatter().setStyleName(0, GlimmpseConstants.STYLE_WIZARD_STEP_TABLE_HEADER);
        groupSizesTable.setWidget(0, 0, new HTML(Glimmpse.constants.relativeGroupSizeTableColumn()));
        for (int col = 0; col < groups.getNumberOfColumns(); col++) {
            groupSizesTable.setWidget(0, col + 1, new HTML(groups.getColumnLabel(col)));
        }
        for (int row = 0; row < groups.getNumberOfRows(); row++) {
            groupSizesTable.setWidget(row + 1, 0, createGroupSizeListBox());
            groupSizesTable.getRowFormatter().setStyleName(row + 1,
                    GlimmpseConstants.STYLE_WIZARD_STEP_TABLE_ROW);
            for (int col = 0; col < groups.getNumberOfColumns(); col++) {
                groupSizesTable.setWidget(row + 1, col + 1, new HTML(groups.getValueString(row, col)));
            }
        }
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.client.monitoring.views.FileSystemView.java

License:Open Source License

public FileSystemView(final RMController controller, String url) {
    setWidth100();/*w  ww.  ja  v  a 2 s.  c  om*/

    final List<String> attrs = new ArrayList<String>();

    attrs.add("DevName");
    attrs.add("DirName");
    attrs.add("Files");
    attrs.add("Options");
    attrs.add("SysTypeName");
    attrs.add("Free");
    attrs.add("Used");
    attrs.add("Total");

    final RMServiceAsync rm = controller.getRMService();
    final RMModel model = controller.getModel();
    final long t = System.currentTimeMillis();

    final LoginModel loginModel = LoginModel.getInstance();

    // loading runtime info
    rm.getNodeMBeansInfo(loginModel.getSessionId(), url, "sigar:Type=FileSystem,Name=*", attrs,
            new AsyncCallback<String>() {
                public void onSuccess(String result) {
                    if (!loginModel.isLoggedIn())
                        return;

                    LogModel.getInstance()
                            .logMessage("Fetched Runtime info in " + (System.currentTimeMillis() - t) + "ms");

                    //{"sigar:Name=/boot,Type=FileSystem":[{"name":"DevName","value":"/dev/sda1"},{"name":"DirName","value":"/boot"},{"name":"Files","value":76912},{"name":"Options","value":"rw"},{"name":"SysTypeName","value":"ext4"},{"name":"Free","value":236558},{"name":"Used","value":60927},{"name":"Total","value":297485}],"sigar:Name=/,Type=FileSystem":[{"name":"DevName","value":"/dev/sda2"},{"name":"DirName","value":"/"},{"name":"Files","value":1921360},{"name":"Options","value":"rw"},{"name":"SysTypeName","value":"ext4"},{"name":"Free","value":15705152},{"name":"Used","value":14532496},{"name":"Total","value":30237648}],"sigar:Name=/local,Type=FileSystem":[{"name":"DevName","value":"/dev/sda5"},{"name":"DirName","value":"/local"},{"name":"Files","value":58851328},{"name":"Options","value":"rw"},{"name":"SysTypeName","value":"ext4"},{"name":"Free","value":916766088},{"name":"Used","value":9996480},{"name":"Total","value":926762568}]}

                    Options opts = Options.create();
                    opts.setLegend(LegendPosition.NONE);
                    opts.setColors("#fcaf3e", "#3a668d", "#35a849", "#fcaf3e", "#24c1ff", "#1e4ed7", "#ef2929",
                            "#000000");

                    JSONObject object = controller.parseJSON(result).isObject();
                    if (object != null) {

                        for (String disk : object.keySet()) {

                            HLayout diskLayout = new HLayout();

                            DataTable pieData = DataTable.create();
                            pieData.addColumn(ColumnType.STRING, "Type");
                            pieData.addColumn(ColumnType.NUMBER, "Bytes");

                            DetailViewer details = new DetailViewer();
                            DetailViewerRecord dv = new DetailViewerRecord();
                            DetailViewerField[] fields = new DetailViewerField[attrs.size()];
                            for (int i = 0; i < fields.length; i++) {
                                fields[i] = new DetailViewerField(attrs.get(i));
                            }
                            details.setFields(fields);

                            JSONArray properties = object.get(disk).isArray();

                            for (int i = 0; i < properties.size(); i++) {
                                String name = properties.get(i).isObject().get("name").isString().stringValue();
                                String value = properties.get(i).isObject().get("value").toString();
                                if (name.equals("Free") || name.equals("Used")) {
                                    pieData.addRow();
                                    pieData.setValue(pieData.getNumberOfRows() - 1, 0, name);
                                    pieData.setValue(pieData.getNumberOfRows() - 1, 1,
                                            properties.get(i).isObject().get("value").isNumber().doubleValue());
                                }

                                if (name.equals("Free") || name.equals("Used") || name.equals("Total")) {
                                    int inMb = Integer.parseInt(value) / 1024;
                                    if (inMb > 1024) {
                                        value = (inMb / 1024) + " Gb";
                                    } else {
                                        value = inMb + " Mb";
                                    }
                                }
                                dv.setAttribute(name, value);
                            }
                            details.setData(new DetailViewerRecord[] { dv });
                            details.setWidth("50%");

                            PieChart pie = new PieChart(pieData, opts);
                            pie.setWidth("50%");
                            pie.draw(pieData, opts);
                            diskLayout.addMember(details);
                            diskLayout.addMember(pie);
                            addMember(diskLayout);
                        }

                    }
                }

                public void onFailure(Throwable caught) {
                    if (JSONUtils.getJsonErrorCode(caught) == 401) {
                        LogModel.getInstance().logMessage("You have been disconnected from the server.");
                    }
                }
            });
}

From source file:org.sonar.plugins.timeline.client.GwtTimeline.java

License:Open Source License

private void renderDataTable(DataTable table) {
    if (table != null && table.getNumberOfRows() > 0) {
        Element content = DOM.getElementById("content");
        int width = content.getClientWidth() > 0 ? content.getClientWidth() : 800;
        Widget toRender = new AnnotatedTimeLine(table, createOptions(), width + "px",
                GwtTimeline.DEFAULT_HEIGHT + "px");
        renderTimeline(toRender);//from ww  w .j a v  a 2 s .c om
    } else {
        renderNoData();
    }
}