Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar sorting options #305

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DataPlotly/core/plot_types/bar_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)]

Expand All @@ -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
30 changes: 27 additions & 3 deletions DataPlotly/gui/plot_settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)))
Expand Down
1 change: 1 addition & 0 deletions DataPlotly/test/test_data_plotly_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file modified DataPlotly/test/test_layer.dbf
Binary file not shown.
Loading