Added several improvements, changes and bug fixes

This commit is contained in:
Robert Vokac 2024-03-10 16:36:36 +00:00
parent dc55cd4878
commit 066aa76ca4
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
8 changed files with 81 additions and 44 deletions

View File

@ -162,20 +162,23 @@ public class WorkingDayForStats extends WorkingDay {
list.remove(0); list.remove(0);
list.remove(0); list.remove(0);
list.remove(0); list.remove(0);
while(list.get(list.size() - 1).isThisDayTimeOff()) {
list.remove(list.size() - 1);
}
String[] days = new String[list.size()]; String[] days = new String[list.size()];
double[] arrival = new double[list.size()];
double[] ma7 = new double[list.size()]; double[] ma7 = new double[list.size()];
double[] ma14 = new double[list.size()]; double[] ma14 = new double[list.size()];
double[] ma28 = new double[list.size()]; double[] ma28 = new double[list.size()];
double[] ma56 = new double[list.size()]; double[] ma56 = new double[list.size()];
double[] arrival = new double[list.size()];
ArrivalChartData acd = new ArrivalChartData(); ArrivalChartData acd = new ArrivalChartData();
acd.setDays(days); acd.setDays(days);
acd.setArrival(arrival); acd.setArrival(arrival);
acd.setTarget(target);
acd.setMa7(ma7); acd.setMa7(ma7);
acd.setMa14(ma14); acd.setMa14(ma14);
acd.setMa28(ma28); acd.setMa28(ma28);
acd.setMa56(ma56); acd.setMa56(ma56);
acd.setTarget(0);
if(startDate != null && !startDate.isEmpty()) { if(startDate != null && !startDate.isEmpty()) {
acd.setStartDate(startDate); acd.setStartDate(startDate);
} }
@ -186,7 +189,7 @@ public class WorkingDayForStats extends WorkingDay {
WorkingDayForStats wdfs = list.get(i); WorkingDayForStats wdfs = list.get(i);
days[i] = wdfs.getId(); days[i] = wdfs.getId();
arrival[i] = wdfs.isThisDayTimeOff() ? wdfs.getArrivalTimeMovingAverage7Days() - target : wdfs.getArrivalAsDouble() - target; arrival[i] = (wdfs.isThisDayTimeOff() ? wdfs.getArrivalTimeMovingAverage7Days() : wdfs.getArrivalAsDouble()) - target;
ma7[i] = wdfs.getArrivalTimeMovingAverage7Days() - target; ma7[i] = wdfs.getArrivalTimeMovingAverage7Days() - target;
ma14[i] = wdfs.getArrivalTimeMovingAverage14Days() - target; ma14[i] = wdfs.getArrivalTimeMovingAverage14Days() - target;
ma28[i] = wdfs.getArrivalTimeMovingAverage28Days() - target; ma28[i] = wdfs.getArrivalTimeMovingAverage28Days() - target;

View File

@ -3,28 +3,42 @@ package org.nanoboot.utils.timecalc.swing.common;
import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel; import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart; import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle; import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.category.DefaultCategoryDataset;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Rectangle;
import java.util.function.BiConsumer;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 20.02.2024 * @since 20.02.2024
*/ */
public class ArrivalChart extends JPanel { public class ArrivalChart extends JPanel {
private static final Color ORANGE = new Color(237, 125, 49);
private static final Color BLUE = new Color(68, 114, 196);
private static final Color BROWN = new Color(128,0, 64);
private static final Color PURPLE = new Color(128,0, 255);
public static final Rectangle EMPTY_RECTANGLE = new Rectangle();
public ArrivalChart(ArrivalChartData data) { public ArrivalChart(ArrivalChartData data) {
this(data.getDays(), data.getArrival(), data.getMa7(), data.getMa14(), data.getMa28(), data.getMa56(), data.getTarget(), this(data.getDays(), data.getArrival(), data.getTarget(), data.getMa7(), data.getMa14(), data.getMa28(), data.getMa56(),
data.getStartDate(), data.getEndDate()); data.getStartDate(), data.getEndDate());
} }
public ArrivalChart(String[] days, double[] arrival, double[] ma7, public ArrivalChart(String[] days, double[] arrival, double target, double[] ma7,
double[] ma14, double[] ma28, double[] ma56, double target, String startDate, String endDate) { double[] ma14, double[] ma28, double[] ma56, String startDate, String endDate) {
this.setLayout(null); this.setLayout(null);
this.setVisible(true); this.setVisible(true);
@ -32,7 +46,7 @@ public class ArrivalChart extends JPanel {
String title = "Arrivals"; String title = "Arrivals";
CategoryDataset dataset = CategoryDataset dataset =
createDataset(days, arrival, ma7, ma14, ma28, ma56, target, title, startDate, endDate); createDataset(days, arrival, target, ma7, ma14, ma28, ma56, title, startDate, endDate);
JFreeChart chart = createChart(dataset, title); JFreeChart chart = createChart(dataset, title);
ChartPanel chartPanel = new ChartPanel(chart); ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); chartPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
@ -40,7 +54,7 @@ public class ArrivalChart extends JPanel {
chartPanel.setDomainZoomable(true); chartPanel.setDomainZoomable(true);
chartPanel.setMouseZoomable(true); chartPanel.setMouseZoomable(true);
this.add(chartPanel); this.add(chartPanel);
chartPanel.setBounds(10, 10, 800, 400); chartPanel.setBounds(10, 10, 1200, 400);
} }
@ -57,33 +71,40 @@ public class ArrivalChart extends JPanel {
true, true,
false false
); );
// Plot plot = chart.getPlot();
// CategoryPlot plot = chart.getCategoryPlot();
// XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); LineAndShapeRenderer renderer = new LineAndShapeRenderer();
// chart.setBorderVisible(false); renderer.setDrawOutlines(false);
// BiConsumer<Integer, Color> setSeries = (i, c) -> { chart.setBorderVisible(false);
// renderer.setSeriesPaint(i, c); BiConsumer<Integer, Color> setSeries = (i, c) -> {
// renderer.setSeriesStroke(i, new BasicStroke(1.0f)); renderer.setSeriesPaint(i, c);
// renderer.setSeriesShape(i, new Rectangle()); renderer.setSeriesStroke(i, new BasicStroke(dataset.getRowCount() > 180 ? 1.0f : (i == 1 || i == 2 ? 1.5f : 1.25f)));
// }; renderer.setSeriesShape(i, EMPTY_RECTANGLE);
// setSeries.accept(0, Color.GRAY); };
// setSeries.accept(1, Color.BLACK); setSeries.accept(0, Color.GRAY);
// setSeries.accept(2, Color.RED); setSeries.accept(1, ORANGE);
// setSeries.accept(3, Color.GREEN); setSeries.accept(2, BLUE);
// setSeries.accept(4, Color.BLUE); setSeries.accept(3, Color.GREEN);
// setSeries.accept(5, Color.ORANGE); setSeries.accept(4, BROWN);
// setSeries.accept(5, PURPLE);
// plot.setRenderer(renderer);
// plot.setBackgroundPaint(Color.white); plot.setRenderer(renderer);
// plot.setBackgroundPaint(Color.white);
// plot.setRangeGridlinesVisible(true); // plot.setRangeGridlinesVisible(true);
// plot.setRangeGridlinePaint(Color.BLACK); // plot.setRangeGridlinePaint(Color.BLACK);
// //
// plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinesVisible(true);
// plot.setDomainGridlinePaint(Color.BLACK); // plot.setDomainGridlinePaint(Color.BLACK);
// chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setFrame(BlockBorder.NONE);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLabelFont(SwingUtils.VERY_SMALL_FONT);
domainAxis.setTickLabelFont(SwingUtils.VERY_SMALL_FONT);
domainAxis.setCategoryLabelPositionOffset(10);
domainAxis.setTickLabelsVisible(true);
chart.setTitle(new TextTitle(title, chart.setTitle(new TextTitle(title,
new Font("Serif", Font.BOLD, 18) new Font("Serif", Font.BOLD, 18)
) )
@ -92,9 +113,9 @@ public class ArrivalChart extends JPanel {
return chart; return chart;
} }
private CategoryDataset createDataset(String[] days, double[] arrival, private CategoryDataset createDataset(String[] days, double[] arrival, double target,
double[] ma7, double[] ma14, double[] ma28, double[] ma7, double[] ma14, double[] ma28,
double[] ma56, double target, String title, String startDate, String endDate) { double[] ma56, String title, String startDate, String endDate) {
if (startDate == null) { if (startDate == null) {
startDate = "0-0-0"; startDate = "0-0-0";
} }
@ -103,11 +124,11 @@ public class ArrivalChart extends JPanel {
} }
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String seriesArrival = "Arrival"; String seriesArrival = "Arrival";
String seriesTarget = "Target (" + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(target) + " h)";
String seriesMa7 = "MA7"; String seriesMa7 = "MA7";
String seriesMa14 = "MA14"; String seriesMa14 = "MA14";
String seriesMa28 = "MA28"; String seriesMa28 = "MA28";
String seriesMa56 = "MA56"; String seriesMa56 = "MA56";
String seriesTarget = "Target";
String[] dayArray0 = startDate.split("-"); String[] dayArray0 = startDate.split("-");
int year1 = Integer.valueOf(dayArray0[0]); int year1 = Integer.valueOf(dayArray0[0]);
@ -141,11 +162,12 @@ public class ArrivalChart extends JPanel {
} }
} }
dataset.addValue(arrival[i], seriesArrival, date); dataset.addValue(arrival[i], seriesArrival, date);
dataset.addValue(0, seriesTarget, date);
dataset.addValue(ma7[i], seriesMa7, date); dataset.addValue(ma7[i], seriesMa7, date);
dataset.addValue(ma14[i], seriesMa14, date); dataset.addValue(ma14[i], seriesMa14, date);
dataset.addValue(ma28[i], seriesMa28, date); dataset.addValue(ma28[i], seriesMa28, date);
dataset.addValue(ma56[i], seriesMa56, date); dataset.addValue(ma56[i], seriesMa56, date);
dataset.addValue(target, seriesTarget, date);
} }
return dataset; return dataset;

View File

@ -16,11 +16,11 @@ import lombok.Setter;
public class ArrivalChartData { public class ArrivalChartData {
private String[] days; private String[] days;
private double[] arrival; private double[] arrival;
private double target;
private double[] ma7; private double[] ma7;
private double[] ma14; private double[] ma14;
private double[] ma28; private double[] ma28;
private double[] ma56; private double[] ma56;
private double target;
private String startDate; private String startDate;
private String endDate; private String endDate;
} }

View File

@ -2,6 +2,8 @@ package org.nanoboot.utils.timecalc.swing.common;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel; import javax.swing.JPanel;
/** /**
@ -23,6 +25,17 @@ public class DayPanel extends JPanel {
this.month = monthIn; this.month = monthIn;
this.day = dayIn; this.day = dayIn;
setSize(1050, 600); setSize(1050, 600);
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JButton addButton = new JButton("Add");
JButton addButton2 = new JButton("Add");
JButton addButton3 = new JButton("Add");
JButton addButton4 = new JButton("Add");
add(addButton);
add(addButton2);
add(addButton3);
add(addButton4);
} }
} }

View File

@ -87,7 +87,7 @@ public class MainWindow extends TWindow {
this.overtimeTextField = new TTextField("", 40); this.overtimeTextField = new TTextField("", 40);
this.workingTimeTextField = new TTextField("8:00", 40); this.workingTimeTextField = new TTextField("8:00", 40);
this.pauseTimeTextField = new TTextField("0:30", 40); this.pauseTimeTextField = new TTextField("0:30", 40);
this.noteTextField = new TTextField("", 120); this.noteTextField = new TTextField("", 100);
this.departureTextField = new TTextField(); this.departureTextField = new TTextField();
this.elapsedTextField = new TTextField("", 100); this.elapsedTextField = new TTextField("", 100);
this.remainingTextField = new TTextField("", 100); this.remainingTextField = new TTextField("", 100);
@ -300,8 +300,8 @@ public class MainWindow extends TWindow {
pauseDecreaseButton.setBounds(pauseTimeTextField.getX() + pauseTimeTextField.getWidth(), pauseTimeTextField.getY() + 15, 15, 15); pauseDecreaseButton.setBounds(pauseTimeTextField.getX() + pauseTimeTextField.getWidth(), pauseTimeTextField.getY() + 15, 15, 15);
// //
TLabel noteTextFieldLabel = new TLabel("Note:", 40); TLabel noteTextFieldLabel = new TLabel("Note:", 30);
noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField); noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField, 10);
noteTextField.setBoundsFromLeft(noteTextFieldLabel); noteTextField.setBoundsFromLeft(noteTextFieldLabel);
timeOffCheckBox.setBoundsFromLeft(noteTextField); timeOffCheckBox.setBoundsFromLeft(noteTextField);

View File

@ -11,7 +11,7 @@ public class SwingUtils {
public static final int MARGIN = 10; public static final int MARGIN = 10;
public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10); public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10);
public static final Font VERY_SMALL_FONT = new Font("sans", Font.PLAIN, 8); public static final Font VERY_SMALL_FONT = new Font("sans", Font.PLAIN, 9);
public static final Font MEDIUM_MONOSPACE_FONT public static final Font MEDIUM_MONOSPACE_FONT
= new Font(Font.MONOSPACED, Font.PLAIN, 12); = new Font(Font.MONOSPACED, Font.PLAIN, 12);

View File

@ -87,7 +87,7 @@ public class WorkingDaysWindow extends TWindow {
TLabel deleteLabel = new TLabel("Delete:"); TLabel deleteLabel = new TLabel("Delete:");
add(deleteLabel); add(deleteLabel);
deleteLabel.setBounds(exitButton.getX() + exitButton.getWidth() + SwingUtils.MARGIN, exitButton.getY(), 100, 30); deleteLabel.setBounds(exitButton.getX() + exitButton.getWidth() + SwingUtils.MARGIN, exitButton.getY(), 50, 30);
TTextField deleteTextField = new TTextField(); TTextField deleteTextField = new TTextField();
add(deleteTextField); add(deleteTextField);
deleteTextField.setBounds(deleteLabel.getX() + deleteLabel.getWidth() + SwingUtils.MARGIN, deleteLabel.getY(), 100, 30); deleteTextField.setBounds(deleteLabel.getX() + deleteLabel.getWidth() + SwingUtils.MARGIN, deleteLabel.getY(), 100, 30);
@ -106,7 +106,7 @@ public class WorkingDaysWindow extends TWindow {
TLabel startLabel = new TLabel("Start:"); TLabel startLabel = new TLabel("Start:");
add(startLabel); add(startLabel);
startLabel.setBounds(deleteTextField.getX() + deleteTextField.getWidth() + SwingUtils.MARGIN, deleteTextField.getY(), 50, 30); startLabel.setBounds(deleteTextField.getX() + deleteTextField.getWidth() + 6 * SwingUtils.MARGIN, deleteTextField.getY(), 50, 30);
this.startTextField = new TTextField(); this.startTextField = new TTextField();
add(startTextField); add(startTextField);
startTextField.setBounds(startLabel.getX() + startLabel.getWidth() + SwingUtils.MARGIN, startLabel.getY(), 100, 30); startTextField.setBounds(startLabel.getX() + startLabel.getWidth() + SwingUtils.MARGIN, startLabel.getY(), 100, 30);
@ -125,12 +125,11 @@ public class WorkingDaysWindow extends TWindow {
reloadButton.doClick(); reloadButton.doClick();
}); });
// //
ArrivalChartData acd = new ArrivalChartData(new String[]{}, new double[]{}, new double[]{}, new double[]{}, new double[]{}, new double[]{},7d, null, null); ArrivalChartData acd = new ArrivalChartData(new String[]{}, new double[]{}, 7d, new double[]{}, new double[]{}, new double[]{}, new double[]{}, null, null);
this.arrivalChart = new ArrivalChart(acd); this.arrivalChart = new ArrivalChart(acd);
arrivalChart.setBounds(SwingUtils.MARGIN, years.getY() + years.getHeight()+ SwingUtils.MARGIN, arrivalChart.setBounds(SwingUtils.MARGIN, years.getY() + years.getHeight()+ SwingUtils.MARGIN,
800, 1200,
400); 400);
add(arrivalChart); add(arrivalChart);
// //
@ -138,7 +137,7 @@ public class WorkingDaysWindow extends TWindow {
= new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(SwingUtils.MARGIN, arrivalChart.getY() + arrivalChart.getHeight()+ SwingUtils.MARGIN, scrollPane.setBounds(SwingUtils.MARGIN, arrivalChart.getY() + arrivalChart.getHeight()+ SwingUtils.MARGIN,
1000, 1200,
300); 300);
add(scrollPane); add(scrollPane);
scrollPane.setViewportView(table); scrollPane.setViewportView(table);

View File

@ -12,7 +12,7 @@ public class NumberFormats {
public static final NumberFormat FORMATTER_ZERO_DECIMAL_PLACES public static final NumberFormat FORMATTER_ZERO_DECIMAL_PLACES
= new DecimalFormat("#00"); = new DecimalFormat("#00");
public static final NumberFormat FORMATTER_TWO_DECIMAL_PLACES public static final NumberFormat FORMATTER_TWO_DECIMAL_PLACES
= new DecimalFormat("#00.00"); = new DecimalFormat("#0.00");
public static final NumberFormat FORMATTER_FIVE_DECIMAL_PLACES public static final NumberFormat FORMATTER_FIVE_DECIMAL_PLACES
= new DecimalFormat("#0.00000"); = new DecimalFormat("#0.00000");
public static final NumberFormat FORMATTER_THREE_DECIMAL_PLACES public static final NumberFormat FORMATTER_THREE_DECIMAL_PLACES