Skip to content
Snippets Groups Projects
Commit 7444d051 authored by Simon Könnecke's avatar Simon Könnecke
Browse files

Split supervisor and wallet histogram

parent e4f278e1
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,7 @@ public class SuperVisorThreadGUI {
showHistogramBtn.addActionListener(e -> {
LocalDateTime time = (LocalDateTime) dropdown.getSelectedItem();
superVisorGuiControl.loadSnapshot(time);
new SuperVisorHistogramGUI(new HashSet<>(superVisorGuiControl.getSnapshots()), time).init();
new SuperVisorHistogramGUI(superVisorGuiControl, time).init();
});
btnPanel.add(showHistogramBtn);
......
......@@ -164,7 +164,7 @@ public class WalletGuiControlImpl implements WalletGuiControl {
btnShowHistogram.addActionListener(e -> {
LocalDateTime time = (LocalDateTime)dropdown.getSelectedItem();
Set<Snapshot> snapshots = wallet.getSnapshots(time);
new SuperVisorHistogramGUI(snapshots, time).init();
new WalletHistogramGUI(snapshots, time).init();
});
dropdown.addActionListener(e -> {
......
package fucoin.gui;
import fucoin.QDigest;
import fucoin.wallet.Snapshot;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.IntervalMarker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.TextAnchor;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
/**
*
*/
public class WalletHistogramGUI extends JFrame {
private final Set<Snapshot> snapshots;
private final LocalDateTime time;
private static final int width = 1200;
private static final int height = 800;
public WalletHistogramGUI(Set<Snapshot> snapshots, LocalDateTime time) {
super("Histogram of distributed granted commit (Snapshot " + time + ")");
this.time = time;
this.snapshots = new HashSet<>(snapshots);
setVisible(true);
setSize(width, height);
}
private JFreeChart createChart(DefaultCategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createBarChart(
"",
"Transaction size [FUCoins]",
"Frequency",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
final IntervalMarker target = new IntervalMarker(400.0, 700.0);
target.setLabel("Target Range");
target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
target.setLabelAnchor(RectangleAnchor.LEFT);
target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
target.setPaint(new Color(222, 222, 255, 128));
return chart;
}
public void init() {
QDigest qDigest = null;
for (Snapshot item : snapshots) {
if (qDigest == null) {
qDigest = item.getqDigest();
} else {
qDigest = QDigest.unionOf(qDigest, item.getqDigest());
}
}
// row keys...
final String series1 = "Transactions";
// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (long[] item : qDigest.toAscRanges()) {
dataset.addValue(item[2], series1, item[0] + "-" + item[1]);
}
JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
JPanel myPanel = new JPanel(new BorderLayout());
myPanel.add(chartPanel, BorderLayout.CENTER);
JPanel quantilePanel = new JPanel();
final JSlider slider = new JSlider(0, 100);
Hashtable<Integer, JComponent> labelTable = new Hashtable<>();
labelTable.put(0, new JLabel("0.0") );
labelTable.put(5, new JLabel("0.5") );
labelTable.put(10, new JLabel("1.0") );
slider.setLabelTable( labelTable );
slider.setValue(50);
final JTextField quantileValueField = new JTextField();
quantileValueField.setEditable(false);
quantileValueField.setPreferredSize(new Dimension(40, 20));
QDigest finalQDigest = qDigest;
slider.addChangeListener(e -> {
double val = slider.getValue() / 100.;
assert val <= 1.0;
quantileValueField.setText(String.format("%1$d", finalQDigest.getQuantile(val)));
});
slider.getChangeListeners()[0].stateChanged(null);
quantilePanel.add(slider);
quantilePanel.add(quantileValueField);
quantilePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
myPanel.add(quantilePanel, BorderLayout.PAGE_END);
setContentPane(myPanel);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment