def do_render(self, model: Dazzle.GraphModel, x_begin: int, x_end: int, y_begin: float, y_end: float, cairo_context: cairo.Context, area: cairo.RectangleInt) -> None: model_iter = Dazzle.GraphModelIter() cairo_context.save() if model.get_iter_first(model_iter): chunk = area.width / (model.props.max_samples - 1) / 2.0 last_x = self._calc_x(model_iter, x_begin, x_end, area.width) last_y = float(area.height) cairo_context.move_to(last_x, area.height) while Dazzle.GraphModel.iter_next(model_iter): x = self._calc_x(model_iter, x_begin, x_end, area.width) y = self._calc_y(model_iter, y_begin, y_end, area.height, self._column) cairo_context.curve_to(last_x + chunk, last_y, last_x + chunk, y, x, y) last_x = x last_y = y cairo_context.set_line_width(self._line_width) cairo_context.set_source_rgba(self._stacked_color_rgba.red, self._stacked_color_rgba.green, self._stacked_color_rgba.blue, self._stacked_color_rgba.alpha) cairo_context.rel_line_to(0, area.height) cairo_context.stroke_preserve() cairo_context.close_path() cairo_context.fill() if model.get_iter_first(model_iter): chunk = area.width / (model.props.max_samples - 1) / 2.0 last_x = self._calc_x(model_iter, x_begin, x_end, area.width) last_y = float(area.height) cairo_context.move_to(last_x, last_y) while Dazzle.GraphModel.iter_next(model_iter): x = self._calc_x(model_iter, x_begin, x_end, area.width) y = self._calc_y(model_iter, y_begin, y_end, area.height, self._column) cairo_context.curve_to(last_x + chunk, last_y, last_x + chunk, y, x, y) last_x = x last_y = y cairo_context.set_source_rgba(self._stroke_color_rgba.red, self._stroke_color_rgba.green, self._stroke_color_rgba.blue, self._stacked_color_rgba.alpha) cairo_context.stroke() cairo_context.restore()
def refresh_graphs(self, data_dict: Dict[GraphType, Tuple[int, float, str, float, float]]) -> None: time1 = time.time() for graph_type, data_tuple in data_dict.items(): max_value = self._graph_models[graph_type].props.value_max self._graph_models[graph_type].props.value_max = max(data_tuple[4], max_value) graph_model_iter = self._graph_models[graph_type].push(GLib.get_monotonic_time()) self._graph_models[graph_type].iter_set(graph_model_iter, 0, data_tuple[1]) self._graph_views[graph_type][2].set_text(f"{data_tuple[1]:.0f} {data_tuple[2]}") model_iter = Dazzle.GraphModelIter() if self._dialog.props.visible and self._graph_models[graph_type].get_iter_first(model_iter): min_value = data_tuple[4] * 10 max_value = data_tuple[3] while Dazzle.GraphModel.iter_next(iter=model_iter): gval = GObject.Value() Dazzle.GraphModel.iter_get_value(iter=model_iter, column=0, value=gval) val = gval.get_double() min_value = min(val, min_value) max_value = max(val, max_value) self._graph_views[graph_type][0].set_text(f"{min_value:.0f}") self._graph_views[graph_type][1].set_text(f"{max_value:.0f}") self._graph_models[graph_type].props.value_max = max(data_tuple[4], max_value) time2 = time.time() LOG.debug(f'Refresh graph took {((time2 - time1) * 1000.0):.3f} ms')