Chart actualized

This commit is contained in:
Niklas Aumueller 2026-03-05 11:15:21 +01:00
parent 3632cc765d
commit 9ccdd15adb
5 changed files with 88 additions and 7 deletions

View File

@ -65,6 +65,9 @@ public class ApplicationInitializer {
public static void initLookAndFeel() {
try {
UIManager.setLookAndFeel(new FlatDarkLaf());
UIManager.put("Component.focusWidth", 1);
UIManager.put("Button.arc", 8);
UIManager.put("TextComponent.arc", 8);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -53,7 +53,7 @@ public class BinaryEventService {
persistenceService.store(prediction);
evaluationService.evaluate();
//Logger.debug("EVENT", "Prediction verarbeitet: " + prediction);
Logger.debug("EVENT", "Prediction verarbeitet: " + prediction);
} catch (Exception e) {
Logger.error("EVENT", "Payload Verarbeitung fehlgeschlagen: " + payload, e);

View File

@ -3,6 +3,12 @@ package vassistent.ui;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.ui.RectangleAnchor;
import org.jfree.chart.ui.TextAnchor;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
@ -28,10 +34,31 @@ public class DashboardView extends JPanel {
public DashboardView() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
setOpaque(false);
JPanel card = new JPanel(new BorderLayout(10,10));
card.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
card.setBackground(UIManager.getColor("Panel.background"));
card.setOpaque(true);
card.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(
UIManager.getColor("Component.borderColor")
),
BorderFactory.createEmptyBorder(12,12,12,12)
));
// ---------- TOP: Problem Level ----------
JPanel topWrapper = new JPanel(new BorderLayout());
topWrapper.setBorder(BorderFactory.createEmptyBorder(0,0,10,0));
topWrapper.setOpaque(false);
levelBar = new ProblemLevelBar();
add(levelBar, BorderLayout.NORTH);
topWrapper.add(levelBar, BorderLayout.CENTER);
card.add(topWrapper, BorderLayout.NORTH);
// ---------- CENTER: Chart ----------
@ -46,21 +73,45 @@ public class DashboardView extends JPanel {
dataset
);
add(new ChartPanel(chart), BorderLayout.CENTER);
XYPlot plot = chart.getXYPlot();
// Threshold Lines
addThresholdLine(plot, 0.5, "Warning");
addThresholdLine(plot, 0.8, "High");
addThresholdLine(plot, 0.9, "Disaster");
chart.getXYPlot().getRangeAxis().setRange(0.0, 1.02);
NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
rangeAxis.setTickUnit(new NumberTickUnit(0.1));
chart.setAntiAlias(true);
chart.getPlot().setBackgroundPaint(new Color(245,245,245));
chart.getPlot().setOutlineVisible(false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
card.add(chartPanel, BorderLayout.CENTER);
// ---------- SOUTH: Preview + Buttons ----------
add(createBottomPanel(), BorderLayout.SOUTH);
card.add(createBottomPanel(), BorderLayout.SOUTH);
add(card, BorderLayout.CENTER);
}
private JPanel createBottomPanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
JPanel buttonPanel = new JPanel(new FlowLayout());
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT,10,5));
reloadPixelStreamingViewButton = new JButton("Reload Preview");
openFullscreenButton = new JButton("Open Fullscreen");
reloadPixelStreamingViewButton.putClientProperty("JButton.buttonType", "roundRect");
openFullscreenButton.putClientProperty("JButton.buttonType", "roundRect");
buttonPanel.add(reloadPixelStreamingViewButton);
buttonPanel.add(openFullscreenButton);
@ -98,4 +149,18 @@ public class DashboardView extends JPanel {
public JButton getOpenFullscreenButton() {
return openFullscreenButton;
}
private void addThresholdLine(XYPlot plot, double value, String label) {
ValueMarker marker = new ValueMarker(value);
marker.setPaint(Color.RED);
marker.setStroke(new BasicStroke(1.5f));
marker.setLabel(label);
marker.setLabelFont(new Font("Segoe UI", Font.PLAIN, 11));
marker.setLabelAnchor(RectangleAnchor.LEFT);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
plot.addRangeMarker(marker);
}
}

View File

@ -12,6 +12,8 @@ public class ProblemLevelBar extends JPanel {
public ProblemLevelBar() {
setPreferredSize(new Dimension(100, 50));
setOpaque(false);
setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
public void setRatio(double ratio) {
@ -44,7 +46,12 @@ public class ProblemLevelBar extends JPanel {
RenderingHints.VALUE_ANTIALIAS_ON);
// --- Hintergrund ---
g2.setColor(Color.LIGHT_GRAY);
GradientPaint bg = new GradientPaint(
0, 0, new Color(235,235,235),
0, height, new Color(210,210,210)
);
g2.setPaint(bg);
g2.fillRoundRect(0, 0, width, height, 20, 20);
// --- Gefüllter Bereich ---
@ -61,12 +68,18 @@ public class ProblemLevelBar extends JPanel {
g2.setPaint(gradient);
g2.fillRoundRect(0, 0, filledWidth, height, 20, 20);
g2.setStroke(new BasicStroke(2f));
g2.setColor(baseColor.brighter());
g2.drawRoundRect(1,1,width-2,height-2,20,20);
// --- Text ---
String text = level.name() + " (" + (int)(ratio * 100) + "%)";
g2.setColor(Color.BLACK);
FontMetrics fm = g2.getFontMetrics();
int textWidth = fm.stringWidth(text);
g2.setColor(Color.BLACK);
g2.drawString(
text,
(width - textWidth) / 2,