• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nens / ThreeDiToolbox / #2585

16 Sep 2025 02:14PM UTC coverage: 35.069% (-0.08%) from 35.146%
#2585

push

coveralls-python

web-flow
Merge 95c64b660 into f6f4be1e7

6 of 48 new or added lines in 4 files covered. (12.5%)

3 existing lines in 3 files now uncovered.

4857 of 13850 relevant lines covered (35.07%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.65
/tool_fraction_analysis/fraction_plot.py
1
import re
1✔
2
from qgis.PyQt.QtGui import QColor
1✔
3

4
import pyqtgraph as pg
1✔
5

6

7
pg.setConfigOption("background", "w")
1✔
8
pg.setConfigOption("foreground", "k")
1✔
9
from PyQt5.QtCore import Qt
1✔
10
from threedi_results_analysis.threedi_plugin_model import ThreeDiPluginModel
1✔
11
from threedi_results_analysis.tool_fraction_analysis.fraction_model import FractionModel
1✔
12

13

14
class FractionPlot(pg.PlotWidget):
1✔
15
    def __init__(self, parent, result_model: ThreeDiPluginModel, fraction_model: FractionModel):
1✔
16
        super().__init__(parent)
×
17
        self.showGrid(True, True, 0.5)
×
18
        self.fraction_model = fraction_model
×
19
        self.result_model = result_model
×
20
        self.item_map = {}
×
21
        self.setLabel("bottom", "Time", "hrs")
×
22
        self.setLabel("left", "Concentration", "")
×
23
        self.getAxis("left").enableAutoSIPrefix(False)
×
24

25
    def clear_plot(self):
1✔
26
        self.clear()
×
27
        self.item_map.clear()
×
28
        self.setLabel("left", "Concentration", "")
×
29

30
    def item_checked(self, model_item):
1✔
NEW
31
        if not self.item_map:  # No plots yet
×
NEW
32
            return
×
33
        substance = model_item.data()
×
34
        for plot in self.item_map[substance]:
×
35
            plot.setVisible(model_item.checkState() == Qt.Checked)
×
36

37
    def item_color_changed(self, color_model_item):
1✔
NEW
38
        if not self.item_map:  # No plots yet
×
NEW
39
            return
×
40

41
        # Retrieve the substance name from the model
NEW
42
        row = color_model_item.index().row()
×
NEW
43
        selected_model_item = color_model_item.model().item(row, 0)
×
NEW
44
        substance = selected_model_item.data()
×
45

NEW
46
        style, color = color_model_item.data()
×
NEW
47
        pen = pg.mkPen(color=QColor(*color), width=2, style=style)
×
NEW
48
        self.item_map[substance][0].setPen(pen)
×
49

NEW
50
        if len(self.item_map[substance]) == 2:
×
51
            # there is a fill, also change that color
NEW
52
            fill_color = self.reduce_saturation(QColor(*color))
×
NEW
53
            self.item_map[substance][1].setBrush(pg.mkBrush(fill_color))
×
54

55
    def fraction_selected(self, feature_id, substance_unit: str, time_unit: str, stacked: bool, volume: bool):
1✔
56
        """
57
        Retrieve info from model and create plots
58
        """
59
        self.clear_plot()
×
60

61
        substance_unit_conversion = 1.0
×
62

63
        if volume:
×
64
            # for known units, we apply basic conversion
65
            pattern = r"^(.*)/\s*(m3|l)\s*$"
×
66
            matches = re.findall(pattern, substance_unit, flags=re.IGNORECASE)
×
67
            if len(matches) == 1 and len(matches[0]) == 2:
×
68
                if matches[0][1].lower() == "l":
×
69
                    substance_unit_conversion = 1000.0
×
70
                    processed_substance_unit = matches[0][0].strip()
×
71
                    volume_label = "Load"
×
72
                elif matches[0][1].lower() == "m3":
×
73
                    substance_unit_conversion = 1.0
×
74
                    processed_substance_unit = matches[0][0].strip()
×
75
                    volume_label = "Load"
×
76
            elif substance_unit.strip() == "%":
×
77
                substance_unit_conversion = 1.0
×
78
                processed_substance_unit = "m<sup>3</sup>"
×
79
                volume_label = "Volume"
×
80
            else:  # unknown, take original unit as-is and append x m3
81
                substance_unit_conversion = 1.0
×
82
                processed_substance_unit = f"{substance_unit} ยท m<sup>3</sup>"
×
83
                volume_label = "Load"
×
84

85
        plots = self.fraction_model.create_plots(feature_id, time_unit, stacked, volume, substance_unit_conversion)
×
86
        prev_plot = None
×
NEW
87
        for substance, plot, visible in plots:
×
88
            self.item_map[substance] = [plot]
×
89
            plot.setZValue(100)
×
NEW
90
            plot.setVisible(visible)
×
UNCOV
91
            self.addItem(plot)
×
92

93
            if stacked:
×
94
                # Add fill between consecutive plots
95
                plot_color = plot.opts['pen'].color()
×
96
                # Reduce saturation for fill
97
                fill_color = self.reduce_saturation(plot_color)
×
98
                if not prev_plot:
×
99
                    # this is the first, just fill downward to axis
100
                    plot.setFillLevel(0)
×
101
                    plot.setFillBrush(pg.mkBrush(fill_color))
×
102
                else:
103
                    fill = pg.FillBetweenItem(plot, prev_plot, pg.mkBrush(fill_color))
×
104
                    fill.setZValue(20)
×
NEW
105
                    fill.setVisible(visible)
×
106
                    self.addItem(fill)
×
107
                    self.item_map[substance].append(fill)
×
108

109
            prev_plot = plot
×
110

111
        self.setLabel("left", volume_label if volume else "Concentration", processed_substance_unit if volume else substance_unit)
×
112
        self.plotItem.vb.menu.viewAll.triggered.emit()
×
113

114
    def reduce_saturation(self, plot_color):
1✔
115
        return QColor.fromHsvF(plot_color.hueF(), plot_color.saturationF()/2.0, plot_color.valueF())
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc