FunnelChart2D Example

import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../shared")

from DevMachines import __pyside2__, __pyside6__
from DevMachines.QtitanBase import Qtitan
from DevMachines.QtitanChart import (ChartPyramidSeriesLabel, ChartFunnelSeries2D)

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt
    from PySide2.QtWidgets import (QApplication, QComboBox, QSlider, QLabel)

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt
    from PySide6.QtWidgets import (QApplication, QComboBox, QSlider, QLabel)

from DemoChartWindow import DemoChartWindow

class MainWindow(DemoChartWindow):
    def __init__(self):
        DemoChartWindow.__init__(self, "Funnel Chart 2D")
        self.setChart(None)
        self.createSeriesParametrs()
        self.createFunnelSeries()
        self.updateValueParameters()

    def createSeriesParametrs(self):
        seriesTypeGroup = self.createGroupParameters(self.tr("Series"))
        localLayout = seriesTypeGroup.layout()

        self.transparency = QSlider(Qt.Horizontal, seriesTypeGroup)
        self.transparency.setRange(0, 255)
        self.transparency.setSliderPosition(255)
        self.transparency.setSingleStep(5)
        self.connect(self.transparency, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("transparencyChanged(int)"))
        localLayout.addRow(QLabel(self.tr("Transparency:"), seriesTypeGroup))
        localLayout.addRow(self.transparency)

        self.gapSize = QSlider(Qt.Horizontal, seriesTypeGroup)
        self.gapSize.setRange(0, 20)
        self.gapSize.setSliderPosition(4)
        self.gapSize.setSingleStep(1)
        self.connect(self.gapSize, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("gapSizeChanged(int)"))
        localLayout.addRow(QLabel(self.tr("Point Gap:"), seriesTypeGroup))
        localLayout.addRow(self.gapSize)

        self.neckHeightInPercents = QSlider(Qt.Horizontal, seriesTypeGroup)
        self.neckHeightInPercents.setRange(0, 100)
        self.neckHeightInPercents.setSliderPosition(25)
        self.neckHeightInPercents.setSingleStep(1)
        self.connect(self.neckHeightInPercents, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("neckHeightInPercentsChanged(int)"))
        localLayout.addRow(QLabel(self.tr("Neck Height %:"), seriesTypeGroup))
        localLayout.addRow(self.neckHeightInPercents)

        # Option Labels
        self.dataLabelsGroup = self.createGroupParameters(self.tr("Show Data Labels"), True)
        localLayout = self.dataLabelsGroup.layout()

        self.connect(self.dataLabelsGroup, QtCore.SIGNAL("toggled(bool)"), self, QtCore.SLOT("showDataLabels(bool)"))
        self.angleDataLabelsSwitcher = QComboBox(self.dataLabelsGroup)
        self.angleDataLabelsSwitcher.addItem("Left", ChartPyramidSeriesLabel.Left)
        self.angleDataLabelsSwitcher.addItem("Right", ChartPyramidSeriesLabel.Right)
        self.angleDataLabelsSwitcher.addItem("Center", ChartPyramidSeriesLabel.Center)
        self.angleDataLabelsSwitcher.setCurrentIndex(1)
        self.connect(self.angleDataLabelsSwitcher, QtCore.SIGNAL("currentIndexChanged(int)"), self, QtCore.SLOT("labelsPositionChanged(int)"))
        # Layouts Labels
        localLayout.addRow(self.tr("Position:"), self.angleDataLabelsSwitcher)

    def createFunnelSeries(self):
        self.createTitle(self.tr("Web Site Visitor Trend"))
        self.chart.legend().setVisible(True)

        series = ChartFunnelSeries2D()

        pnt = series.add(9152, self.tr("Visited a Web Site: 9152"))
        pnt.setLegendText(self.tr("Visited a Web Site: 100%"))

        pnt = series.add(6870, self.tr("Downloaded a Trial: 6870"))
        pnt.setLegendText(self.tr("Downloaded a Trial: 75%"))

        pnt = series.add(5121, self.tr("Contacted to Support: 5121"))
        pnt.setLegendText(self.tr("Contacted to Support: 56%"))

        pnt = series.add(2224, self.tr("Subscribed: 2224"))
        pnt.setLegendText(self.tr("Subscribed: 24%"))

        pnt = series.add(1670, self.tr("Renewed: 1670"))
        pnt.setLegendText(self.tr("Renewed: 18%"))

        series.setNeckHeightInPercents(25.0)
        self.chart.appendSeries(series)

    def updateValueParameters(self):
        DemoChartWindow.updateValueParameters(self)
        self.transparencyChanged(self.transparency.value())
        self.gapSizeChanged(self.gapSize.value())
        self.labelsPositionChanged(self.angleDataLabelsSwitcher.currentIndex())

    def transparencyChanged(self, value):
        listSeries = self.chart.series()
        for series in listSeries:
            if series.inherits("Qtitan::ChartFunnelSeries2D"):
                series.setTransparency(value)

    def gapSizeChanged(self, value):
        listSeries = self.chart.series()
        for series in listSeries:
            if series.inherits("Qtitan::ChartFunnelSeries2D"):
                series.setGapSize(value)

    def neckHeightInPercentsChanged(self, value):
        listSeries = self.chart.series()
        for series in listSeries:
            if series.inherits("Qtitan::ChartFunnelSeries2D"):
                series.setNeckHeightInPercents(value)

    def labelsPositionChanged(self, index):
        v = self.angleDataLabelsSwitcher.itemData(index)
        listSeries = self.chart.series()
        for series in listSeries:
            label = series.label()
            if label.inherits("Qtitan::ChartPyramidSeriesLabel"):
                label.setPosition(ChartPyramidSeriesLabel.Position(int(v)))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())