Ejemplo n.º 1
0
class Chart(QWidget):
    def __init__(self, chartKey, data, frame, parent=None):
        super(Chart, self).__init__(parent)
        self.frame = frame
        self.data = data
        self.create_chart(chartKey)

    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()

        #Add series to the chart
        self.addSeries(chartKey)

        # for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("Code Size Visualizer")
        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignRight)
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)

    #each section of the pie chart
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)

        #Show chartview only if the content length is less than 6. Otherwise show a table view
        if len(self.data[key]) < 6:
            #print('length',self.data, key)
            for key, value in self.data[key].items():
                print('key, value', key, value)
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)

            self.series.setLabelsVisible()
            self.series.setLabelsPosition(QPieSlice.LabelInsideHorizontal)

            for slice in self.series.slices():
                #slice.setLabel(slice.label())
                slice.setLabel(slice.label() + ' - ' + str(slice.value()) +
                               ' B ')

            self.chart.addSeries(self.series)
            self.frame.frame.hide()
            self.chart.show()
        else:
            self.table = TableView(self.data[key], len(self.data[key]), 1)

            if self.frame.ly.count() > 0:
                self.frame.ly.itemAt(0).widget().setParent(None)

            self.frame.ly.addWidget(self.table)

            self.frame.frame.show()
            self.chart.hide()
Ejemplo n.º 2
0
class Chart(QtWidgets.QWidget):
    def __init__(self,chartKey, frame, parent=None):
        super(Chart, self).__init__(parent, QtCore.Qt.Window)  
        self.frame = frame
        self.create_chart(chartKey)
        
        
    @QtCore.pyqtSlot()
    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()
        
        print('inside chart',self.frame)
        
        #Add series to the chart
        self.addSeries(chartKey)

	# for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)
        
        
       
        
        
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        print(self.series)
        self.series.setHoleSize(0.35)
        print('chart',key)
        
        if len(sampleData[key]) == 2:
            for key, value in sampleData[key].items():
                #print("adding series", str(key), value)
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)
       
            self.chart.addSeries(self.series)
            #self.frame.frame.hide()
            
            #self.frame.frame.removeWidget(self.table)
            
            self.frame.frame.hide()
            self.chart.show()
        else:
            print('hi')
            
            self.table = TableView(data, 5, 4)
            
            
            if self.frame.ly.count() == 0:
                self.frame.ly.addWidget(self.table)
            
            self.frame.frame.show()
            self.chart.hide()
            #print(frame)
            print('parent', self.parent())
Ejemplo n.º 3
0
class Chart(QWidget):
    def __init__(self, chartKey, data, frame, parent=None):
        super(Chart, self).__init__(parent)
        self.frame = frame
        self.data = data

        self.pt = self.parent()

        #add the to the main window
        #self.toolbar = QToolBar("Edit", self)
        #self.pt.addToolBar(self.toolbar)

        #ly = QtWidgets.QVBoxLayout()
        #self.frame = QtWidgets.QFrame()
        #self.frame.setLayout(ly)

        #self.layout = QtWidgets.QGridLayout()

        #print('----------------',self.frame)

        self.create_chart(chartKey)
        clicked = QtCore.pyqtSignal(QtCore.QModelIndex)
        #self.pt.addToolBar(self.navigationBar(data))

    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()

        #Add series to the chart
        self.addSeries(chartKey)

        # for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)

        #navigation = Navigation(classObj, self)
        #self.addToolBar(navigation.toolbar)

        #clicked = QtCore.pyqtSignal(QtCore.QModelIndex)

    def navigationBar(self, data):
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.actionTriggered.connect(self.on_actionTriggered)
        self.model = QtGui.QStandardItemModel(self)
        dict_to_model(self.model.invisibleRootItem(), data)
        it = self.model.item(0, 0)
        ix = self.model.indexFromItem(it)
        root_action = self.toolbar.addAction(it.text())
        root_action.setData(QtCore.QPersistentModelIndex(ix))
        self.listview = QtWidgets.QListView()
        self.listview.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        #self.series.doubleClicked.connect(self.on_clicked)
        self.listview.setModel(self.model)
        self.listview.setRootIndex(ix)
        self.a = 10

        return self.toolbar

    #make the listed items clickable
    #@QtCore.pyqtSlot(QtCore.QModelIndex)
    def on_clicked(self, index):
        if not self.model.hasChildren(index):
            self.clicked.emit(index)
            return
        action = self.toolbar.addAction(index.data())
        action.setData(QtCore.QPersistentModelIndex(index))
        self.listview.setRootIndex(index)
        print(index.data())
        self.chart.addSeries(index.data())

    #make the breadcrumbs clickable in order to go back and forth
    #@QtCore.pyqtSlot(QtWidgets.QAction)
    def on_actionTriggered(self, action):
        ix = action.data()
        self.chart.addSeries(ix.data())
        model = ix.model()
        self.listview.setRootIndex(QtCore.QModelIndex(ix))
        self.toolbar.clear()
        ixs = []
        while ix.isValid():
            ixs.append(ix)
            ix = ix.parent()
        for ix in reversed(ixs):
            action = self.toolbar.addAction(ix.data())
            action.setData(ix)

    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)

        #Show chartview only if the content length is less than 6. Otherwise show a table view
        if len(self.data[key]) < 6:
            for key, value in self.data[key].items():
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)

            for slice in self.series.slices():
                slice.setLabel(slice.label())

            self.chart.addSeries(self.series)
            self.frame.frame.hide()
            self.chart.show()
        else:
            for m, item in self.data[key].items():
                print(m, item)

            self.table = TableView(self.data[key], len(self.data[key]), 1)

            if self.frame.ly.count() > 0:
                self.frame.ly.itemAt(0).widget().setParent(None)

            self.frame.ly.addWidget(self.table)

            self.frame.frame.show()
            self.chart.hide()

        self.series.doubleClicked.connect(self.handle_double_clicked)

    #Show the update chart with the distribution of the selected slice
    def handle_double_clicked(self, slice):
        slice.setExploded()
        slice.setLabelVisible()

        if slice.label() in self.data.keys():
            print("slice", slice.label())
            self.addSeries(slice.label())