Search in sources :

Example 6 with GraphItem

use of org.netxms.client.datacollection.GraphItem in project netxms by netxms.

the class DrawGraph method onCreateStep2.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.activities.AbstractClientActivity#onCreateStep2(android.os.Bundle)
	 */
@Override
protected void onCreateStep2(Bundle savedInstanceState) {
    sp = PreferenceManager.getDefaultSharedPreferences(this);
    dialog = new ProgressDialog(this);
    setContentView(R.layout.graphics);
    // boolean showLegend = getIntent().getBooleanExtra("showLegend", true);
    numGraphs = getIntent().getIntExtra("numGraphs", 0);
    if (numGraphs > 0) {
        items = new GraphItem[numGraphs];
        itemStyles = new GraphItemStyle[numGraphs];
        ArrayList<Integer> nodeIdList = getIntent().getIntegerArrayListExtra("nodeIdList");
        ArrayList<Integer> dciIdList = getIntent().getIntegerArrayListExtra("dciIdList");
        ArrayList<Integer> colorList = getIntent().getIntegerArrayListExtra("colorList");
        ArrayList<Integer> lineWidthList = getIntent().getIntegerArrayListExtra("lineWidthList");
        ArrayList<String> nameList = getIntent().getStringArrayListExtra("nameList");
        for (int i = 0; i < numGraphs; i++) {
            items[i] = new GraphItem();
            items[i].setNodeId(nodeIdList.get(i));
            items[i].setDciId(dciIdList.get(i));
            items[i].setDescription(nameList.get(i));
            itemStyles[i] = new GraphItemStyle();
            itemStyles[i].setColor(colorList.get(i) | 0xFF000000);
            itemStyles[i].setLineWidth(lineWidthList.get(i));
        }
        timeFrom = getIntent().getLongExtra("timeFrom", 0);
        timeTo = getIntent().getLongExtra("timeTo", 0);
        graphTitle = getIntent().getStringExtra("graphTitle");
    }
    graphView = new LineGraphView(this, "");
    graphView.getGraphViewStyle().setVerticalLabelsColor(Color.WHITE);
    graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.WHITE);
    graphView.getGraphViewStyle().setTextSize(Integer.parseInt(sp.getString("global.graph.textsize", "10")));
    graphView.getGraphViewStyle().setLegendWidth(240);
    graphView.setCustomLabelFormatter(new CustomLabel(Integer.parseInt(sp.getString("global.multipliers", "1")), (timeTo - timeFrom) > 86400 * 1000));
    // TOOD: 2014May25 Find a best way to handle this setting
    // graphView.setShowLegend(showLegend);
    graphView.setShowLegend(sp.getBoolean("global.graph.legend", true));
    graphView.setLegendAlign(LegendAlign.TOP);
    graphView.setScalable(true);
    graphView.setScrollable(true);
    TextView title = (TextView) findViewById(R.id.ScreenTitlePrimary);
    title.setText(R.string.graph_title);
}
Also used : LineGraphView(com.jjoe64.graphview.LineGraphView) CustomLabel(org.netxms.ui.android.helpers.CustomLabel) GraphItem(org.netxms.client.datacollection.GraphItem) GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle) TextView(android.widget.TextView) ProgressDialog(android.app.ProgressDialog)

Example 7 with GraphItem

use of org.netxms.client.datacollection.GraphItem in project netxms by netxms.

the class AbstractComparisonChart method onCreateStep2.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.activities.AbstractClientActivity#onCreateStep2(android.os.Bundle)
	 */
@Override
protected void onCreateStep2(Bundle savedInstanceState) {
    dialog = new ProgressDialog(this);
    setContentView(R.layout.graphics);
    int numItems = getIntent().getIntExtra("numItems", 0);
    if (numItems > 0) {
        items = new GraphItem[numItems];
        values = new double[numItems];
        ArrayList<Integer> nodeIdList = getIntent().getIntegerArrayListExtra("nodeIdList");
        ArrayList<Integer> dciIdList = getIntent().getIntegerArrayListExtra("dciIdList");
        ArrayList<String> nameList = getIntent().getStringArrayListExtra("nameList");
        colorList = getIntent().getIntegerArrayListExtra("colorList");
        for (int i = 0; i < numItems; i++) {
            items[i] = new GraphItem();
            items[i].setNodeId(nodeIdList.get(i));
            items[i].setDciId(dciIdList.get(i));
            items[i].setDescription(nameList.get(i));
        }
        graphTitle = getIntent().getStringExtra("graphTitle");
    }
    TextView title = (TextView) findViewById(R.id.ScreenTitlePrimary);
    title.setText(R.string.graph_title);
}
Also used : GraphItem(org.netxms.client.datacollection.GraphItem) TextView(android.widget.TextView) ProgressDialog(android.app.ProgressDialog)

