HolonInformationPanel.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. package holeg.ui.view.information;
  2. import holeg.model.Flexibility;
  3. import holeg.model.HolonElement;
  4. import holeg.model.HolonObject;
  5. import holeg.model.HolonObject.HolonObjectState;
  6. import holeg.preferences.ColorPreference;
  7. import holeg.preferences.ImagePreference;
  8. import holeg.ui.controller.Control;
  9. import holeg.ui.model.GuiSettings;
  10. import holeg.ui.view.image.Import;
  11. import holeg.utility.math.decimal.Format;
  12. import org.knowm.xchart.PieChart;
  13. import org.knowm.xchart.PieChartBuilder;
  14. import org.knowm.xchart.PieSeries.PieSeriesRenderStyle;
  15. import org.knowm.xchart.XChartPanel;
  16. import org.knowm.xchart.style.PieStyler;
  17. import org.knowm.xchart.style.PieStyler.LabelType;
  18. import javax.swing.*;
  19. import javax.swing.border.EmptyBorder;
  20. import javax.swing.event.PopupMenuEvent;
  21. import javax.swing.event.PopupMenuListener;
  22. import java.awt.*;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.logging.Logger;
  26. import java.util.stream.Collectors;
  27. public class HolonInformationPanel extends JPanel {
  28. private static final Logger log = Logger.getLogger(HolonInformationPanel.class.getName());
  29. //private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
  30. // HolonObjectState.PRODUCER;
  31. private final int defaultWidth = 50;
  32. private final int defaultHeight = 200;
  33. private static final Color[] supplyStateColors = new Color[] { ColorPreference.HolonObject.Producer,
  34. ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.Supplied,
  35. ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.NotSupplied,
  36. ColorPreference.HolonObject.NoEnergy, ColorPreference.InformationPanel.NoData };
  37. private static final Color[] productionColors = new Color[] { ColorPreference.Energy.Production,
  38. ColorPreference.Energy.Consumption, ColorPreference.InformationPanel.NoData };
  39. private static final Color[] activeColors = new Color[] { ColorPreference.Element.Active,
  40. ColorPreference.Element.Inactive, ColorPreference.InformationPanel.NoData };
  41. private static final Color[] flexibilityColors = new Color[] { ColorPreference.Flexibility.Offered,
  42. ColorPreference.Flexibility.InUse, ColorPreference.Flexibility.OnCooldown,
  43. ColorPreference.Flexibility.NotOffered, ColorPreference.Flexibility.Unavailable, ColorPreference.Flexibility.NoFlexibility,
  44. ColorPreference.InformationPanel.NoData };
  45. private static final Color[] priorityColors = new Color[] { ColorPreference.Element.Priority.Essential,
  46. ColorPreference.Element.Priority.High, ColorPreference.Element.Priority.Medium,
  47. ColorPreference.Element.Priority.Low, ColorPreference.InformationPanel.NoData };
  48. private final PieChart supplyChart = createSupplyStateChart();
  49. private final PieChart priorityChart = createPriorityChart();
  50. private final PieChart flexibilityChart = createFlexibilityChart();
  51. private final PieChart energyChart = createProductionChart();
  52. private final PieChart activeChart = createActiveChart();
  53. private final JPanel graphPanel = new JPanel(new GridLayout(0, 2));
  54. private final JPanel titlePanel = new JPanel(new BorderLayout(0, 0));
  55. private final JCheckBoxMenuItem producerCheckBox = new JCheckBoxMenuItem("Producer", true);
  56. private final JCheckBoxMenuItem overSuppliedCheckBox = new JCheckBoxMenuItem("Over supplied", true);
  57. private final JCheckBoxMenuItem suppliedCheckBox = new JCheckBoxMenuItem("Supplied", true);
  58. private final JCheckBoxMenuItem partiallySuppliedCheckBox = new JCheckBoxMenuItem("Partial supplied", true);
  59. private final JCheckBoxMenuItem notSuppliedCheckBox = new JCheckBoxMenuItem("Not supplied", true);
  60. private final JCheckBoxMenuItem noEnergyCheckBox = new JCheckBoxMenuItem("No energy", true);
  61. private final JCheckBoxMenuItem essentialCheckBox = new JCheckBoxMenuItem("Essential", true);
  62. private final JCheckBoxMenuItem highCheckBox = new JCheckBoxMenuItem("High", true);
  63. private final JCheckBoxMenuItem mediumBox = new JCheckBoxMenuItem("Medium", true);
  64. private final JCheckBoxMenuItem lowCheckBox = new JCheckBoxMenuItem("Low", true);
  65. private final JCheckBoxMenuItem activeCheckBox = new JCheckBoxMenuItem("Active", true);
  66. private final JCheckBoxMenuItem inactiveCheckBox = new JCheckBoxMenuItem("Inactive", true);
  67. private final JCheckBoxMenuItem noFlexibilityCheckBox = new JCheckBoxMenuItem("No Flexibility", true);
  68. private final JCheckBoxMenuItem inUseCheckBox = new JCheckBoxMenuItem("In use", true);
  69. private final JCheckBoxMenuItem offeredCheckBox = new JCheckBoxMenuItem("Offered", true);
  70. private final JCheckBoxMenuItem notOfferedCheckBox = new JCheckBoxMenuItem("Not offered", true);
  71. private final JCheckBoxMenuItem onCooldownCheckBox = new JCheckBoxMenuItem("On cooldown", true);
  72. private final JCheckBoxMenuItem unavailableCheckBox = new JCheckBoxMenuItem("Unavailable", true);
  73. private final Control control;
  74. private final JLabel differenceEnergyLabelAmount = new JLabel("");
  75. public HolonInformationPanel(Control control) {
  76. control.OnSelectionChanged.addListener(this::updateCharts);
  77. control.OnCanvasUpdate.addListener(this::updateCharts);
  78. this.control = control;
  79. this.setLayout(new BorderLayout());
  80. initGraphPanel();
  81. initTitlePanel();
  82. this.setBackground(ColorPreference.Panel.Background);
  83. this.add(titlePanel, BorderLayout.PAGE_START);
  84. this.add(graphPanel, BorderLayout.CENTER);
  85. }
  86. public void updateCharts() {
  87. FilterableGroupNode tempGroupNode = new FilterableGroupNode();
  88. if(GuiSettings.getSelectedObjects().isEmpty()){
  89. tempGroupNode.add(control.getModel().getCanvas());
  90. }else{
  91. tempGroupNode.addAll(GuiSettings.getSelectedObjects());
  92. }
  93. List<HolonObject> filteredHolonObjectList = tempGroupNode.getAllHolonObjectsRecursive().filter(this::stateFilter).toList();
  94. Map<HolonObjectState, Long> stateMap = filteredHolonObjectList.stream().collect(Collectors.groupingBy(HolonObject::getState, Collectors.counting()));
  95. // UPDATE SUPPLY STATE
  96. int producerAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PRODUCER, 0L));
  97. int overSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.OVER_SUPPLIED, 0L));
  98. int suppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.SUPPLIED, 0L));
  99. int partiallySuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PARTIALLY_SUPPLIED, 0L));
  100. int notSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NOT_SUPPLIED, 0L));
  101. int noEnergyAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NO_ENERGY, 0L));
  102. supplyChart.updatePieSeries("Producer", producerAmount);
  103. supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
  104. supplyChart.updatePieSeries("Supplied", suppliedAmount);
  105. supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
  106. supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
  107. supplyChart.updatePieSeries("No energy", noEnergyAmount);
  108. supplyChart.updatePieSeries("No Data", filteredHolonObjectList.isEmpty() ? 1 : 0);
  109. //UPDATE PRIORITIES
  110. List<HolonElement> filteredHolonElements = filteredHolonObjectList.stream().flatMap(HolonObject::elementsStream)
  111. .filter(ele -> priorityFilter(ele) && activeFilter(ele) && flexibilityFilter(ele)).toList();
  112. Map<HolonElement.Priority, Long> priorityCounts = filteredHolonElements.stream()
  113. .collect(Collectors.groupingBy(HolonElement::getPriority, Collectors.counting()));
  114. long essential = priorityCounts.getOrDefault(HolonElement.Priority.Essential, 0L);
  115. long high = priorityCounts.getOrDefault(HolonElement.Priority.High, 0L);
  116. long medium = priorityCounts.getOrDefault(HolonElement.Priority.Medium, 0L);
  117. long low = priorityCounts.getOrDefault(HolonElement.Priority.Low, 0L);
  118. priorityChart.updatePieSeries("Essential", essential);
  119. priorityChart.updatePieSeries("High", high);
  120. priorityChart.updatePieSeries("Medium", medium);
  121. priorityChart.updatePieSeries("Low", low);
  122. boolean hasPriority = essential + high + medium + low > 0;
  123. priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
  124. // UPDATE PRODUCTION
  125. float consumption = filteredHolonElements.stream().filter(element -> element.getActualEnergy() < 0)
  126. .map(element -> -element.getActualEnergy()).reduce(0.0f, Float::sum);
  127. float production = filteredHolonElements.stream()
  128. .map(HolonElement::getActualEnergy).filter(energy -> energy > 0).reduce(0.0f, Float::sum);
  129. float difference = Math.abs(production - consumption);
  130. energyChart.updatePieSeries("Production", production);
  131. energyChart.updatePieSeries("Consumption", consumption);
  132. energyChart.updatePieSeries("No Data", production + consumption == 0 ? 1 : 0);
  133. differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
  134. // UPDATE FLEXIBILITIES
  135. int inUse = 0;
  136. int offered = 0;
  137. int onCooldown = 0;
  138. int notOffered = 0;
  139. int unavailable = 0;
  140. List<Flexibility> flexList = filteredHolonElements.stream().flatMap(ele -> ele.flexList.stream()).toList();
  141. for (Flexibility flex : flexList) {
  142. switch (flex.getState()) {
  143. case IN_USE -> inUse++;
  144. case NOT_OFFERED -> notOffered++;
  145. case OFFERED -> offered++;
  146. case ON_COOLDOWN -> onCooldown++;
  147. case UNAVAILABLE -> unavailable++;
  148. default -> {
  149. }
  150. }
  151. }
  152. int noFlexibility = (int)filteredHolonElements.stream().filter(ele -> ele.flexList.isEmpty()).count();
  153. flexibilityChart.updatePieSeries("No flexibility", noFlexibility);
  154. flexibilityChart.updatePieSeries("Offered", offered);
  155. flexibilityChart.updatePieSeries("In use", inUse);
  156. flexibilityChart.updatePieSeries("On cooldown", onCooldown);
  157. flexibilityChart.updatePieSeries("Not offered", notOffered);
  158. flexibilityChart.updatePieSeries("Unavailable", unavailable);
  159. boolean hasFlex = noFlexibility + offered + inUse + onCooldown + notOffered + unavailable > 0;
  160. flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
  161. Map<Boolean, Long> activeCounts = filteredHolonElements.stream()
  162. .collect(Collectors.groupingBy(HolonElement::isOn, Collectors.counting()));
  163. // UPDATE ActiveInActive
  164. int activeAmount = Math.toIntExact(activeCounts.getOrDefault(true, 0L));
  165. int inactiveAmounts = Math.toIntExact(activeCounts.getOrDefault(false, 0L));
  166. activeChart.updatePieSeries("Active", activeAmount);
  167. activeChart.updatePieSeries("Inactive", inactiveAmounts);
  168. activeChart.updatePieSeries("No Data", activeAmount + inactiveAmounts == 0 ? 1 : 0);
  169. this.revalidate();
  170. this.repaint();
  171. }
  172. private JPopupMenu createHolonStateSelection(){
  173. JPopupMenu menu = new JPopupMenu();
  174. producerCheckBox.addActionListener(clicked -> updateCharts());
  175. overSuppliedCheckBox.addActionListener(clicked -> updateCharts());
  176. suppliedCheckBox.addActionListener(clicked -> updateCharts());
  177. partiallySuppliedCheckBox.addActionListener(clicked -> updateCharts());
  178. notSuppliedCheckBox.addActionListener(clicked -> updateCharts());
  179. noEnergyCheckBox.addActionListener(clicked -> updateCharts());
  180. menu.add(producerCheckBox);
  181. menu.add(overSuppliedCheckBox);
  182. menu.add(suppliedCheckBox);
  183. menu.add(partiallySuppliedCheckBox);
  184. menu.add(notSuppliedCheckBox);
  185. menu.add(noEnergyCheckBox);
  186. return menu;
  187. }
  188. private JPopupMenu createPrioritySelection(){
  189. JPopupMenu menu = new JPopupMenu();
  190. essentialCheckBox.addActionListener(clicked -> updateCharts());
  191. highCheckBox.addActionListener(clicked -> updateCharts());
  192. mediumBox.addActionListener(clicked -> updateCharts());
  193. lowCheckBox.addActionListener(clicked -> updateCharts());
  194. menu.add(essentialCheckBox);
  195. menu.add(highCheckBox);
  196. menu.add(mediumBox);
  197. menu.add(lowCheckBox);
  198. return menu;
  199. }
  200. private JPopupMenu createActiveSelection(){
  201. JPopupMenu menu = new JPopupMenu();
  202. activeCheckBox.addActionListener(clicked -> updateCharts());
  203. inactiveCheckBox.addActionListener(clicked -> updateCharts());
  204. menu.add(activeCheckBox);
  205. menu.add(inactiveCheckBox);
  206. return menu;
  207. }
  208. private JPopupMenu createFlexibilitySelection(){
  209. JPopupMenu menu = new JPopupMenu();
  210. noFlexibilityCheckBox.addActionListener(clicked -> updateCharts());
  211. offeredCheckBox.addActionListener(clicked -> updateCharts());
  212. notOfferedCheckBox.addActionListener(clicked -> updateCharts());
  213. unavailableCheckBox.addActionListener(clicked -> updateCharts());
  214. inUseCheckBox.addActionListener(clicked -> updateCharts());
  215. onCooldownCheckBox.addActionListener(clicked -> updateCharts());
  216. menu.add(noFlexibilityCheckBox);
  217. menu.add(offeredCheckBox);
  218. menu.add(notOfferedCheckBox);
  219. menu.add(unavailableCheckBox);
  220. menu.add(inUseCheckBox);
  221. menu.add(onCooldownCheckBox);
  222. return menu;
  223. }
  224. private JPanel initMenuButtonPanel(JPopupMenu menu){
  225. JPanel buttonPanel = new JPanel(new BorderLayout());
  226. MenuButton button = new MenuButton(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.Filter, 20, 20)), menu);
  227. buttonPanel.add(button, BorderLayout.LINE_END);
  228. buttonPanel.setOpaque(false);
  229. button.setPressedIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
  230. button.setRolloverIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
  231. button.setBorderPainted(false);
  232. button.setBorder(null);
  233. button.setFocusable(false);
  234. button.setMargin(new Insets(0, 0, 0, 0));
  235. button.setContentAreaFilled(false);
  236. return buttonPanel;
  237. }
  238. private boolean stateFilter(HolonObject holonObject){
  239. return switch (holonObject.getState()) {
  240. case PRODUCER -> producerCheckBox.isSelected();
  241. case OVER_SUPPLIED -> overSuppliedCheckBox.isSelected();
  242. case SUPPLIED -> suppliedCheckBox.isSelected();
  243. case PARTIALLY_SUPPLIED -> partiallySuppliedCheckBox.isSelected();
  244. case NOT_SUPPLIED -> notSuppliedCheckBox.isSelected();
  245. case NO_ENERGY -> noEnergyCheckBox.isSelected();
  246. };
  247. }
  248. private boolean priorityFilter(HolonElement ele){
  249. return switch (ele.priority) {
  250. case Essential -> essentialCheckBox.isSelected();
  251. case High -> highCheckBox.isSelected();
  252. case Medium -> mediumBox.isSelected();
  253. case Low -> lowCheckBox.isSelected();
  254. };
  255. }
  256. private boolean activeFilter(HolonElement ele){
  257. return ele.active ? activeCheckBox.isSelected(): inactiveCheckBox.isSelected();
  258. }
  259. private boolean flexibilityFilter(HolonElement ele){
  260. if(ele.flexList.isEmpty()){
  261. return noFlexibilityCheckBox.isSelected();
  262. }
  263. Map<Flexibility.FlexState,Long> flexes = ele.flexList.stream().collect(Collectors.groupingBy(Flexibility::getState, Collectors.counting()));
  264. return flexes.keySet().stream().anyMatch(flexState -> switch (flexState) {
  265. case IN_USE -> inUseCheckBox.isSelected();
  266. case UNAVAILABLE -> unavailableCheckBox.isSelected();
  267. case OFFERED -> offeredCheckBox.isSelected();
  268. case NOT_OFFERED -> notOfferedCheckBox.isSelected();
  269. case ON_COOLDOWN -> onCooldownCheckBox.isSelected();
  270. });
  271. }
  272. public static class MenuButton extends JToggleButton {
  273. JPopupMenu popup;
  274. public MenuButton(Icon icon, JPopupMenu menu) {
  275. super(icon);
  276. this.popup = menu;
  277. addActionListener(clicked -> {
  278. if (MenuButton.this.isSelected()) {
  279. popup.show(MenuButton.this, 0, MenuButton.this.getBounds().height);
  280. } else {
  281. popup.setVisible(false);
  282. }
  283. });
  284. popup.addPopupMenuListener(new PopupMenuListener() {
  285. @Override
  286. public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
  287. @Override
  288. public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
  289. MenuButton.this.setSelected(false);
  290. }
  291. @Override
  292. public void popupMenuCanceled(PopupMenuEvent e) {}
  293. });
  294. }
  295. }
  296. private void initGraphPanel() {
  297. graphPanel.setBackground(ColorPreference.Panel.Background);
  298. XChartPanel<PieChart> panelHolonObject = new XChartPanel<>(supplyChart);
  299. panelHolonObject.setLayout(new BorderLayout());
  300. panelHolonObject.add(initMenuButtonPanel(createHolonStateSelection()), BorderLayout.PAGE_START);
  301. panelHolonObject.setBackground(ColorPreference.Panel.Background);
  302. graphPanel.add(panelHolonObject);
  303. XChartPanel<PieChart> panelPriority = new XChartPanel<>(priorityChart);
  304. panelPriority.setLayout(new BorderLayout());
  305. panelPriority.add(initMenuButtonPanel(createPrioritySelection()), BorderLayout.PAGE_START);
  306. panelPriority.setBackground(ColorPreference.Panel.Background);
  307. graphPanel.add(panelPriority);
  308. XChartPanel<PieChart> panelFlexibility = new XChartPanel<>(flexibilityChart);
  309. panelFlexibility.setLayout(new BorderLayout());
  310. panelFlexibility.add(initMenuButtonPanel(createFlexibilitySelection()), BorderLayout.PAGE_START);
  311. panelFlexibility.setBackground(ColorPreference.Panel.Background);
  312. graphPanel.add(panelFlexibility);
  313. Component panel = initEnergyChart();
  314. graphPanel.add(panel);
  315. XChartPanel<PieChart> panelActive = new XChartPanel<>(activeChart);
  316. panelActive.setLayout(new BorderLayout());
  317. panelActive.add(initMenuButtonPanel(createActiveSelection()), BorderLayout.PAGE_START);
  318. panelActive.setBackground(ColorPreference.Panel.Background);
  319. graphPanel.add(panelActive);
  320. graphPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
  321. }
  322. private JLayeredPane initEnergyChart() {
  323. JLayeredPane panel = new JLayeredPane();
  324. JPanel panelMiddle = new JPanel(new GridBagLayout());
  325. XChartPanel<PieChart> panelEnergy = new XChartPanel<>(energyChart);
  326. panelEnergy.setBackground(ColorPreference.Panel.Background);
  327. GridBagConstraints c = new GridBagConstraints();
  328. c.gridx = 0;
  329. c.gridy = 0;
  330. c.insets = new Insets(15, 0, 0, 0); // top padding
  331. JLabel difference = new JLabel("Difference:");
  332. difference.setHorizontalAlignment(JLabel.CENTER);
  333. difference.setAlignmentX(Component.CENTER_ALIGNMENT);
  334. difference.setForeground(ColorPreference.Panel.Title);
  335. difference.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 10));
  336. panelMiddle.add(difference, c);
  337. differenceEnergyLabelAmount.setHorizontalAlignment(JLabel.CENTER);
  338. differenceEnergyLabelAmount.setForeground(Color.red);
  339. differenceEnergyLabelAmount.setAlignmentX(Component.CENTER_ALIGNMENT);
  340. differenceEnergyLabelAmount.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 12));
  341. c.insets = new Insets(0, 0, 0, 0);
  342. c.gridy = 1;
  343. panelMiddle.add(differenceEnergyLabelAmount, c);
  344. panel.setLayout(new OverlayLayout(panel));
  345. panelEnergy.setOpaque(false);
  346. panelMiddle.setOpaque(false);
  347. panel.add(panelMiddle, Integer.valueOf(0));
  348. panel.add(panelEnergy, Integer.valueOf(1));
  349. return panel;
  350. }
  351. public void initTitlePanel() {
  352. titlePanel.setBackground(ColorPreference.Panel.Background);
  353. titlePanel.setBorder(new EmptyBorder(5, 5, 2, 0));
  354. }
  355. public void setDefaultPieChartSettings(PieChart chart) {
  356. PieStyler styler = chart.getStyler();
  357. styler.setChartTitleVisible(true);
  358. styler.setDefaultSeriesRenderStyle(PieSeriesRenderStyle.Donut);
  359. styler.setLabelsFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 14));
  360. styler.setLabelType(LabelType.Percentage);
  361. styler.setLabelsFontColor(Color.black);
  362. styler.setLabelsFontColorAutomaticEnabled(false);
  363. styler.setLabelsDistance(0.8);
  364. styler.setChartFontColor(ColorPreference.Panel.Title);
  365. styler.setToolTipsEnabled(true);
  366. styler.setPlotContentSize(0.9);
  367. styler.setPlotBackgroundColor(ColorPreference.Panel.Transparent);
  368. styler.setPlotBorderColor(ColorPreference.Panel.Transparent);
  369. styler.setLegendVisible(false);
  370. styler.setChartBackgroundColor(ColorPreference.Panel.Transparent);
  371. }
  372. public PieChart createSupplyStateChart() {
  373. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("HolonObjects").build();
  374. setDefaultPieChartSettings(chart);
  375. chart.getStyler().setSeriesColors(supplyStateColors);
  376. // Series
  377. chart.addSeries("Producer", 0);
  378. chart.addSeries("Over supplied", 0);
  379. chart.addSeries("Supplied", 0);
  380. chart.addSeries("Partial supplied", 0);
  381. chart.addSeries("Not supplied", 0);
  382. chart.addSeries("No energy", 0);
  383. chart.addSeries("No Data", 0);
  384. return chart;
  385. }
  386. public PieChart createPriorityChart() {
  387. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Priorities").build();
  388. setDefaultPieChartSettings(chart);
  389. // Customize Chart
  390. chart.getStyler().setSeriesColors(priorityColors);
  391. // Series
  392. chart.addSeries("Essential", 0);
  393. chart.addSeries("High", 0);
  394. chart.addSeries("Medium", 0);
  395. chart.addSeries("Low", 0);
  396. chart.addSeries("No Data", 0);
  397. return chart;
  398. }
  399. public PieChart createFlexibilityChart() {
  400. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Flexibilities").build();
  401. setDefaultPieChartSettings(chart);
  402. // Customize Chart
  403. chart.getStyler().setSeriesColors(flexibilityColors);
  404. // Series
  405. chart.addSeries("Offered", 0);
  406. chart.addSeries("In use", 0);
  407. chart.addSeries("On cooldown", 0);
  408. chart.addSeries("Not offered", 0);
  409. chart.addSeries("Unavailable", 0);
  410. chart.addSeries("No flexibility", 0);
  411. chart.addSeries("No Data", 0);
  412. return chart;
  413. }
  414. public PieChart createProductionChart() {
  415. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight)
  416. .title("Production vs. Consumption").build();
  417. setDefaultPieChartSettings(chart);
  418. // Customize Chart
  419. // Customize Chart
  420. chart.getStyler().setSeriesColors(productionColors);
  421. // Series
  422. chart.addSeries("Production", 0);
  423. chart.addSeries("Consumption", 0);
  424. chart.addSeries("No Data", 0);
  425. return chart;
  426. }
  427. public PieChart createActiveChart() {
  428. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Active").build();
  429. setDefaultPieChartSettings(chart);
  430. // Customize Chart
  431. // Customize Chart
  432. chart.getStyler().setSeriesColors(activeColors);
  433. // Series
  434. chart.addSeries("Active", 0);
  435. chart.addSeries("Inactive", 0);
  436. chart.addSeries("No Data", 0);
  437. return chart;
  438. }
  439. }