g3w-admin-qplotly 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. g3w_admin_qplotly-0.0.1.dist-info/METADATA +52 -0
  2. g3w_admin_qplotly-0.0.1.dist-info/RECORD +139 -0
  3. g3w_admin_qplotly-0.0.1.dist-info/WHEEL +5 -0
  4. g3w_admin_qplotly-0.0.1.dist-info/licenses/LICENSE +373 -0
  5. g3w_admin_qplotly-0.0.1.dist-info/top_level.txt +1 -0
  6. qplotly/__init__.py +1 -0
  7. qplotly/admin.py +34 -0
  8. qplotly/api/__init__.py +0 -0
  9. qplotly/api/plots/__init__.py +0 -0
  10. qplotly/api/plots/views.py +211 -0
  11. qplotly/api/widgets/__init__.py +0 -0
  12. qplotly/api/widgets/permissions.py +79 -0
  13. qplotly/api/widgets/serializers.py +109 -0
  14. qplotly/api/widgets/views.py +287 -0
  15. qplotly/apiurls.py +132 -0
  16. qplotly/apps.py +11 -0
  17. qplotly/locale/bg/LC_MESSAGES/django.mo +0 -0
  18. qplotly/locale/bg/LC_MESSAGES/django.po +162 -0
  19. qplotly/locale/de/LC_MESSAGES/django.mo +0 -0
  20. qplotly/locale/de/LC_MESSAGES/django.po +126 -0
  21. qplotly/locale/de/LC_MESSAGES/djangojs.mo +0 -0
  22. qplotly/locale/de/LC_MESSAGES/djangojs.po +221 -0
  23. qplotly/locale/es/LC_MESSAGES/django.mo +0 -0
  24. qplotly/locale/es/LC_MESSAGES/django.po +151 -0
  25. qplotly/locale/es/LC_MESSAGES/djangojs.mo +0 -0
  26. qplotly/locale/es/LC_MESSAGES/djangojs.po +232 -0
  27. qplotly/locale/fi/LC_MESSAGES/django.mo +0 -0
  28. qplotly/locale/fi/LC_MESSAGES/django.po +126 -0
  29. qplotly/locale/fi/LC_MESSAGES/djangojs.mo +0 -0
  30. qplotly/locale/fi/LC_MESSAGES/djangojs.po +222 -0
  31. qplotly/locale/fr/LC_MESSAGES/django.mo +0 -0
  32. qplotly/locale/fr/LC_MESSAGES/django.po +160 -0
  33. qplotly/locale/fr/LC_MESSAGES/djangojs.mo +0 -0
  34. qplotly/locale/fr/LC_MESSAGES/djangojs.po +222 -0
  35. qplotly/locale/it/LC_MESSAGES/django.mo +0 -0
  36. qplotly/locale/it/LC_MESSAGES/django.po +163 -0
  37. qplotly/locale/it/LC_MESSAGES/djangojs.mo +0 -0
  38. qplotly/locale/it/LC_MESSAGES/djangojs.po +220 -0
  39. qplotly/locale/pl/LC_MESSAGES/django.mo +0 -0
  40. qplotly/locale/pl/LC_MESSAGES/django.po +129 -0
  41. qplotly/locale/pl/LC_MESSAGES/djangojs.mo +0 -0
  42. qplotly/locale/pl/LC_MESSAGES/djangojs.po +217 -0
  43. qplotly/locale/pt/LC_MESSAGES/django.mo +0 -0
  44. qplotly/locale/pt/LC_MESSAGES/django.po +160 -0
  45. qplotly/locale/ro/LC_MESSAGES/django.mo +0 -0
  46. qplotly/locale/ro/LC_MESSAGES/django.po +128 -0
  47. qplotly/locale/ro/LC_MESSAGES/djangojs.mo +0 -0
  48. qplotly/locale/ro/LC_MESSAGES/djangojs.po +222 -0
  49. qplotly/locale/se/LC_MESSAGES/django.mo +0 -0
  50. qplotly/locale/se/LC_MESSAGES/django.po +126 -0
  51. qplotly/locale/se/LC_MESSAGES/djangojs.mo +0 -0
  52. qplotly/locale/se/LC_MESSAGES/djangojs.po +222 -0
  53. qplotly/migrations/0001_initial.py +26 -0
  54. qplotly/migrations/0002_qplotlywidget_type.py +18 -0
  55. qplotly/migrations/0003_auto_20200925_0838.py +18 -0
  56. qplotly/migrations/0004_auto_20200925_1535.py +25 -0
  57. qplotly/migrations/0005_qplotlywidget_show_on_start_client.py +18 -0
  58. qplotly/migrations/0006_alter_qplotlywidget_options_qplotlywidget_order.py +23 -0
  59. qplotly/migrations/0007_alter_qplotlywidget_options_and_more.py +22 -0
  60. qplotly/migrations/0008_alter_qplotlywidget_order.py +18 -0
  61. qplotly/migrations/0009_qplotlywidget_show_in_sidebar.py +18 -0
  62. qplotly/migrations/0010_remove_qplotlywidget_show_in_sidebar_and_more.py +22 -0
  63. qplotly/migrations/0011_rename_show_poistion_qplotlywidget_show_position.py +18 -0
  64. qplotly/migrations/0012_qplotlywidgetrelation_qplotlywidget_related_widgets.py +34 -0
  65. qplotly/migrations/0013_alter_qplotlywidgetrelation_source_and_more.py +24 -0
  66. qplotly/migrations/0014_alter_qplotlywidgetrelation_source_and_more.py +24 -0
  67. qplotly/migrations/0015_qplotlywidgetrelation_project.py +34 -0
  68. qplotly/migrations/0016_remove_qplotlywidget_project.py +17 -0
  69. qplotly/migrations/__init__.py +0 -0
  70. qplotly/models.py +142 -0
  71. qplotly/receivers.py +356 -0
  72. qplotly/requirements.txt +1 -0
  73. qplotly/server_filters/__init__.py +1 -0
  74. qplotly/server_filters/relations.py +32 -0
  75. qplotly/static/qplotly/icons/2dhistogram.svg +2048 -0
  76. qplotly/static/qplotly/icons/barplot.svg +2048 -0
  77. qplotly/static/qplotly/icons/boxplot.svg +2048 -0
  78. qplotly/static/qplotly/icons/contour.svg +2056 -0
  79. qplotly/static/qplotly/icons/histogram.svg +2048 -0
  80. qplotly/static/qplotly/icons/pie.svg +2048 -0
  81. qplotly/static/qplotly/icons/polar.svg +2055 -0
  82. qplotly/static/qplotly/icons/scatterplot.svg +2048 -0
  83. qplotly/static/qplotly/icons/scatterternary.svg +2055 -0
  84. qplotly/static/qplotly/icons/violin.svg +2878 -0
  85. qplotly/static/qplotly/js/data-widget-qplotlyWidgetList.js +373 -0
  86. qplotly/static/qplotly/js/i18n/bg.js +19 -0
  87. qplotly/static/qplotly/js/i18n/de.js +19 -0
  88. qplotly/static/qplotly/js/i18n/en.js +19 -0
  89. qplotly/static/qplotly/js/i18n/fi.js +19 -0
  90. qplotly/static/qplotly/js/i18n/fr.js +19 -0
  91. qplotly/static/qplotly/js/i18n/index.js +19 -0
  92. qplotly/static/qplotly/js/i18n/it.js +19 -0
  93. qplotly/static/qplotly/js/i18n/ro.js +19 -0
  94. qplotly/static/qplotly/js/i18n/se.js +19 -0
  95. qplotly/static/qplotly/js/i18n/uk.js +19 -0
  96. qplotly/static/qplotly/js/plugin.js +927 -0
  97. qplotly/static/qplotly/js/sidebar.js +373 -0
  98. qplotly/static/qplotly/js/widget.js +9 -0
  99. qplotly/static/qplotly/plotly-1.52.2.min.js +7 -0
  100. qplotly/static/qplotly/polyfill.min.js +3 -0
  101. qplotly/templates/qplotly/include/plot_type_icon.html +52 -0
  102. qplotly/templates/qplotly/layer_action.html +13 -0
  103. qplotly/templates/qplotly/plots_list_order.html +68 -0
  104. qplotly/templates/qplotly/plots_list_order_action.html +14 -0
  105. qplotly/templatetags/__init__.py +0 -0
  106. qplotly/templatetags/qplotly_tags.py +28 -0
  107. qplotly/urls.py +52 -0
  108. qplotly/utils/__init__.py +13 -0
  109. qplotly/utils/models.py +86 -0
  110. qplotly/utils/qplotly_factory.py +699 -0
  111. qplotly/utils/qplotly_settings.py +37 -0
  112. qplotly/vendor/DataPlotly/__init__.py +0 -0
  113. qplotly/vendor/DataPlotly/core/__init__.py +0 -0
  114. qplotly/vendor/DataPlotly/core/plot_factory.py +843 -0
  115. qplotly/vendor/DataPlotly/core/plot_settings.py +322 -0
  116. qplotly/vendor/DataPlotly/core/plot_types/__init__.py +20 -0
  117. qplotly/vendor/DataPlotly/core/plot_types/bar_plot.py +83 -0
  118. qplotly/vendor/DataPlotly/core/plot_types/box.py +56 -0
  119. qplotly/vendor/DataPlotly/core/plot_types/contour.py +43 -0
  120. qplotly/vendor/DataPlotly/core/plot_types/histogram.py +66 -0
  121. qplotly/vendor/DataPlotly/core/plot_types/histogram2d.py +39 -0
  122. qplotly/vendor/DataPlotly/core/plot_types/icons/2dhistogram.svg +2048 -0
  123. qplotly/vendor/DataPlotly/core/plot_types/icons/barplot.svg +2048 -0
  124. qplotly/vendor/DataPlotly/core/plot_types/icons/boxplot.svg +2048 -0
  125. qplotly/vendor/DataPlotly/core/plot_types/icons/contour.svg +2056 -0
  126. qplotly/vendor/DataPlotly/core/plot_types/icons/histogram.svg +2048 -0
  127. qplotly/vendor/DataPlotly/core/plot_types/icons/pie.svg +2048 -0
  128. qplotly/vendor/DataPlotly/core/plot_types/icons/polar.svg +2055 -0
  129. qplotly/vendor/DataPlotly/core/plot_types/icons/scatterplot.svg +2048 -0
  130. qplotly/vendor/DataPlotly/core/plot_types/icons/scatterternary.svg +2055 -0
  131. qplotly/vendor/DataPlotly/core/plot_types/icons/violin.svg +2878 -0
  132. qplotly/vendor/DataPlotly/core/plot_types/pie.py +60 -0
  133. qplotly/vendor/DataPlotly/core/plot_types/plot_type.py +170 -0
  134. qplotly/vendor/DataPlotly/core/plot_types/polar.py +63 -0
  135. qplotly/vendor/DataPlotly/core/plot_types/scatter.py +74 -0
  136. qplotly/vendor/DataPlotly/core/plot_types/ternary.py +129 -0
  137. qplotly/vendor/DataPlotly/core/plot_types/violin.py +62 -0
  138. qplotly/vendor/__init__.py +0 -0
  139. qplotly/views.py +148 -0