Example 8 with GraphItem

use of org.netxms.client.datacollection.GraphItem in project netxms by netxms.

the class TableComparisonChartElement method updateChart.

/**
 * Update chart with new data
 *
 * @param data
 */
private void updateChart(final Table data) {
    // FIXME //$NON-NLS-1$
    String instanceColumn = (config.getInstanceColumn() != null) ? config.getInstanceColumn() : "";
    if (instanceColumn == null)
        return;
    final int icIndex = data.getColumnIndex(instanceColumn);
    final int dcIndex = data.getColumnIndex(config.getDataColumn());
    if ((icIndex == -1) || (dcIndex == -1))
        // at least one column is missing
        return;
    if (config.isSortOnDataColumn()) {
        data.sort(new Comparator<TableRow>() {

            @Override
            public int compare(TableRow row1, TableRow row2) {
                TableCell c1 = row1.get(dcIndex);
                TableCell c2 = row2.get(dcIndex);
                String s1 = (c1 != null) ? c1.getValue() : "";
                String s2 = (c2 != null) ? c2.getValue() : "";
                int result = 0;
                try {
                    double value1 = Double.parseDouble(s1);
                    double value2 = Double.parseDouble(s2);
                    result = Double.compare(value1, value2);
                } catch (NumberFormatException e) {
                    result = s1.compareToIgnoreCase(s2);
                }
                return config.isSortDescending() ? -result : result;
            }
        });
        // Sorting may reorder instances, so clear everything
        instanceMap.clear();
        chart.removeAllParameters();
    }
    boolean rebuild = false;
    for (int i = 0; i < data.getRowCount(); i++) {
        String instance = data.getCellValue(i, icIndex);
        if (instance == null)
            continue;
        double value;
        try {
            value = Double.parseDouble(data.getCellValue(i, dcIndex));
        } catch (NumberFormatException e) {
            value = 0.0;
        }
        Integer index = instanceMap.get(instance);
        if (index == null) {
            if ((instanceMap.size() >= DataChart.MAX_CHART_ITEMS) || ((value == 0) && config.isIgnoreZeroValues()))
                continue;
            // $NON-NLS-1$
            index = chart.addParameter(new GraphItem(config.getNodeId(), config.getDciId(), 0, DataType.INT32, Long.toString(config.getDciId()), instance, "%s"), 0.0);
            instanceMap.put(instance, index);
            rebuild = true;
        }
        chart.updateParameter(index, value, false);
    }
    if (!chartInitialized) {
        chart.initializationComplete();
        chartInitialized = true;
    } else {
        if (rebuild)
            chart.rebuild();
        else
            chart.refresh();
    }
}
Also used : TableCell(org.netxms.client.TableCell) TableRow(org.netxms.client.TableRow) GraphItem(org.netxms.client.datacollection.GraphItem) Point(org.eclipse.swt.graphics.Point)

Example 9 with GraphItem

use of org.netxms.client.datacollection.GraphItem in project netxms by netxms.

the class ObjectTooltip method addStatusChart.

/**
 * Status chart
 */
private void addStatusChart(AbstractObject object, MapLabelProvider labelProvider) {
    BirtChartFigure chart = new BirtChartFigure(BirtChartFigure.BAR_CHART, labelProvider.getColors());
    add(chart);
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    gd.heightHint = 180;
    gd.widthHint = 320;
    setConstraint(chart, gd);
    int[] objectCount = new int[6];
    collectData(objectCount, object);
    chart.setTitleVisible(true);
    chart.setChartTitle(Messages.get().ObjectTooltip_ChartTitle);
    chart.setLegendPosition(GraphSettings.POSITION_RIGHT);
    chart.setLegendVisible(true);
    chart.set3DModeEnabled(true);
    chart.setTransposed(false);
    chart.setTranslucent(false);
    chart.setBorder(new LineBorder());
    for (int i = 0; i <= ObjectStatus.UNKNOWN.getValue(); i++) {
        // $NON-NLS-1$
        chart.addParameter(// $NON-NLS-1$
        new GraphItem(0, 0, 0, DataType.INT32, StatusDisplayInfo.getStatusText(i), StatusDisplayInfo.getStatusText(i), "%s"), objectCount[i]);
        chart.setPaletteEntry(i, new ChartColor(StatusDisplayInfo.getStatusColor(i).getRGB()));
    }
    chart.initializationComplete();
}
Also used : ChartColor(org.netxms.ui.eclipse.charts.api.ChartColor) LineBorder(org.eclipse.draw2d.LineBorder) GridData(org.eclipse.draw2d.GridData) GraphItem(org.netxms.client.datacollection.GraphItem) BirtChartFigure(org.netxms.ui.eclipse.charts.figures.BirtChartFigure) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 10 with GraphItem

