From f08dfe018b25499fab72fa9274f092f150ad403b Mon Sep 17 00:00:00 2001 From: ghtmtt Date: Wed, 31 Aug 2022 18:06:11 +0200 Subject: [PATCH 1/3] sort bar plots option --- DataPlotly/core/plot_types/bar_plot.py | 2 + DataPlotly/gui/plot_settings_widget.py | 30 +- DataPlotly/ui/dataplotly_dockwidget_base.ui | 412 ++++++++++---------- 3 files changed, 240 insertions(+), 204 deletions(-) diff --git a/DataPlotly/core/plot_types/bar_plot.py b/DataPlotly/core/plot_types/bar_plot.py index 2e6db616..45350337 100644 --- a/DataPlotly/core/plot_types/bar_plot.py +++ b/DataPlotly/core/plot_types/bar_plot.py @@ -62,6 +62,7 @@ def create_trace(settings): 'color': settings.data_defined_stroke_colors if settings.data_defined_stroke_colors else settings.properties['out_color'], 'width': settings.data_defined_stroke_widths if settings.data_defined_stroke_widths else settings.properties['marker_width']} }, + width=settings.data_defined_marker_sizes if settings.data_defined_marker_sizes else settings.properties['marker_size'], opacity=settings.properties['opacity'] )] @@ -70,5 +71,6 @@ def create_layout(settings): layout = super(BarPlotFactory, BarPlotFactory).create_layout(settings) layout['barmode'] = settings.layout['bar_mode'] + layout['xaxis']['categoryorder'] = settings.layout['bar_sort'] return layout diff --git a/DataPlotly/gui/plot_settings_widget.py b/DataPlotly/gui/plot_settings_widget.py index 06c37c80..763bf53b 100644 --- a/DataPlotly/gui/plot_settings_widget.py +++ b/DataPlotly/gui/plot_settings_widget.py @@ -674,6 +674,16 @@ def refreshWidgets(self): # pylint: disable=too-many-statements,too-many-branch self.bar_mode_combo.addItem(self.tr('Stacked'), 'stack') self.bar_mode_combo.addItem(self.tr('Overlay'), 'overlay') + # BarPlot value sorting + self.bar_sort_combo.clear() + self.bar_sort_combo.addItem(self.tr('None'), 'trace') + self.bar_sort_combo.addItem(self.tr('Descending'), 'total descending') + self.bar_sort_combo.addItem(self.tr('Ascending'), 'total ascending') + self.bar_sort_combo.addItem(self.tr('Mean Ascending'), 'mean ascending') + self.bar_sort_combo.addItem(self.tr('Mean Descending'), 'mean descending') + self.bar_sort_combo.addItem(self.tr('Median Ascending'), 'median ascending') + self.bar_sort_combo.addItem(self.tr('Median Descending'), 'median descending') + # Histogram normalization mode self.hist_norm_combo.clear() self.hist_norm_combo.addItem(self.tr('Enumerated'), '') @@ -768,6 +778,16 @@ def refreshWidgets(self): # pylint: disable=too-many-statements,too-many-branch ), None, False ) + # change the label and the spin box value when the bar plot is chosen + if self.ptype == 'bar': + self.marker_size_lab.setText(self.tr('Bar width')) + self.marker_size.setValue(0.5) + + # change the label and the spin box value when the scatter plot is chosen + if self.ptype == 'scatter': + self.marker_size_lab.setText(self.tr('Marker size')) + self.marker_size.setValue(10) + # info combo for data hovering self.info_combo.clear() self.info_combo.addItem(self.tr('All Values'), 'all') @@ -813,9 +833,9 @@ def refreshWidgets(self): # pylint: disable=too-many-statements,too-many-branch self.marker_width_lab: ['scatter', 'bar', 'box', 'histogram', 'polar', 'ternary', 'violin'], self.marker_width: ['scatter', 'bar', 'box', 'histogram', 'polar', 'ternary', 'violin'], self.stroke_defined_button: ['scatter', 'bar', 'box', 'histogram', 'polar', 'ternary', 'violin'], - self.marker_size_lab: ['scatter', 'polar', 'ternary'], - self.marker_size: ['scatter', 'polar', 'ternary'], - self.size_defined_button: ['scatter', 'polar', 'ternary'], + self.marker_size_lab: ['scatter', 'polar', 'ternary', 'bar'], + self.marker_size: ['scatter', 'polar', 'ternary', 'bar'], + self.size_defined_button: ['scatter', 'polar', 'ternary', 'bar'], self.marker_type_lab: ['scatter', 'polar'], self.marker_type_combo: ['scatter', 'polar'], self.alpha_lab: ['scatter', 'bar', 'box', 'histogram', 'polar', 'ternary', 'violin', 'contour'], @@ -824,6 +844,8 @@ def refreshWidgets(self): # pylint: disable=too-many-statements,too-many-branch 'violin'], self.bar_mode_lab: ['bar', 'histogram'], self.bar_mode_combo: ['bar', 'histogram'], + self.bar_sort_label: ['bar'], + self.bar_sort_combo: ['bar'], self.legend_label: ['all'], self.legend_title: ['all'], self.legend_title_defined_button: ['all'], @@ -1096,6 +1118,7 @@ def get_settings(self) -> PlotSettings: # pylint: disable=R0915 'range_slider': {'visible': self.range_slider_combo.isChecked(), 'borderwidth': 1}, 'bar_mode': self.bar_mode_combo.currentData(), + 'bar_sort': self.bar_sort_combo.currentData(), 'x_type': self.x_axis_mode_combo.currentData(), 'y_type': self.y_axis_mode_combo.currentData(), 'x_inv': None if not self.invert_x_check.isChecked() else 'reversed', @@ -1223,6 +1246,7 @@ def set_settings(self, settings: PlotSettings): # pylint: disable=too-many-stat self.y_axis_max.setValue(settings.layout.get('y_max') if settings.layout.get('y_max', None) is not None else 0.0) self.orientation_combo.setCurrentIndex(self.orientation_combo.findData(settings.properties.get('box_orientation', 'v'))) self.bar_mode_combo.setCurrentIndex(self.bar_mode_combo.findData(settings.layout.get('bar_mode', None))) + self.bar_sort_combo.setCurrentIndex(self.bar_sort_combo.findData(settings.layout.get('bar_sort', None))) self.hist_norm_combo.setCurrentIndex(self.hist_norm_combo.findData(settings.properties.get('normalization', None))) self.box_statistic_combo.setCurrentIndex(self.box_statistic_combo.findData(settings.properties.get('box_stat', None))) self.outliers_combo.setCurrentIndex(self.outliers_combo.findData(settings.properties.get('box_outliers', None))) diff --git a/DataPlotly/ui/dataplotly_dockwidget_base.ui b/DataPlotly/ui/dataplotly_dockwidget_base.ui index 91ac9eba..dd526c67 100644 --- a/DataPlotly/ui/dataplotly_dockwidget_base.ui +++ b/DataPlotly/ui/dataplotly_dockwidget_base.ui @@ -320,7 +320,7 @@ QListWidget::item::selected { 0 - -270 + 0 673 989 @@ -883,8 +883,8 @@ QListWidget::item::selected { 0 0 - 414 - 583 + 673 + 789 @@ -915,63 +915,151 @@ QListWidget::item::selected { false - - - - true + + + + 1.000000000000000 + + + 0.100000000000000 - - + + + + + + + Z label + + + + + + + Additional hover label + + + + + + + + + + Grid color + + + + + - Set X Axis Bounds + Title and labels customization - true + false - + false - - - + + + - Minimum + Y ticks font - - + + - ... + Y label font - - + + - ... + X ticks font - - + + - Maximum + Title font - - + + + + X label font + + - - + + + + + + + QgsFontButton::ModeQFont + + + + + + + QgsFontButton::ModeQFont + + + + + + + QgsFontButton::ModeQFont + + + + + + + QgsFontButton::ModeQFont + + + + + + + + + + QgsFontButton::ModeQFont + + + + + + + + + + + - + + + + ... + + + + Set Y Axis Bounds @@ -1020,48 +1108,35 @@ QListWidget::item::selected { - - - - X label - - - - - - - - - - - - - ... + + + + true - - + + - Y label + Plot title - - + + ... - - + + - Invert Y axis + ... - + @@ -1082,10 +1157,31 @@ QListWidget::item::selected { - - + + + + + + + X label + + + + + + + Invert Y axis + + + + + + + Bar mode + + - + @@ -1106,10 +1202,13 @@ QListWidget::item::selected { - - + + + + + - ... + Y label @@ -1141,181 +1240,92 @@ QListWidget::item::selected { - - - - Bar mode - - - - - - - - - - 1.000000000000000 - - - 0.100000000000000 - - - - - - - - - - Grid color - - - - - - - Invert X axis - - - - - - - Bar gap - - - - - - - Plot title - - - - - - - Additional hover label - - - - - + + - Title and labels customization + Set X Axis Bounds - false - - true - - - - - Y ticks font - - - - - + + false + + + + - Y label font + Minimum - - + + - X ticks font + ... - - + + - Title font + ... - - + + - X label font - - - - - - - - - - QgsFontButton::ModeQFont - - - - - - - QgsFontButton::ModeQFont - - - - - - - QgsFontButton::ModeQFont - - - - - - - QgsFontButton::ModeQFont - - - - - - - - - - QgsFontButton::ModeQFont + Maximum - - - - - + + - - + + - - + + - - + + + + Bar gap + + + + + ... - - + + - Z label + Invert X axis + + + + + + + Sort values + + + + + + From bbddb7582b1f3fa1433c6f836348840971f16e57 Mon Sep 17 00:00:00 2001 From: ghtmtt Date: Wed, 31 Aug 2022 18:06:27 +0200 Subject: [PATCH 2/3] add the test for the option --- DataPlotly/test/test_data_plotly_dialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/DataPlotly/test/test_data_plotly_dialog.py b/DataPlotly/test/test_data_plotly_dialog.py index 39201b0e..3b89cd8b 100644 --- a/DataPlotly/test/test_data_plotly_dialog.py +++ b/DataPlotly/test/test_data_plotly_dialog.py @@ -144,6 +144,7 @@ def test_settings_round_trip(self): # pylint: disable=too-many-statements settings.layout['font_yticks_color'] = "#000000" settings.layout['range_slider']['visible'] = True settings.layout['bar_mode'] = 'overlay' + settings.layout['bar_sort'] = 'total ascending' settings.layout['x_type'] = 'log' settings.layout['y_type'] = 'category' settings.layout['x_inv'] = 'reversed' From d8bfe1488ea6129afd6df30b9d56e7b98731cc3d Mon Sep 17 00:00:00 2001 From: Matteo Ghetta Date: Wed, 31 Aug 2022 17:54:51 +0200 Subject: [PATCH 3/3] Bar width data defined (#304) * add bar width with custom data and standard value * update the attribute table of the test layer * restore label and marker size when the scatter plot is chosen --- DataPlotly/test/test_layer.dbf | Bin 3349 -> 3480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/DataPlotly/test/test_layer.dbf b/DataPlotly/test/test_layer.dbf index 1bb62bc6dc79b5439941e9f5807edd54a609cf1d..624b3522b4f2d8a745f60788e5e98eca5a58f5c4 100644 GIT binary patch delta 214 zcmbO#HA9-4xr#%clYxPOkuhx|_f?_t%#@N0AQuSyKm<3_#!H2a0tR}P1`2Rsk+NBk zlZkP%7jp=Ufu4!+=IP8yAT<^ia3u<6#b7m)*g^yh^$g7s5~fhi(d;2CKpCUWE7*aW p4fRY65o(N~Y6Q7JYK%=b$8kZ_7$ejeLe(7S@#TSv8UQVl0swY7DLeoG delta 111 zcmbOsJynXExtvRklYxQZAw%>;?yH*^lNnhR6cj9qHy3iUFitLK4%&Q$IT|cx1`=as oob19D2vTAS<*s56+|0%SQDO`d3uD}Ti3`Fvgc{?>>&++y03u@>xc~qF