@@ -0,0 +1,322 @@
1
+ """Encapsulates settings for a plot
2
+
3
+ .. note:: This program is free software; you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation; either version 2 of the License, or
6
+ (at your option) any later version.
7
+ """
8
+
9
+ from copy import deepcopy
10
+ from qgis.PyQt.QtCore import QFile, QIODevice
11
+ from qgis.PyQt.QtXml import QDomDocument, QDomElement
12
+ from qgis.core import QgsXmlUtils, QgsPropertyCollection, QgsPropertyDefinition
13
+
14
+ def _pc_deepcopy(self, memo):
15
+ return QgsPropertyCollection(self)
16
+
17
+ QgsPropertyCollection.__deepcopy__ = _pc_deepcopy
18
+
19
+ class PlotSettings: # pylint: disable=too-many-instance-attributes
20
+ """
21
+ The PlotSettings class encapsulates all settings relating to a plot, and contains
22
+ methods for serializing and deserializing these settings.
23
+ """
24
+
25
+ PROPERTY_FILTER = 1
26
+ PROPERTY_MARKER_SIZE = 2
27
+ PROPERTY_COLOR = 3
28
+ PROPERTY_STROKE_COLOR = 4
29
+ PROPERTY_STROKE_WIDTH = 5
30
+ PROPERTY_X_MIN = 6
31
+ PROPERTY_X_MAX = 7
32
+ PROPERTY_Y_MIN = 8
33
+ PROPERTY_Y_MAX = 9
34
+ PROPERTY_TITLE = 10
35
+ PROPERTY_LEGEND_TITLE = 11
36
+ PROPERTY_X_TITLE = 12
37
+ PROPERTY_Y_TITLE = 13
38
+ PROPERTY_Z_TITLE = 14
39
+ PROPERTY_FONT_TITLE_SIZE = 15
40
+ PROPERTY_FONT_TITLE_FAMILY = 16
41
+ PROPERTY_FONT_TITLE_COLOR = 17
42
+ PROPERTY_FONT_XLABEL_SIZE = 18
43
+ PROPERTY_FONT_XLABEL_FAMILY = 19
44
+ PROPERTY_FONT_XLABEL_COLOR = 20
45
+ PROPERTY_FONT_XTICKS_SIZE = 21
46
+ PROPERTY_FONT_XTICKS_FAMILY = 22
47
+ PROPERTY_FONT_XTICKS_COLOR = 23
48
+ PROPERTY_FONT_YLABEL_SIZE = 24
49
+ PROPERTY_FONT_YLABEL_FAMILY = 25
50
+ PROPERTY_FONT_YLABEL_COLOR = 26
51
+ PROPERTY_FONT_YTICKS_SIZE = 27
52
+ PROPERTY_FONT_YTICKS_FAMILY = 28
53
+ PROPERTY_FONT_YTICKS_COLOR = 29
54
+
55
+ DYNAMIC_PROPERTIES = {
56
+ PROPERTY_FILTER: QgsPropertyDefinition('filter', 'Feature filter', QgsPropertyDefinition.Boolean),
57
+ PROPERTY_MARKER_SIZE: QgsPropertyDefinition('marker_size', 'Marker size', QgsPropertyDefinition.DoublePositive),
58
+ PROPERTY_COLOR: QgsPropertyDefinition('color', 'Color', QgsPropertyDefinition.ColorWithAlpha),
59
+ PROPERTY_STROKE_COLOR: QgsPropertyDefinition('stroke_color', 'Stroke color',
60
+ QgsPropertyDefinition.ColorWithAlpha),
61
+ PROPERTY_STROKE_WIDTH: QgsPropertyDefinition('stroke_width', 'Stroke width',
62
+ QgsPropertyDefinition.DoublePositive),
63
+ PROPERTY_TITLE: QgsPropertyDefinition('title', 'Plot title', QgsPropertyDefinition.String),
64
+ PROPERTY_LEGEND_TITLE: QgsPropertyDefinition('legend_title', 'Legend title', QgsPropertyDefinition.String),
65
+ PROPERTY_FONT_TITLE_SIZE: QgsPropertyDefinition('font_title_size', 'Font title size', QgsPropertyDefinition.String),
66
+ PROPERTY_FONT_TITLE_FAMILY: QgsPropertyDefinition('font_title_family', 'Font title family', QgsPropertyDefinition.String),
67
+ PROPERTY_FONT_TITLE_COLOR: QgsPropertyDefinition('font_title_color', 'Font title color', QgsPropertyDefinition.ColorWithAlpha),
68
+ PROPERTY_FONT_XLABEL_SIZE: QgsPropertyDefinition('font_xlabel_size', 'Font xlabel size', QgsPropertyDefinition.String),
69
+ PROPERTY_FONT_XLABEL_FAMILY: QgsPropertyDefinition('font_xlabel_family', 'Font xlabel family', QgsPropertyDefinition.String),
70
+ PROPERTY_FONT_XLABEL_COLOR: QgsPropertyDefinition('font_xlabel_color', 'Font xlabel color', QgsPropertyDefinition.ColorWithAlpha),
71
+ PROPERTY_FONT_XTICKS_SIZE: QgsPropertyDefinition('font_xticks_size', 'Font xticks size', QgsPropertyDefinition.String),
72
+ PROPERTY_FONT_XTICKS_FAMILY: QgsPropertyDefinition('font_xticks_family', 'Font xticks family', QgsPropertyDefinition.String),
73
+ PROPERTY_FONT_XTICKS_COLOR: QgsPropertyDefinition('font_xticks_color', 'Font xticks color', QgsPropertyDefinition.ColorWithAlpha),
74
+ PROPERTY_FONT_YLABEL_SIZE: QgsPropertyDefinition('font_ylabel_size', 'Font ylabel size', QgsPropertyDefinition.String),
75
+ PROPERTY_FONT_YLABEL_FAMILY: QgsPropertyDefinition('font_ylabel_family', 'Font ylabel family', QgsPropertyDefinition.String),
76
+ PROPERTY_FONT_YLABEL_COLOR: QgsPropertyDefinition('font_ylabel_color', 'Font ylabel color', QgsPropertyDefinition.ColorWithAlpha),
77
+ PROPERTY_FONT_YTICKS_SIZE: QgsPropertyDefinition('font_yticks_size', 'Font yticks size', QgsPropertyDefinition.String),
78
+ PROPERTY_FONT_YTICKS_FAMILY: QgsPropertyDefinition('font_yticks_family', 'Font yticks family', QgsPropertyDefinition.String),
79
+ PROPERTY_FONT_YTICKS_COLOR: QgsPropertyDefinition('font_yticks_color', 'Font yticks color', QgsPropertyDefinition.ColorWithAlpha),
80
+ PROPERTY_X_TITLE: QgsPropertyDefinition('x_title', 'X title', QgsPropertyDefinition.String),
81
+ PROPERTY_Y_TITLE: QgsPropertyDefinition('y_title', 'Y title', QgsPropertyDefinition.String),
82
+ PROPERTY_Z_TITLE: QgsPropertyDefinition('z_title', 'Z title', QgsPropertyDefinition.String),
83
+ PROPERTY_X_MIN: QgsPropertyDefinition('x_min', 'X axis minimum', QgsPropertyDefinition.Double),
84
+ PROPERTY_X_MAX: QgsPropertyDefinition('x_max', 'X axis maximum', QgsPropertyDefinition.Double),
85
+ PROPERTY_Y_MIN: QgsPropertyDefinition('y_min', 'Y axis minimum', QgsPropertyDefinition.Double),
86
+ PROPERTY_Y_MAX: QgsPropertyDefinition('y_max', 'Y axis maximum', QgsPropertyDefinition.Double)
87
+ }
88
+
89
+ # pylint: disable=too-many-arguments
90
+ def __init__(self, plot_type: str = 'scatter', properties: dict = None, layout: dict = None,
91
+ source_layer_id=None, dock_title: str = None, dock_id: str = None):
92
+ # Define default plot dictionary used as a basis for plot initialization
93
+ # prepare the default dictionary with None values
94
+ # plot properties
95
+ plot_base_properties = {
96
+ 'marker': 'markers',
97
+ 'custom': None,
98
+ 'hover_text': None,
99
+ 'additional_hover_text': None,
100
+ 'hover_label_text': None,
101
+ 'x_name': '',
102
+ 'y_name': '',
103
+ 'z_name': '',
104
+ 'in_color': '#8ebad9',
105
+ 'out_color': '#1f77b4',
106
+ 'marker_width': 1,
107
+ 'marker_size': 10,
108
+ 'marker_symbol': 0,
109
+ 'line_dash': 'solid',
110
+ 'box_orientation': 'v',
111
+ 'box_stat': None,
112
+ 'box_outliers': False,
113
+ 'name': '',
114
+ 'normalization': None,
115
+ 'cont_type': 'fill',
116
+ 'color_scale': None,
117
+ 'show_lines': False,
118
+ 'cumulative': False,
119
+ 'show_colorscale_legend': False,
120
+ 'invert_color_scale': False,
121
+ 'invert_hist': 'increasing',
122
+ 'bins': 0,
123
+ 'selected_features_only': False,
124
+ 'visible_features_only': False,
125
+ 'color_scale_data_defined_in_check': False,
126
+ 'color_scale_data_defined_in_invert_check': False,
127
+ 'marker_type_combo': 'Points',
128
+ 'point_combo': '',
129
+ 'line_combo': 'Solid Line',
130
+ 'contour_type_combo': 'Fill',
131
+ 'show_lines_check': False,
132
+ 'opacity': 1,
133
+ 'violin_side': None,
134
+ 'violin_box': False,
135
+ 'show_mean_line': False,
136
+ 'layout_filter_by_map': False,
137
+ 'layout_filter_by_atlas': False,
138
+ 'pie_hole': 0
139
+ }
140
+
141
+ # layout nested dictionary
142
+ plot_base_layout = {
143
+ 'title': 'Plot Title',
144
+ 'legend': True,
145
+ 'legend_title': None,
146
+ 'legend_orientation': 'h',
147
+ 'x_title': '',
148
+ 'y_title': '',
149
+ 'z_title': '',
150
+ 'font_title_size': 10,
151
+ 'font_title_family': "Arial",
152
+ 'font_title_color': "#000000",
153
+ 'font_xlabel_size': 10,
154
+ 'font_xlabel_family': "Arial",
155
+ 'font_xlabel_color': "#000000",
156
+ 'font_xticks_size': 10,
157
+ 'font_xticks_family': "Arial",
158
+ 'font_xticks_color': "#000000",
159
+ 'font_ylabel_size': 10,
160
+ 'font_ylabel_family': "Arial",
161
+ 'font_ylabel_color': "#000000",
162
+ 'font_yticks_size': 10,
163
+ 'font_yticks_family': "Arial",
164
+ 'font_yticks_color': "#000000",
165
+ 'xaxis': None,
166
+ 'bar_mode': None,
167
+ 'x_type': None,
168
+ 'y_type': None,
169
+ 'x_inv': None,
170
+ 'y_inv': None,
171
+ 'x_min': None,
172
+ 'x_max': None,
173
+ 'y_min': None,
174
+ 'y_max': None,
175
+ 'range_slider': {'borderwidth': 1, 'visible': False},
176
+ 'bargaps': 0,
177
+ 'polar': {'angularaxis': {'direction': 'clockwise'}},
178
+ 'additional_info_expression': '',
179
+ 'bins_check': False,
180
+ 'gridcolor': '#bdbfc0'
181
+ }
182
+
183
+ self.plot_base_dic = {
184
+ 'plot_type': None,
185
+ 'layer': None,
186
+ 'plot_prop': plot_base_properties,
187
+ 'layout_prop': plot_base_layout
188
+ }
189
+
190
+ self.data_defined_properties = QgsPropertyCollection()
191
+
192
+ # Set class properties - we use the base dictionaries, replacing base values with
193
+ # those from the passed properties dicts
194
+ if properties is None:
195
+ self.properties = plot_base_properties
196
+ else:
197
+ self.properties = {**plot_base_properties, **properties}
198
+ if layout is None:
199
+ self.layout = plot_base_layout
200
+ else:
201
+ self.layout = {**plot_base_layout, **layout}
202
+
203
+ self.plot_type = plot_type
204
+
205
+ self.x = []
206
+ self.y = []
207
+ self.z = []
208
+ self.feature_ids = []
209
+ self.additional_hover_text = []
210
+ self.data_defined_marker_sizes = []
211
+ self.data_defined_colors = []
212
+ self.data_defined_stroke_colors = []
213
+ self.data_defined_stroke_widths = []
214
+
215
+ # layout properties
216
+ self.data_defined_title = ""
217
+ self.data_defined_legend_title = ""
218
+ self.data_defined_x_title = ""
219
+ self.data_defined_y_title = ""
220
+ self.data_defined_z_title = ""
221
+ self.data_defined_x_min = None
222
+ self.data_defined_x_max = None
223
+ self.data_defined_y_min = None
224
+ self.data_defined_y_max = None
225
+ self.source_layer_id = source_layer_id
226
+
227
+ # multiple_dock
228
+ self.dock_title = dock_title
229
+ self.dock_id = dock_id
230
+
231
+ def write_xml(self, document: QDomDocument):
232
+ """
233
+ Writes the plot settings to an XML element
234
+ """
235
+ element = QgsXmlUtils.writeVariant({
236
+ 'plot_type': self.plot_type,
237
+ 'plot_properties': self.properties,
238
+ 'plot_layout': self.layout,
239
+ 'source_layer_id': self.source_layer_id,
240
+ 'dynamic_properties': self.data_defined_properties.toVariant(PlotSettings.DYNAMIC_PROPERTIES)
241
+ }, document)
242
+ return element
243
+
244
+ def read_xml(self, element: QDomElement) -> bool:
245
+ """
246
+ Reads the plot settings from an XML element
247
+ """
248
+ res = QgsXmlUtils.readVariant(element)
249
+ if not isinstance(res, dict) or \
250
+ 'plot_type' not in res or \
251
+ 'plot_properties' not in res or \
252
+ 'plot_layout' not in res:
253
+ return False
254
+
255
+ self.plot_type = res['plot_type']
256
+ self.properties = res['plot_properties']
257
+ self.layout = res['plot_layout']
258
+ self.source_layer_id = res.get('source_layer_id', None)
259
+ self.data_defined_properties.loadVariant(res.get('dynamic_properties', None), PlotSettings.DYNAMIC_PROPERTIES)
260
+
261
+ return True
262
+
263
+ def write_to_project(self, document: QDomDocument):
264
+ """
265
+ Writes the settings to a project (represented by the given DOM document)
266
+ """
267
+ elem = self.write_xml(document)
268
+ if self.dock_id == 'DataPlotly':
269
+ parent_elem = document.createElement('DataPlotly')
270
+ else:
271
+ parent_elem = document.createElement(f'DataPlotly_{self.dock_title}_{self.dock_id}')
272
+ parent_elem.appendChild(elem)
273
+
274
+ root_node = document.elementsByTagName("qgis").item(0)
275
+ root_node.appendChild(parent_elem)
276
+
277
+ def read_from_project(self, document: QDomDocument):
278
+ """
279
+ Reads the settings from a project (represented by the given DOM document)
280
+ """
281
+ root_node = document.elementsByTagName("qgis").item(0)
282
+ if root_node.isNull():
283
+ return False
284
+ if self.dock_id == 'DataPlotly':
285
+ tag = "DataPlotly"
286
+ else:
287
+ tag = f'DataPlotly_{self.dock_title}_{self.dock_id}'
288
+ node = root_node.toElement().firstChildElement(tag)
289
+ if node.isNull():
290
+ return False
291
+
292
+ elem = node.toElement()
293
+ return self.read_xml(elem.firstChildElement())
294
+
295
+ def write_to_file(self, file_name: str) -> bool:
296
+ """
297
+ Writes the settings to an XML file
298
+ """
299
+ document = QDomDocument("dataplotly")
300
+ elem = self.write_xml(document)
301
+ document.appendChild(elem)
302
+
303
+ try:
304
+ with open(file_name, "w", encoding="utf8") as f:
305
+ f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
306
+ f.write(document.toString())
307
+ return True
308
+ except FileNotFoundError:
309
+ return False
310
+
311
+ def read_from_file(self, file_name: str) -> bool:
312
+ """
313
+ Reads the settings from an XML file
314
+ """
315
+ f = QFile(file_name)
316
+ if f.open(QIODevice.ReadOnly):
317
+ document = QDomDocument()
318
+ if document.setContent(f):
319
+ if self.read_xml(document.firstChildElement()):
320
+ return True
321
+
322
+ return False
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Available plot types
4
+
5
+ .. note:: This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+ """
10
+
11
+ from .bar_plot import BarPlotFactory
12
+ from .box import BoxPlotFactory
13
+ from .contour import ContourFactory
14
+ from .histogram2d import Histogram2dFactory
15
+ from .histogram import HistogramFactory
16
+ from .pie import PieChartFactory
17
+ from .polar import PolarChartFactory
18
+ from .scatter import ScatterPlotFactory
19
+ from .ternary import TernaryFactory
20
+ from .violin import ViolinFactory
@@ -0,0 +1,83 @@
1
+ """
2
+ Bar plot
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+
10
+ import os
11
+ from plotly import graph_objs
12
+ from qgis.PyQt.QtGui import QIcon
13
+ from qplotly.vendor.DataPlotly.core.plot_types.plot_type import PlotType
14
+
15
+
16
+ class BarPlotFactory(PlotType):
17
+ """
18
+ Factory for bar plots
19
+ """
20
+
21
+ @staticmethod
22
+ def type_name():
23
+ return 'bar'
24
+
25
+ @staticmethod
26
+ def name():
27
+ return PlotType.tr('Bar Plot')
28
+
29
+ @staticmethod
30
+ def icon():
31
+ return QIcon(os.path.join(os.path.dirname(__file__), 'icons/barplot.svg'))
32
+
33
+ @staticmethod
34
+ def create_trace(settings):
35
+ # flip the variables according to the box orientation
36
+
37
+ if settings.properties['box_orientation'] == 'h':
38
+ y = settings.x
39
+ x = settings.y
40
+ else:
41
+ x = settings.x
42
+ y = settings.y
43
+
44
+ # tweak the width value
45
+ if settings.data_defined_marker_sizes:
46
+ width = settings.data_defined_marker_sizes
47
+ # set to None if 0.0 or Auto, useful especially for date/datetime data
48
+ elif settings.properties['marker_size'] == 0.0:
49
+ width = None
50
+ else:
51
+ width = settings.properties['marker_size']
52
+
53
+ return [graph_objs.Bar(
54
+ x=x,
55
+ y=y,
56
+ text=settings.additional_hover_text,
57
+ textposition=settings.properties.get('hover_label_position'),
58
+ name=settings.data_defined_legend_title if settings.data_defined_legend_title != '' else settings.properties['name'],
59
+ ids=settings.feature_ids,
60
+ customdata=settings.properties['custom'],
61
+ orientation=settings.properties['box_orientation'],
62
+ marker={'color': settings.data_defined_colors if settings.data_defined_colors else settings.properties['in_color'],
63
+ 'colorscale': settings.properties['color_scale'],
64
+ 'showscale': settings.properties['show_colorscale_legend'],
65
+ 'reversescale': settings.properties['invert_color_scale'],
66
+ 'colorbar': {
67
+ 'len': 0.8
68
+ },
69
+ 'line': {
70
+ 'color': settings.data_defined_stroke_colors if settings.data_defined_stroke_colors else settings.properties['out_color'],
71
+ 'width': settings.data_defined_stroke_widths if settings.data_defined_stroke_widths else settings.properties['marker_width']}
72
+ },
73
+ width=width,
74
+ opacity=settings.properties['opacity']
75
+ )]
76
+
77
+ @staticmethod
78
+ def create_layout(settings):
79
+ layout = super(BarPlotFactory, BarPlotFactory).create_layout(settings)
80
+
81
+ layout['barmode'] = settings.layout['bar_mode']
82
+
83
+ return layout
@@ -0,0 +1,56 @@
1
+ """
2
+ Box plot
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+
10
+ import os
11
+ from plotly import graph_objs
12
+ from qgis.PyQt.QtGui import QIcon
13
+ from qplotly.vendor.DataPlotly.core.plot_types.plot_type import PlotType
14
+
15
+
16
+ class BoxPlotFactory(PlotType):
17
+ """
18
+ Factory for box plots
19
+ """
20
+
21
+ @staticmethod
22
+ def type_name():
23
+ return 'box'
24
+
25
+ @staticmethod
26
+ def name():
27
+ return PlotType.tr('Box Plot')
28
+
29
+ @staticmethod
30
+ def icon():
31
+ return QIcon(os.path.join(os.path.dirname(__file__), 'icons/boxplot.svg'))
32
+
33
+ @staticmethod
34
+ def create_trace(settings):
35
+ # flip the variables according to the box orientation
36
+
37
+ if settings.properties['box_orientation'] == 'h':
38
+ y = settings.x
39
+ x = settings.y
40
+ else:
41
+ x = settings.x
42
+ y = settings.y
43
+
44
+ return [graph_objs.Box(
45
+ x=x or None,
46
+ y=y,
47
+ name=settings.data_defined_legend_title if settings.data_defined_legend_title != '' else settings.properties['name'],
48
+ customdata=settings.properties['custom'],
49
+ boxmean=settings.properties['box_stat'],
50
+ orientation=settings.properties['box_orientation'],
51
+ boxpoints=settings.properties['box_outliers'],
52
+ fillcolor=settings.data_defined_colors[0] if settings.data_defined_colors else settings.properties['in_color'],
53
+ line={'color': settings.data_defined_stroke_colors[0] if settings.data_defined_stroke_colors else settings.properties['out_color'],
54
+ 'width': settings.data_defined_stroke_widths[0] if settings.data_defined_stroke_widths else settings.properties['marker_width']},
55
+ opacity=settings.properties['opacity']
56
+ )]
@@ -0,0 +1,43 @@
1
+ """
2
+ Contour chart factory
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+
10
+ import os
11
+ from plotly import graph_objs
12
+ from qgis.PyQt.QtGui import QIcon
13
+ from qplotly.vendor.DataPlotly.core.plot_types.plot_type import PlotType
14
+
15
+
16
+ class ContourFactory(PlotType):
17
+ """
18
+ Factory for contour charts
19
+ """
20
+
21
+ @staticmethod
22
+ def type_name():
23
+ return 'contour'
24
+
25
+ @staticmethod
26
+ def name():
27
+ return PlotType.tr('Contour Plot')
28
+
29
+ @staticmethod
30
+ def icon():
31
+ return QIcon(os.path.join(os.path.dirname(__file__), 'icons/contour.svg'))
32
+
33
+ @staticmethod
34
+ def create_trace(settings):
35
+ return [graph_objs.Contour(
36
+ z=[settings.x, settings.y],
37
+ contours={
38
+ 'coloring': settings.properties['cont_type'],
39
+ 'showlines': settings.properties['show_lines']
40
+ },
41
+ colorscale=settings.properties['color_scale'],
42
+ opacity=settings.properties['opacity']
43
+ )]
@@ -0,0 +1,66 @@
1
+ """
2
+ Histogram factory
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+
10
+ import os
11
+ from plotly import graph_objs
12
+ from qgis.PyQt.QtGui import QIcon
13
+ from qplotly.vendor.DataPlotly.core.plot_types.plot_type import PlotType
14
+
15
+
16
+ class HistogramFactory(PlotType):
17
+ """
18
+ Factory for histogram plots
19
+ """
20
+
21
+ @staticmethod
22
+ def type_name():
23
+ return 'histogram'
24
+
25
+ @staticmethod
26
+ def name():
27
+ return PlotType.tr('Histogram')
28
+
29
+ @staticmethod
30
+ def icon():
31
+ return QIcon(os.path.join(os.path.dirname(__file__), 'icons/histogram.svg'))
32
+
33
+ @staticmethod
34
+ def create_trace(settings):
35
+ return [
36
+ graph_objs.Histogram(
37
+ x=settings.x,
38
+ y=settings.x,
39
+ name=settings.data_defined_legend_title if settings.data_defined_legend_title != '' else settings.properties['name'],
40
+ orientation=settings.properties['box_orientation'],
41
+ nbinsx=settings.properties['bins'],
42
+ nbinsy=settings.properties['bins'],
43
+ marker={
44
+ 'color': settings.data_defined_colors if settings.data_defined_colors else settings.properties['in_color'],
45
+ 'line': {
46
+ 'color': settings.data_defined_stroke_colors if settings.data_defined_stroke_colors else settings.properties['out_color'],
47
+ 'width': settings.data_defined_stroke_widths if settings.data_defined_stroke_widths else settings.properties['marker_width']
48
+ }
49
+ },
50
+ histnorm=settings.properties['normalization'],
51
+ opacity=settings.properties['opacity'],
52
+ cumulative={
53
+ 'enabled': settings.properties['cumulative'],
54
+ 'direction': settings.properties['invert_hist']
55
+ }
56
+ )
57
+ ]
58
+
59
+ @staticmethod
60
+ def create_layout(settings):
61
+ layout = super(HistogramFactory, HistogramFactory).create_layout(settings)
62
+
63
+ layout['barmode'] = settings.layout['bar_mode']
64
+ layout['bargroupgap'] = settings.layout['bargaps']
65
+
66
+ return layout
@@ -0,0 +1,39 @@
1
+ """
2
+ 2D histogram factory
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+
10
+ import os
11
+ from plotly import graph_objs
12
+ from qgis.PyQt.QtGui import QIcon
13
+ from qplotly.vendor.DataPlotly.core.plot_types.plot_type import PlotType
14
+
15
+
16
+ class Histogram2dFactory(PlotType):
17
+ """
18
+ Factory for 2D histograms
19
+ """
20
+
21
+ @staticmethod
22
+ def type_name():
23
+ return '2dhistogram'
24
+
25
+ @staticmethod
26
+ def name():
27
+ return PlotType.tr('2D Histogram')
28
+
29
+ @staticmethod
30
+ def icon():
31
+ return QIcon(os.path.join(os.path.dirname(__file__), 'icons/2dhistogram.svg'))
32
+
33
+ @staticmethod
34
+ def create_trace(settings):
35
+ return [graph_objs.Histogram2d(
36
+ x=settings.x,
37
+ y=settings.y,
38
+ colorscale=settings.properties['color_scale']
39
+ )]