use of org.netxms.client.datacollection.GraphItem in project netxms by netxms.

the class HistoricalGraphView method configureGraphFromSettings.

/**
 * Configure graph from graph settings
 */
private void configureGraphFromSettings() {
    if (chart != null)
        ((Widget) chart).dispose();
    chart = ChartFactory.createLineChart(chartParent, SWT.NONE);
    createPopupMenu();
    // General settings
    setPartName(settings.getTitle());
    chart.setChartTitle(settings.getTitle());
    // Chart visual settings
    chart.setLogScaleEnabled(settings.isLogScale());
    chart.setGridVisible(settings.isShowGrid());
    chart.setLegendVisible(settings.isShowLegend());
    chart.setLegendPosition(settings.getLegendPosition());
    chart.setExtendedLegend(settings.isExtendedLegend());
    chart.setStacked(settings.isStacked());
    chart.setTranslucent(settings.isTranslucent());
    chart.setLineWidth(settings.getLineWidth());
    chart.setUseMultipliers(settings.isUseMultipliers());
    if (!settings.isAutoScale())
        chart.setYAxisRange(settings.getMinYScaleValue(), settings.getMaxYScaleValue());
    else
        chart.modifyYBase(settings.modifyYBase());
    // Data
    final List<GraphItemStyle> styles = new ArrayList<GraphItemStyle>(settings.getDciList().length);
    int index = 0;
    int nodeId = 0;
    for (ChartDciConfig dci : settings.getDciList()) {
        // Check that all DCI's are form one node
        nodeId |= dci.nodeId;
        // $NON-NLS-1$
        final String name = settings.isShowHostNames() ? (session.getObjectName(dci.nodeId) + " - " + dci.getName()) : dci.getName();
        chart.addParameter(new GraphItem(dci.nodeId, dci.dciId, 0, DataType.INT32, Long.toString(dci.dciId), name, dci.getDisplayFormat()));
        int color = dci.getColorAsInt();
        if (color == -1)
            color = ChartColor.getDefaultColor(index).getRGB();
        styles.add(new GraphItemStyle(getDisplayType(dci), color, 2, dci.invertValues ? GraphItemStyle.INVERTED : 0));
        index++;
    }
    // Check that all DCI's are form one node
    if (index > 0)
        useMoreThanOneShoucrNode = (nodeId != settings.getDciList()[0].nodeId);
    chart.setItemStyles(styles);
    if (settings.getTimeFrameType() == GraphSettings.TIME_FRAME_BACK_FROM_NOW) {
        settings.setTimeFrom(new Date(System.currentTimeMillis() - settings.getTimeRangeMillis()));
        settings.setTimeTo(new Date(System.currentTimeMillis()));
    }
    getDataFromServer();
    // Automatic refresh
    actionAutoRefresh.setChecked(settings.isAutoRefresh());
    refreshMenuSelection();
    refreshController.setInterval(settings.isAutoRefresh() ? settings.getRefreshRate() : -1);
}
Also used : ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ArrayList(java.util.ArrayList) GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle) GraphItem(org.netxms.client.datacollection.GraphItem) Date(java.util.Date)

Aggregations

GraphItem (org.netxms.client.datacollection.GraphItem)11 GraphItemStyle (org.netxms.client.datacollection.GraphItemStyle)3 ChartColor (org.netxms.ui.eclipse.charts.api.ChartColor)3 ProgressDialog (android.app.ProgressDialog)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2 DciDataRow (org.netxms.client.datacollection.DciDataRow)2 DataComparisonChart (org.netxms.ui.eclipse.charts.api.DataComparisonChart)2 LineGraphView (com.jjoe64.graphview.LineGraphView)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 GridData (org.eclipse.draw2d.GridData)1 LineBorder (org.eclipse.draw2d.LineBorder)1 Widget (org.eclipse.swt.widgets.Widget)1 PartInitException (org.eclipse.ui.PartInitException)1 TableCell (org.netxms.client.TableCell)1