Skip to content

Commit 33410b5

Browse files
committed
Added swimming lines in Genealogy Chart
* #11
1 parent 76bab67 commit 33410b5

File tree

8 files changed

+161
-3
lines changed

8 files changed

+161
-3
lines changed

MLC/GUI/Autogenerated/autogenerated.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def setupUi(self, Experiment):
597597
Experiment.setCentralWidget(self.centralWidget)
598598

599599
self.retranslateUi(Experiment)
600-
self.tabWidget.setCurrentIndex(1)
600+
self.tabWidget.setCurrentIndex(0)
601601
self.next_gen_button.clicked.connect(Experiment.on_next_gen_button_clicked)
602602
self.save_config_button.clicked.connect(Experiment.on_save_config_button_clicked)
603603
self.dimension_check.clicked.connect(Experiment.on_dimension_check_clicked)
@@ -675,6 +675,45 @@ def retranslateUi(self, Experiment):
675675

676676
# -*- coding: utf-8 -*-
677677

678+
# Form implementation generated from reading ui file './untitled/genealogy.ui'
679+
#
680+
# Created by: PyQt5 UI code generator 5.7
681+
#
682+
# WARNING! All changes made in this file will be lost!
683+
684+
from PyQt5 import QtCore, QtGui, QtWidgets
685+
686+
class Ui_GenealogyWindow(object):
687+
def setupUi(self, GenealogyWindow):
688+
GenealogyWindow.setObjectName("GenealogyWindow")
689+
GenealogyWindow.setWindowModality(QtCore.Qt.ApplicationModal)
690+
GenealogyWindow.resize(400, 300)
691+
self.centralWidget = QtWidgets.QWidget(GenealogyWindow)
692+
self.centralWidget.setObjectName("centralWidget")
693+
self.chart_layout = QtWidgets.QVBoxLayout(self.centralWidget)
694+
self.chart_layout.setObjectName("chart_layout")
695+
self.textEdit = QtWidgets.QTextEdit(self.centralWidget)
696+
self.textEdit.setObjectName("textEdit")
697+
self.chart_layout.addWidget(self.textEdit)
698+
GenealogyWindow.setCentralWidget(self.centralWidget)
699+
self.menuBar = QtWidgets.QMenuBar(GenealogyWindow)
700+
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 19))
701+
self.menuBar.setObjectName("menuBar")
702+
GenealogyWindow.setMenuBar(self.menuBar)
703+
self.toolBar = QtWidgets.QToolBar(GenealogyWindow)
704+
self.toolBar.setObjectName("toolBar")
705+
GenealogyWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
706+
707+
self.retranslateUi(GenealogyWindow)
708+
# QtCore.QMetaObject.connectSlotsByName(GenealogyWindow)
709+
710+
def retranslateUi(self, GenealogyWindow):
711+
_translate = QtCore.QCoreApplication.translate
712+
GenealogyWindow.setWindowTitle(_translate("GenealogyWindow", "Genealogy Chart"))
713+
self.toolBar.setWindowTitle(_translate("GenealogyWindow", "toolBar"))
714+
715+
# -*- coding: utf-8 -*-
716+
678717
# Form implementation generated from reading ui file './untitled/edit_properties.ui'
679718
#
680719
# Created by: PyQt5 UI code generator 5.7
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>GenealogyWindow</class>
4+
<widget class="QMainWindow" name="GenealogyWindow">
5+
<property name="windowModality">
6+
<enum>Qt::ApplicationModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>400</width>
13+
<height>300</height>
14+
</rect>
15+
</property>
16+
<property name="windowTitle">
17+
<string>Genealogy Chart</string>
18+
</property>
19+
<widget class="QWidget" name="centralWidget">
20+
<layout class="QVBoxLayout" name="chart_layout">
21+
<item>
22+
<widget class="QTextEdit" name="textEdit"/>
23+
</item>
24+
</layout>
25+
</widget>
26+
<widget class="QMenuBar" name="menuBar">
27+
<property name="geometry">
28+
<rect>
29+
<x>0</x>
30+
<y>0</y>
31+
<width>400</width>
32+
<height>19</height>
33+
</rect>
34+
</property>
35+
</widget>
36+
<widget class="QToolBar" name="toolBar">
37+
<property name="windowTitle">
38+
<string>toolBar</string>
39+
</property>
40+
<attribute name="toolBarArea">
41+
<enum>TopToolBarArea</enum>
42+
</attribute>
43+
<attribute name="toolBarBreak">
44+
<bool>false</bool>
45+
</attribute>
46+
</widget>
47+
</widget>
48+
<resources/>
49+
<connections/>
50+
</ui>

MLC/GUI/Autogenerated/untitled/untitled.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ FORMS += \
2121
mainwindow.ui \
2222
experiment.ui \
2323
edit_properties.ui \
24-
experiment_in_progress.ui
24+
experiment_in_progress.ui \
25+
genealogy.ui
2526

