Search in sources :

Example 1 with Formatter

use of com.exalttech.trex.util.Formatter in project trex-stateless-gui by cisco-system-traffic-generator.

the class StreamLineChart method render.

@Override
protected void render() {
    getChart().getData().clear();
    final StatsStorage statsStorage = StatsStorage.getInstance();
    final Map<Integer, String> selectedPGIDs = statsStorage.getPGIDsStorage().getSelectedPGIds();
    final PGIDStatsStorage pgIDStatsStorage = statsStorage.getPGIDStatsStorage();
    final Map<Integer, ArrayHistory<FlowStatPoint>> latencyStatPointHistoryMap = pgIDStatsStorage.getFlowStatPointHistoryMap();
    final List<XYChart.Series<Double, Number>> seriesList = new LinkedList<>();
    final Formatter formatter = new Formatter();
    synchronized (pgIDStatsStorage.getFlowLock()) {
        latencyStatPointHistoryMap.forEach((final Integer pgID, final ArrayHistory<FlowStatPoint> history) -> {
            if (history == null || history.isEmpty()) {
                return;
            }
            final String color = selectedPGIDs.get(pgID);
            if (color == null) {
                return;
            }
            final double lastTime = history.last().getTime();
            final XYChart.Series<Double, Number> series = new XYChart.Series<>();
            series.setName(String.valueOf(pgID));
            int size = history.size();
            for (int i = 0; i < size; ++i) {
                final FlowStatPoint point = history.get(i);
                final double time = point.getTime();
                final Number value = getValue(point);
                formatter.addValue(value);
                series.getData().add(new XYChart.Data<>(time - lastTime, value));
            }
            setSeriesColor(series, color);
            seriesList.add(series);
        });
    }
    getChart().getData().addAll(seriesList);
    getYAxis().setLabel(String.format("%s (%s%s)", getYChartName(), formatter.getUnitsPrefix(), getYChartUnits()));
}
Also used : ArrayHistory(com.exalttech.trex.util.ArrayHistory) PGIDStatsStorage(com.exalttech.trex.ui.views.storages.PGIDStatsStorage) StatsStorage(com.exalttech.trex.ui.views.storages.StatsStorage) Formatter(com.exalttech.trex.util.Formatter) LinkedList(java.util.LinkedList) FlowStatPoint(com.exalttech.trex.ui.models.stats.FlowStatPoint) PGIDStatsStorage(com.exalttech.trex.ui.views.storages.PGIDStatsStorage) XYChart(javafx.scene.chart.XYChart) FlowStatPoint(com.exalttech.trex.ui.models.stats.FlowStatPoint)

Aggregations

FlowStatPoint (com.exalttech.trex.ui.models.stats.FlowStatPoint)1 PGIDStatsStorage (com.exalttech.trex.ui.views.storages.PGIDStatsStorage)1 StatsStorage (com.exalttech.trex.ui.views.storages.StatsStorage)1 ArrayHistory (com.exalttech.trex.util.ArrayHistory)1 Formatter (com.exalttech.trex.util.Formatter)1 LinkedList (java.util.LinkedList)1 XYChart (javafx.scene.chart.XYChart)1