Search in sources :

Example 1 with GraphItemStyle

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

the class LineChart method applyItemStyle.

/**
 * Apply graph item style
 *
 * @param index item index
 * @param series added series
 */
private void applyItemStyle(int index, ILineSeries series) {
    if ((index < 0) || (index >= itemStyles.size()))
        return;
    GraphItemStyle style = itemStyles.get(index);
    series.setLineColor(ColorConverter.colorFromInt(style.getColor(), colors));
    series.enableArea(style.getType() == GraphItemStyle.AREA);
    series.setInverted(style.isInverted());
}
Also used : GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle)

Example 2 with GraphItemStyle

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

the class PerfTabGraph method addItem.

/**
 * Add another item to graph
 *
 * @param dci
 * @param settings
 */
public void addItem(PerfTabDci dci, PerfTabGraphSettings settings) {
    chart.setLegendVisible(true);
    if (settings.isExtendedLegend())
        chart.setExtendedLegend(true);
    synchronized (items) {
        items.add(dci);
        GraphItemStyle style = new GraphItemStyle(settings.getType(), settings.getColorAsInt(), 2, settings.isInvertedValues() ? GraphItemStyle.INVERTED : 0);
        List<GraphItemStyle> styles = new ArrayList<GraphItemStyle>(chart.getItemStyles());
        if (styles.size() < items.size())
            styles.add(style);
        else
            styles.set(items.size() - 1, style);
        chart.setItemStyles(styles);
        // $NON-NLS-1$ //$NON-NLS-2$
        chart.addParameter(new GraphItem(nodeId, dci.getId(), 0, DataType.INT32, "", settings.getRuntimeName(), "%s"));
    }
}
Also used : ArrayList(java.util.ArrayList) GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle) GraphItem(org.netxms.client.datacollection.GraphItem)

Example 3 with GraphItemStyle

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

the class ChartConfig method parseLegacyConfig.

/**
 * Parse legacy predefined graph config
 *
 * @param settings
 */