2627
DISTFILES += \
2728
New_projectForm.ui.qml \

MLC/GUI/Autogenerated/untitled/untitled.pro.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.2.0, 2017-01-17T23:56:31. -->
3+
<!-- Written by QtCreator 4.2.0, 2017-01-20T09:40:09. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>

MLC/GUI/Experiment/ExperimentDialog.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from MLC.GUI.Experiment.MatplotlibCanvas.CostPerIndividualCanvas import CostPerIndividualCanvas
1313
from MLC.GUI.Experiment.QtCharts.QtChartWrapper import QtChartWrapper
1414
from MLC.GUI.Experiment.ExperimentInProgress import ExperimentInProgress
15+
from MLC.GUI.Experiment.GenealogyDialog import GenealogyDialog
1516
from MLC.GUI.Tables.ConfigDictTableModel import ConfigDictTableModel
1617
from MLC.GUI.Tables.ConfigTableModel import ConfigTableModel
1718
from MLC.individual.Individual import Individual
@@ -251,6 +252,8 @@ def on_convergence_button_clicked(self):
251252

252253
def on_genealogy_button_clicked(self):
253254
logger.debug('[EXPERIMENT {0}] [GENEALOGY_BUTTON] - Executing on_genealogy_button_clicked function')
255+
dialog = GenealogyDialog(self, self._mlc_local, self._current_gen, 10)
256+
dialog.show()
254257

255258
def _config_table_edited(self, left, right):
256259
config_table = self._autogenerated_object.config_table
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from MLC.GUI.Autogenerated.autogenerated import Ui_GenealogyWindow
2+
from MLC.GUI.Experiment.QtCharts.GenealogyChart import GenealogyChart
3+
from PyQt5.QtWidgets import QMainWindow
4+
5+
class GenealogyDialog(QMainWindow):
6+
7+
def __init__(self, parent, mlc_local, generation, individual):
8+
QMainWindow.__init__(self, parent)
9+
self._autogenerated_object = Ui_GenealogyWindow()
10+
self._autogenerated_object.setupUi(self)
11+
12+
self._genealogy_chart = GenealogyChart(mlc_local, generation, individual)
13+
self._create_new_chart()
14+
15+
def _create_new_chart(self):
16+
chart_layout = self._autogenerated_object.chart_layout
17+
18+
# Remove all previous widgets before rendering again
19+
for i in reversed(range(chart_layout.count())):
20+
chart_layout.itemAt(i).widget().setParent(None)
21+
# Add the Indiv Canvas
22+
chart_layout.addWidget(self._genealogy_chart.get_widget())
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from MLC.GUI.Experiment.QtCharts.QtChartWrapper import QtChartWrapper
2+
from MLC.mlc_parameters.mlc_parameters import Config
3+
from PyQt5.QtCore import Qt
4+
5+
6+
class GenealogyChart(QtChartWrapper):
7+
CHART_COLORS = [Qt.black, Qt.red, Qt.green, Qt.blue,
8+
Qt.cyan, Qt.magenta, Qt.yellow, Qt.gray]
9+
10+
def __init__(self, mlc_local, generation, individual):
11+
QtChartWrapper.__init__(self, False)
12+
self._mlc_local = mlc_local
13+
self._indivs_per_gen = Config.get_instance().getint("POPULATION", "size")
14+
self._amount_generations = generation
15+
self._indiv_index = individual
16+
17+
self._add_axis()
18+
self._add_swimming_lines()
19+
20+
def _add_axis(self):
21+
# Set the object name to be able to retrieve it later
22+
self.set_xaxis(log=False, label="Generations",
23+
label_format='%i', tick_count=self._amount_generations)
24+
self.set_yaxis(log=False, label="Individuals",
25+
label_format='%g', tick_count=10)
26+
27+
chart_view = self.get_widget()
28+
chart_view.chart().axisX().setRange(1, self._amount_generations)
29+
chart_view.chart().axisY().setRange(1, self._indivs_per_gen)
30+
31+
def _add_swimming_lines(self):
32+
amount_colors = len(GenealogyChart.CHART_COLORS)
33+
# TODO: Increase the marker size
34+
# when the individuals amount per generations decrease
35+
marker_size = 3
36+
37+
for index in xrange(self._amount_generations + 1):
38+
self.add_scatter(marker_size=marker_size,
39+
color=GenealogyChart.CHART_COLORS[index % amount_colors])
40+
41+
for indiv_id in xrange(self._indivs_per_gen):
42+
self.append_point(index, index, indiv_id)

MLC/GUI/Experiment/QtCharts/QtChartWrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, show_legend=False):
1818
self._chart.legend().hide()
1919

2020
self._view = QChartView(self._chart)
21+
self._view.setRubberBand(QChartView.RectangleRubberBand)
2122
self._view.setRenderHint(QPainter.Antialiasing)
2223
self._view.setUpdatesEnabled(True)
2324

0 commit comments

Comments
 (0)