private void parseLegacyConfig(String settings) {
    autoRefresh = false;
    showLegend = false;
    showGrid = false;
    int dciCount = 0;
    GraphItemStyle[] itemStyles = new GraphItemStyle[GraphSettings.MAX_GRAPH_ITEM_COUNT];
    for (int i = 0; i < itemStyles.length; i++) itemStyles[i] = new GraphItemStyle();
    String[] elements = settings.split("\u007F");
    for (int i = 0; i < elements.length; i++) {
        int index = elements[i].indexOf(':');
        if (index == -1)
            continue;
        final String name = elements[i].substring(0, index);
        final String value = elements[i].substring(index + 1);
        if (name.equals("A")) {
            refreshRate = SafeParser.parseInt(value, 30);
        } else if (name.equals("F")) {
            int flags = SafeParser.parseInt(value, 0);
            if ((flags & GraphSettings.GF_AUTO_UPDATE) != 0)
                autoRefresh = true;
            if ((flags & GraphSettings.GF_SHOW_GRID) != 0)
                showGrid = true;
            if ((flags & GraphSettings.GF_SHOW_LEGEND) != 0)
                showLegend = true;
            if ((flags & GraphSettings.GF_SHOW_HOST_NAMES) != 0)
                showHostNames = true;
            if ((flags & GraphSettings.GF_LOG_SCALE) != 0)
                logScale = true;
        } else if (name.equals("N")) {
            dciCount = SafeParser.parseInt(value, 0);
            dciList = new ChartDciConfig[dciCount];
            for (int j = 0; j < dciCount; j++) dciList[j] = new ChartDciConfig();
        } else if (name.equals("TFT")) {
            timeFrameType = SafeParser.parseInt(value, GraphSettings.TIME_FRAME_BACK_FROM_NOW);
        } else if (name.equals("TU")) {
            timeUnits = SafeParser.parseInt(value, GraphSettings.TIME_UNIT_HOUR);
        } else if (name.equals("NTU")) {
            timeRange = SafeParser.parseInt(value, 1);
        } else if (name.equals("TS")) {
            timeFrom = new Date((long) SafeParser.parseInt(value, 0) * 1000L);
        } else if (name.equals("TF")) {
            timeTo = new Date((long) SafeParser.parseInt(value, 0) * 1000L);
        } else if (name.equals("T")) {
            title = value;
        } else if (name.equals("S")) {
        // autoscale flag
        } else if (name.equals("G")) {
            showGrid = (SafeParser.parseInt(value, 1) != 0);
        } else if (name.equals("L")) {
            showLegend = (SafeParser.parseInt(value, 1) != 0);
        } else if (name.equals("R")) {
        // show ruler flag
        } else if (name.equals("H")) {
            showHostNames = (SafeParser.parseInt(value, 0) != 0);
        } else if (name.equals("O")) {
            logScale = (SafeParser.parseInt(value, 0) != 0);
        } else if (name.equals("CA")) {
        // axis color
        } else if (name.equals("CB")) {
        // background color
        } else if (name.equals("CG")) {
        // grid color
        } else if (name.equals("CLF")) {
        // legend text color
        } else if (name.equals("CLB")) {
        // legend background color
        } else if (name.equals("CP")) {
        // plot area color
        } else if (name.equals("CR")) {
        // ruler color
        } else if (name.equals("CS")) {
        // selection color
        } else if (name.equals("CT")) {
        // text color
        } else if (// Item color
        name.charAt(0) == 'C') {
            int item = SafeParser.parseInt(name.substring(1), -1);
            if ((item >= 0) && (item < itemStyles.length))
                itemStyles[item].setColor(SafeParser.parseInt(value, 0));
        } else if (// Item type
        name.charAt(0) == 'T') {
            int item = SafeParser.parseInt(name.substring(1), -1);
            if ((item >= 0) && (item < itemStyles.length))
                itemStyles[item].setType(SafeParser.parseInt(value, 0));
        } else if (// Item line width
        name.charAt(0) == 'W') {
            int item = SafeParser.parseInt(name.substring(1), -1);
            if ((item >= 0) && (item < itemStyles.length))
                itemStyles[item].setLineWidth(SafeParser.parseInt(value, 0));
        } else if (// Item flags
        (name.charAt(0) == 'F') && (name.charAt(1) == 'L')) {
            int item = SafeParser.parseInt(name.substring(2), -1);
            if ((item >= 0) && (item < itemStyles.length))
                itemStyles[item].setFlags(SafeParser.parseInt(value, 0));
        } else if (// Node ID
        name.charAt(0) == 'N') {
            int item = SafeParser.parseInt(name.substring(1), -1);
            if ((item >= 0) && (item < dciCount))
                dciList[item].nodeId = SafeParser.parseLong(value, 0);
        } else if (// DCI information
        name.charAt(0) == 'I') {
            if (// description
            name.charAt(1) == 'D') {
                int item = SafeParser.parseInt(name.substring(2), -1);
                if ((item >= 0) && (item < dciCount))
                    dciList[item].name = value;
            } else if (// name
            name.charAt(1) == 'N') {
            } else if (// source
            name.charAt(1) == 'S') {
            } else if (// data type
            name.charAt(1) == 'T') {
            } else // assume DCI ID - Ixxx
            {
                int item = SafeParser.parseInt(name.substring(1), -1);
                if ((item >= 0) && (item < dciCount))
                    dciList[item].dciId = SafeParser.parseLong(value, 0);
            }
        }
    }
    // Apply item styles
    for (int i = 0; (i < dciList.length) && (i < itemStyles.length); i++) {
        dciList[i].color = "0x" + Integer.toHexString(itemStyles[i].getColor());
        dciList[i].lineWidth = itemStyles[i].getLineWidth();
    }
}
Also used : GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle) Date(java.util.Date)

Example 4 with GraphItemStyle

use of org.netxms.client.datacollection.GraphItemStyle 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 5 with GraphItemStyle

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

the class LineChart method paintThresholds.

/**
 * Paint DCI thresholds
 */
private void paintThresholds(PaintEvent e, IAxis axis) {
    GC gc = e.gc;
    Rectangle clientArea = getPlotArea().getClientArea();
    for (GraphItemStyle style : itemStyles) {
        if (style.isShowThresholds()) {
            int y = axis.getPixelCoordinate(10);
            gc.setForeground(ColorConverter.colorFromInt(style.getColor(), colors));
            // gc.setLineStyle(SWT.LINE_DOT);
            gc.setLineWidth(3);
            gc.drawLine(0, y, clientArea.width, y);
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GraphItemStyle(org.netxms.client.datacollection.GraphItemStyle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) DataPoint(org.netxms.ui.eclipse.charts.api.DataPoint)

Aggregations

GraphItemStyle (org.netxms.client.datacollection.GraphItemStyle)6 GraphItem (org.netxms.client.datacollection.GraphItem)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ProgressDialog (android.app.ProgressDialog)1 TextView (android.widget.TextView)1 LineGraphView (com.jjoe64.graphview.LineGraphView)1 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 ChartDciConfig (org.netxms.client.datacollection.ChartDciConfig)1 CustomLabel (org.netxms.ui.android.helpers.CustomLabel)1 DataPoint (org.netxms.ui.eclipse.charts.api.DataPoint)1