layrz-sdk 3.0.14__py3-none-any.whl → 3.1.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.

Potentially problematic release.


This version of layrz-sdk might be problematic. Click here for more details.

Files changed (123) hide show
  1. layrz_sdk/__init__.py +1 -1
  2. layrz_sdk/constants.py +5 -0
  3. layrz_sdk/entities/__init__.py +129 -73
  4. layrz_sdk/entities/asset.py +71 -0
  5. layrz_sdk/entities/{general/asset_operation_mode.py → asset_operation_mode.py} +31 -30
  6. layrz_sdk/entities/broadcast_request.py +12 -0
  7. layrz_sdk/entities/broadcast_response.py +12 -0
  8. layrz_sdk/entities/broadcast_result.py +20 -0
  9. layrz_sdk/entities/{broadcasts/status.py → broadcast_status.py} +28 -27
  10. layrz_sdk/entities/case.py +47 -0
  11. layrz_sdk/entities/case_ignored_status.py +26 -0
  12. layrz_sdk/entities/case_status.py +23 -0
  13. layrz_sdk/entities/charts/axis_config.py +15 -0
  14. layrz_sdk/entities/charts/{bar.py → bar_chart.py} +171 -208
  15. layrz_sdk/entities/charts/chart_alignment.py +27 -0
  16. layrz_sdk/entities/charts/chart_color.py +44 -0
  17. layrz_sdk/entities/charts/chart_configuration.py +10 -0
  18. layrz_sdk/entities/charts/chart_data_serie.py +19 -0
  19. layrz_sdk/entities/charts/chart_data_serie_type.py +28 -0
  20. layrz_sdk/entities/charts/chart_data_type.py +27 -0
  21. layrz_sdk/entities/charts/{render_technology.py → chart_render_technology.py} +30 -29
  22. layrz_sdk/entities/charts/{column.py → column_chart.py} +197 -236
  23. layrz_sdk/entities/charts/html_chart.py +34 -0
  24. layrz_sdk/entities/charts/{line.py → line_chart.py} +244 -282
  25. layrz_sdk/entities/charts/map_center_type.py +22 -0
  26. layrz_sdk/entities/charts/map_chart.py +104 -0
  27. layrz_sdk/entities/charts/map_point.py +22 -0
  28. layrz_sdk/entities/charts/number_chart.py +50 -0
  29. layrz_sdk/entities/charts/{pie.py → pie_chart.py} +127 -148
  30. layrz_sdk/entities/charts/radar_chart.py +77 -0
  31. layrz_sdk/entities/charts/{radial_bar.py → radial_bar_chart.py} +127 -148
  32. layrz_sdk/entities/charts/{scatter.py → scatter_chart.py} +206 -290
  33. layrz_sdk/entities/charts/scatter_serie.py +15 -0
  34. layrz_sdk/entities/charts/scatter_serie_item.py +8 -0
  35. layrz_sdk/entities/charts/table_chart.py +50 -0
  36. layrz_sdk/entities/charts/table_header.py +8 -0
  37. layrz_sdk/entities/charts/table_row.py +9 -0
  38. layrz_sdk/entities/charts/timeline_chart.py +75 -0
  39. layrz_sdk/entities/charts/timeline_serie.py +12 -0
  40. layrz_sdk/entities/charts/timeline_serie_item.py +12 -0
  41. layrz_sdk/entities/checkpoint.py +18 -0
  42. layrz_sdk/entities/comment.py +16 -0
  43. layrz_sdk/entities/custom_field.py +10 -0
  44. layrz_sdk/entities/custom_report_page.py +16 -0
  45. layrz_sdk/entities/device.py +13 -0
  46. layrz_sdk/entities/event.py +23 -0
  47. layrz_sdk/entities/geofence.py +11 -0
  48. layrz_sdk/entities/last_message.py +12 -0
  49. layrz_sdk/entities/message.py +23 -0
  50. layrz_sdk/entities/outbound_service.py +10 -0
  51. layrz_sdk/entities/position.py +101 -0
  52. layrz_sdk/entities/presence_type.py +16 -0
  53. layrz_sdk/entities/{reports/report.py → report.py} +257 -286
  54. layrz_sdk/entities/report_col.py +40 -0
  55. layrz_sdk/entities/report_configuration.py +8 -0
  56. layrz_sdk/entities/report_data_type.py +28 -0
  57. layrz_sdk/entities/{reports/format.py → report_format.py} +27 -26
  58. layrz_sdk/entities/report_header.py +43 -0
  59. layrz_sdk/entities/report_page.py +17 -0
  60. layrz_sdk/entities/report_row.py +28 -0
  61. layrz_sdk/entities/sensor.py +11 -0
  62. layrz_sdk/entities/{formatting/text_align.py → text_alignment.py} +26 -25
  63. layrz_sdk/entities/trigger.py +11 -0
  64. layrz_sdk/entities/user.py +10 -0
  65. layrz_sdk/entities/waypoint.py +18 -0
  66. layrz_sdk/helpers/__init__.py +8 -2
  67. layrz_sdk/helpers/color.py +41 -45
  68. layrz_sdk/lcl/__init__.py +7 -2
  69. layrz_sdk/lcl/core.py +832 -820
  70. layrz_sdk/py.typed +0 -0
  71. {layrz_sdk-3.0.14.dist-info → layrz_sdk-3.1.1.dist-info}/LICENSE +6 -6
  72. {layrz_sdk-3.0.14.dist-info → layrz_sdk-3.1.1.dist-info}/METADATA +48 -45
  73. layrz_sdk-3.1.1.dist-info/RECORD +75 -0
  74. {layrz_sdk-3.0.14.dist-info → layrz_sdk-3.1.1.dist-info}/WHEEL +1 -1
  75. layrz_sdk/entities/broadcasts/__init__.py +0 -6
  76. layrz_sdk/entities/broadcasts/request.py +0 -30
  77. layrz_sdk/entities/broadcasts/response.py +0 -30
  78. layrz_sdk/entities/broadcasts/result.py +0 -53
  79. layrz_sdk/entities/broadcasts/service.py +0 -28
  80. layrz_sdk/entities/cases/__init__.py +0 -4
  81. layrz_sdk/entities/cases/case.py +0 -120
  82. layrz_sdk/entities/cases/comment.py +0 -37
  83. layrz_sdk/entities/cases/trigger.py +0 -31
  84. layrz_sdk/entities/charts/__init__.py +0 -21
  85. layrz_sdk/entities/charts/alignment.py +0 -26
  86. layrz_sdk/entities/charts/color.py +0 -38
  87. layrz_sdk/entities/charts/configuration.py +0 -54
  88. layrz_sdk/entities/charts/data_type.py +0 -26
  89. layrz_sdk/entities/charts/exceptions.py +0 -29
  90. layrz_sdk/entities/charts/html.py +0 -44
  91. layrz_sdk/entities/charts/map.py +0 -179
  92. layrz_sdk/entities/charts/number.py +0 -52
  93. layrz_sdk/entities/charts/radar.py +0 -102
  94. layrz_sdk/entities/charts/serie.py +0 -56
  95. layrz_sdk/entities/charts/serie_type.py +0 -27
  96. layrz_sdk/entities/charts/table.py +0 -74
  97. layrz_sdk/entities/charts/timeline.py +0 -148
  98. layrz_sdk/entities/checkpoints/__init__.py +0 -4
  99. layrz_sdk/entities/checkpoints/checkpoint.py +0 -50
  100. layrz_sdk/entities/checkpoints/waypoint.py +0 -52
  101. layrz_sdk/entities/events/__init__.py +0 -2
  102. layrz_sdk/entities/events/event.py +0 -58
  103. layrz_sdk/entities/formatting/__init__.py +0 -2
  104. layrz_sdk/entities/general/__init__.py +0 -9
  105. layrz_sdk/entities/general/asset.py +0 -72
  106. layrz_sdk/entities/general/custom_field.py +0 -29
  107. layrz_sdk/entities/general/device.py +0 -45
  108. layrz_sdk/entities/general/geofence.py +0 -53
  109. layrz_sdk/entities/general/sensor.py +0 -31
  110. layrz_sdk/entities/general/user.py +0 -29
  111. layrz_sdk/entities/repcom/__init__.py +0 -2
  112. layrz_sdk/entities/repcom/transaction.py +0 -54
  113. layrz_sdk/entities/reports/__init__.py +0 -7
  114. layrz_sdk/entities/reports/col.py +0 -86
  115. layrz_sdk/entities/reports/header.py +0 -57
  116. layrz_sdk/entities/reports/page.py +0 -64
  117. layrz_sdk/entities/reports/row.py +0 -43
  118. layrz_sdk/entities/telemetry/__init__.py +0 -5
  119. layrz_sdk/entities/telemetry/last_message.py +0 -41
  120. layrz_sdk/entities/telemetry/message.py +0 -37
  121. layrz_sdk/entities/telemetry/position.py +0 -51
  122. layrz_sdk-3.0.14.dist-info/RECORD +0 -70
  123. {layrz_sdk-3.0.14.dist-info → layrz_sdk-3.1.1.dist-info}/top_level.txt +0 -0
@@ -1,290 +1,206 @@
1
- """Scatter chart"""
2
-
3
- from typing import Any, List
4
-
5
- from .alignment import ChartAlignment
6
- from .configuration import AxisConfig
7
- from .exceptions import ChartException
8
- from .render_technology import ChartRenderTechnology
9
- from .serie_type import ChartDataSerieType
10
-
11
-
12
- class ScatterSerieItem:
13
- """
14
- Chart Data Serie Item for Scatter Charts
15
- """
16
-
17
- def __init__(self, x: float, y: float) -> None:
18
- """
19
- Constructor
20
-
21
- Args
22
- ----
23
- x : X value of the item.
24
- y : Y value of the item.
25
- """
26
- self.x = x
27
- self.y = y
28
-
29
-
30
- class ScatterSerie:
31
- """
32
- Chart Data Serie for Timeline charts
33
- """
34
-
35
- def __init__(
36
- self,
37
- data: List[ScatterSerieItem],
38
- color: str,
39
- label: str,
40
- serie_type: ChartDataSerieType = ChartDataSerieType.SCATTER,
41
- ) -> None:
42
- """
43
- Constructor
44
- ----
45
- Arguments
46
- data : List of data points.
47
- color : Color of the serie.
48
- label : Label of the serie.
49
- """
50
- for i, datum in enumerate(data):
51
- if not isinstance(datum, ScatterSerieItem):
52
- raise ChartException(f'Y Axis serie {i} must be an instance of ChartDataSerie')
53
- self.data = data
54
-
55
- if not isinstance(color, str):
56
- raise ChartException('color must be an instance of str')
57
- self.color = color
58
-
59
- if not isinstance(label, str):
60
- raise ChartException('label must be an instance of str')
61
- self.label = label
62
-
63
- if not isinstance(serie_type, ChartDataSerieType):
64
- raise ChartException('serie_type must be an instance of ChartDataSerieType')
65
- self.serie_type = serie_type
66
-
67
-
68
- class ScatterChart:
69
- """
70
- Scatter chart configuration
71
- """
72
-
73
- def __init__(
74
- self,
75
- series: List[ScatterSerie],
76
- title: str = 'Chart',
77
- align: ChartAlignment = ChartAlignment.CENTER,
78
- x_axis_config: AxisConfig = None,
79
- y_axis_config: AxisConfig = None,
80
- ) -> None:
81
- """
82
- Constructor
83
- ----
84
- Arguments
85
- series : Defines the series of the chart, uses the ScatterSerie class.
86
- Please read the documentation to more information.
87
- title : Title of the chart.
88
- align : Alignment of the chart.
89
- """
90
- for i, serie in enumerate(series):
91
- if not isinstance(serie, ScatterSerie):
92
- raise ChartException(f'Y Axis serie {i} must be an instance of ScatterSerie')
93
- self.series = series
94
-
95
- if not isinstance(title, str):
96
- raise ChartException('title must be an instance of str')
97
- self.title = title
98
-
99
- if not isinstance(align, ChartAlignment):
100
- raise ChartException('align must be an instance of ChartAlignment')
101
- self.align = align
102
-
103
- if x_axis_config is None:
104
- x_axis_config = AxisConfig(label='', measure_unit='')
105
-
106
- if not isinstance(x_axis_config, AxisConfig):
107
- raise ChartException('x_axis_config must be an instance of AxisConfig')
108
- self.x_axis_config = x_axis_config
109
-
110
- if y_axis_config is None:
111
- y_axis_config = AxisConfig(label='', measure_unit='')
112
-
113
- if not isinstance(y_axis_config, AxisConfig):
114
- raise ChartException('y_axis_config must be an instance of AxisConfig')
115
- self.y_axis_config = y_axis_config
116
-
117
- def render(
118
- self,
119
- technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS,
120
- ) -> Any:
121
- """
122
- Render chart to a graphic Library.
123
- We have two graphic libraries: GRAPHIC and APEXCHARTS.
124
-
125
- GRAPHIC is a Flutter chart library. To return this option, use the parameter use_new_definition=True.
126
- APEXCHARTS is a Javascript chart library. This is the default option.
127
- """
128
- if technology == ChartRenderTechnology.GRAPHIC:
129
- return {
130
- 'library': 'GRAPHIC',
131
- 'chart': 'SCATTER',
132
- 'configuration': self._render_graphic(),
133
- }
134
-
135
- if technology == ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS:
136
- return {
137
- 'library': 'SYNCFUSION_FLUTTER_CHARTS',
138
- 'chart': 'SCATTER',
139
- 'configuration': self._render_syncfusion_flutter_charts(),
140
- }
141
-
142
- if technology == ChartRenderTechnology.APEX_CHARTS:
143
- return {
144
- 'library': 'APEXCHARTS',
145
- 'chart': 'SCATTER',
146
- 'configuration': self._render_apexcharts(),
147
- }
148
-
149
- return {
150
- 'library': 'FLUTTER',
151
- 'chart': 'TEXT',
152
- 'configuration': [f'Unsupported {technology}'],
153
- }
154
-
155
- def _render_syncfusion_flutter_charts(self) -> Any:
156
- """
157
- Converts the configuration of the chart to Flutter library Graphic.
158
- """
159
- series = []
160
- for serie in self.series:
161
- data = []
162
-
163
- type_serie = 'SCATTER'
164
- if serie.serie_type == ChartDataSerieType.SCATTER:
165
- type_serie = 'SCATTER'
166
- elif serie.serie_type == ChartDataSerieType.LINE:
167
- type_serie = 'LINE'
168
- elif serie.serie_type == ChartDataSerieType.AREA:
169
- type_serie = 'AREA'
170
- else:
171
- continue
172
-
173
- for item in serie.data:
174
- if not isinstance(item.x, (int, float)):
175
- continue
176
- if not isinstance(item.y, (int, float)):
177
- continue
178
-
179
- data.append(
180
- {
181
- 'xAxis': item.x,
182
- 'yAxis': item.y,
183
- }
184
- )
185
-
186
- series.append(
187
- {
188
- 'label': serie.label,
189
- 'color': serie.color,
190
- 'values': data,
191
- 'type': type_serie,
192
- }
193
- )
194
-
195
- return {
196
- 'series': series,
197
- 'xAxis': {
198
- 'label': self.x_axis_config.label,
199
- 'measureUnit': self.x_axis_config.measure_unit,
200
- 'dataType': self.x_axis_config.data_type.value,
201
- 'minValue': self.x_axis_config.min_value,
202
- 'maxValue': self.x_axis_config.max_value,
203
- },
204
- 'yAxis': {
205
- 'label': self.y_axis_config.label,
206
- 'measureUnit': self.y_axis_config.measure_unit,
207
- 'dataType': self.y_axis_config.data_type.value,
208
- 'minValue': self.y_axis_config.min_value,
209
- 'maxValue': self.y_axis_config.max_value,
210
- },
211
- }
212
-
213
- def _render_graphic(self) -> Any:
214
- """
215
- Converts the configuration of the chart to Flutter library Graphic.
216
- """
217
- series = []
218
- for serie in self.series:
219
- data = []
220
-
221
- type_serie = 'SCATTER'
222
- if serie.serie_type == ChartDataSerieType.SCATTER:
223
- type_serie = 'SCATTER'
224
- elif serie.serie_type == ChartDataSerieType.LINE:
225
- type_serie = 'LINE'
226
- elif serie.serie_type == ChartDataSerieType.AREA:
227
- type_serie = 'AREA'
228
- else:
229
- continue
230
-
231
- for item in serie.data:
232
- data.append(
233
- {
234
- 'x_axis': item.x,
235
- 'y_axis': item.y,
236
- }
237
- )
238
-
239
- series.append(
240
- {
241
- 'group': serie.label,
242
- 'color': serie.color,
243
- 'values': data,
244
- 'type': type_serie,
245
- }
246
- )
247
-
248
- return series
249
-
250
- def _render_apexcharts(self) -> Any:
251
- """
252
- Converts the configuration of the chart to Javascript library ApexCharts.
253
- """
254
-
255
- series = []
256
- colors = []
257
-
258
- for serie in self.series:
259
- data = []
260
-
261
- for item in serie.data:
262
- data.append([item.x, item.y])
263
-
264
- series.append(
265
- {
266
- 'name': serie.label,
267
- 'data': data,
268
- 'type': serie.serie_type.value,
269
- }
270
- )
271
- colors.append(serie.color)
272
-
273
- config = {
274
- 'series': series,
275
- 'colors': colors,
276
- 'title': {
277
- 'text': self.title,
278
- 'align': self.align.value,
279
- 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'},
280
- },
281
- 'chart': {
282
- 'type': 'scatter',
283
- 'animations': {'enabled': False},
284
- 'toolbar': {'show': False},
285
- 'zoom': {'enabled': False},
286
- },
287
- 'dataLabels': {'enabled': True},
288
- }
289
-
290
- return config
1
+ """Scatter chart"""
2
+
3
+ import sys
4
+ from typing import Any, Dict, List
5
+
6
+ from pydantic import BaseModel, Field
7
+
8
+ from .axis_config import AxisConfig
9
+ from .chart_alignment import ChartAlignment
10
+ from .chart_data_serie_type import ChartDataSerieType
11
+ from .chart_render_technology import ChartRenderTechnology
12
+ from .scatter_serie import ScatterSerie
13
+
14
+ if sys.version_info >= (3, 11):
15
+ from typing import Self
16
+ else:
17
+ from typing_extensions import Self
18
+
19
+
20
+ class ScatterChart(BaseModel):
21
+ """Scatter chart configuration"""
22
+
23
+ series: List[ScatterSerie] = Field(description='List of series to be displayed in the chart', default_factory=list)
24
+ title: str = Field(description='Title of the chart', default='Chart')
25
+ align: ChartAlignment = Field(description='Alignment of the chart', default=ChartAlignment.CENTER)
26
+ x_axis_config: AxisConfig = Field(
27
+ default_factory=lambda: AxisConfig(),
28
+ description='Configuration of the X Axis',
29
+ )
30
+ y_axis_config: AxisConfig = Field(
31
+ default_factory=lambda: AxisConfig(),
32
+ description='Configuration of the Y Axis',
33
+ )
34
+
35
+ def render(
36
+ self: Self,
37
+ technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS,
38
+ ) -> Dict[str, Any]:
39
+ """
40
+ Render chart to a graphic Library.
41
+ :param technology: The technology to use to render the chart.
42
+ :return: The configuration of the chart.
43
+ """
44
+ if technology == ChartRenderTechnology.GRAPHIC:
45
+ return {
46
+ 'library': 'GRAPHIC',
47
+ 'chart': 'SCATTER',
48
+ 'configuration': self._render_graphic(),
49
+ }
50
+
51
+ if technology == ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS:
52
+ return {
53
+ 'library': 'SYNCFUSION_FLUTTER_CHARTS',
54
+ 'chart': 'SCATTER',
55
+ 'configuration': self._render_syncfusion_flutter_charts(),
56
+ }
57
+
58
+ if technology == ChartRenderTechnology.APEX_CHARTS:
59
+ return {
60
+ 'library': 'APEXCHARTS',
61
+ 'chart': 'SCATTER',
62
+ 'configuration': self._render_apexcharts(),
63
+ }
64
+
65
+ return {
66
+ 'library': 'FLUTTER',
67
+ 'chart': 'TEXT',
68
+ 'configuration': [f'Unsupported {technology}'],
69
+ }
70
+
71
+ def _render_syncfusion_flutter_charts(self: Self) -> Dict[str, Any]:
72
+ """
73
+ Converts the configuration of the chart to Flutter library Graphic.
74
+ """
75
+ series = []
76
+ for serie in self.series:
77
+ data = []
78
+
79
+ type_serie = 'SCATTER'
80
+ if serie.serie_type == ChartDataSerieType.SCATTER:
81
+ type_serie = 'SCATTER'
82
+ elif serie.serie_type == ChartDataSerieType.LINE:
83
+ type_serie = 'LINE'
84
+ elif serie.serie_type == ChartDataSerieType.AREA:
85
+ type_serie = 'AREA'
86
+ else:
87
+ continue
88
+
89
+ for item in serie.data:
90
+ if not isinstance(item.x, (int, float)):
91
+ continue
92
+ if not isinstance(item.y, (int, float)):
93
+ continue
94
+
95
+ data.append(
96
+ {
97
+ 'xAxis': item.x,
98
+ 'yAxis': item.y,
99
+ }
100
+ )
101
+
102
+ series.append(
103
+ {
104
+ 'label': serie.label,
105
+ 'color': serie.color,
106
+ 'values': data,
107
+ 'type': type_serie,
108
+ }
109
+ )
110
+
111
+ return {
112
+ 'series': series,
113
+ 'xAxis': {
114
+ 'label': self.x_axis_config.label,
115
+ 'measureUnit': self.x_axis_config.measure_unit,
116
+ 'dataType': self.x_axis_config.data_type.value,
117
+ 'minValue': self.x_axis_config.min_value,
118
+ 'maxValue': self.x_axis_config.max_value,
119
+ },
120
+ 'yAxis': {
121
+ 'label': self.y_axis_config.label,
122
+ 'measureUnit': self.y_axis_config.measure_unit,
123
+ 'dataType': self.y_axis_config.data_type.value,
124
+ 'minValue': self.y_axis_config.min_value,
125
+ 'maxValue': self.y_axis_config.max_value,
126
+ },
127
+ }
128
+
129
+ def _render_graphic(self: Self) -> List[Dict[str, Any]]:
130
+ """
131
+ Converts the configuration of the chart to Flutter library Graphic.
132
+ """
133
+ series = []
134
+ for serie in self.series:
135
+ data = []
136
+
137
+ type_serie = 'SCATTER'
138
+ if serie.serie_type == ChartDataSerieType.SCATTER:
139
+ type_serie = 'SCATTER'
140
+ elif serie.serie_type == ChartDataSerieType.LINE:
141
+ type_serie = 'LINE'
142
+ elif serie.serie_type == ChartDataSerieType.AREA:
143
+ type_serie = 'AREA'
144
+ else:
145
+ continue
146
+
147
+ for item in serie.data:
148
+ data.append(
149
+ {
150
+ 'x_axis': item.x,
151
+ 'y_axis': item.y,
152
+ }
153
+ )
154
+
155
+ series.append(
156
+ {
157
+ 'group': serie.label,
158
+ 'color': serie.color,
159
+ 'values': data,
160
+ 'type': type_serie,
161
+ }
162
+ )
163
+
164
+ return series
165
+
166
+ def _render_apexcharts(self: Self) -> Dict[str, Any]:
167
+ """
168
+ Converts the configuration of the chart to Javascript library ApexCharts.
169
+ """
170
+
171
+ series = []
172
+ colors = []
173
+
174
+ for serie in self.series:
175
+ data = []
176
+
177
+ for item in serie.data:
178
+ data.append([item.x, item.y])
179
+
180
+ series.append(
181
+ {
182
+ 'name': serie.label,
183
+ 'data': data,
184
+ 'type': serie.serie_type.value,
185
+ }
186
+ )
187
+ colors.append(serie.color)
188
+
189
+ config = {
190
+ 'series': series,
191
+ 'colors': colors,
192
+ 'title': {
193
+ 'text': self.title,
194
+ 'align': self.align.value,
195
+ 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'},
196
+ },
197
+ 'chart': {
198
+ 'type': 'scatter',
199
+ 'animations': {'enabled': False},
200
+ 'toolbar': {'show': False},
201
+ 'zoom': {'enabled': False},
202
+ },
203
+ 'dataLabels': {'enabled': True},
204
+ }
205
+
206
+ return config
@@ -0,0 +1,15 @@
1
+ from typing import List
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+ from .chart_data_serie_type import ChartDataSerieType
6
+ from .scatter_serie_item import ScatterSerieItem
7
+
8
+
9
+ class ScatterSerie(BaseModel):
10
+ """Chart Data Serie for Timeline charts"""
11
+
12
+ data: List[ScatterSerieItem] = Field(description='List of data points', default_factory=list)
13
+ color: str = Field(description='Color of the serie', default='')
14
+ label: str = Field(description='Label of the serie', default='')
15
+ serie_type: ChartDataSerieType = Field(description='Type of the serie', default=ChartDataSerieType.SCATTER)
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+
4
+ class ScatterSerieItem(BaseModel):
5
+ """Chart Data Serie Item for Scatter Charts"""
6
+
7
+ x: float = Field(description='X value of the item')
8
+ y: float = Field(description='Y value of the item')
@@ -0,0 +1,50 @@
1
+ """Number chart"""
2
+
3
+ import sys
4
+ from typing import Any, Dict, List
5
+
6
+ from pydantic import BaseModel, Field
7
+
8
+ from .chart_render_technology import ChartRenderTechnology
9
+ from .table_header import TableHeader
10
+ from .table_row import TableRow
11
+
12
+ if sys.version_info >= (3, 11):
13
+ from typing import Self
14
+ else:
15
+ from typing_extensions import Self
16
+
17
+
18
+ class TableChart(BaseModel):
19
+ """Table chart configuration"""
20
+
21
+ columns: List[TableHeader] = Field(description='List of columns', default_factory=list)
22
+ rows: List[TableRow] = Field(description='List of rows', default_factory=list)
23
+
24
+ def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER) -> Dict[str, Any]:
25
+ """
26
+ Render chart to a graphic Library.
27
+ :param technology: The technology to use to render the chart.
28
+ :return: The configuration of the chart.
29
+ """
30
+ if technology == ChartRenderTechnology.FLUTTER:
31
+ return {
32
+ 'library': 'FLUTTER',
33
+ 'chart': 'TABLE',
34
+ 'configuration': self._render_flutter(),
35
+ }
36
+
37
+ return {
38
+ 'library': 'FLUTTER',
39
+ 'chart': 'TEXT',
40
+ 'configuration': [f'Unsupported {technology}'],
41
+ }
42
+
43
+ def _render_flutter(self: Self) -> Dict[str, Any]:
44
+ """
45
+ Converts the configuration of the chart to a Flutter native components.
46
+ """
47
+ return {
48
+ 'columns': [{'key': column.key, 'label': column.label} for column in self.columns],
49
+ 'rows': [{'data': row.data} for row in self.rows],
50
+ }
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+
4
+ class TableHeader(BaseModel):
5
+ """Table header chart configuration"""
6
+
7
+ label: str = Field(description='Label of the header')
8
+ key: str = Field(description='Key of the header')
@@ -0,0 +1,9 @@
1
+ from typing import Any
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class TableRow(BaseModel):
7
+ """Table row chart configuration"""
8
+
9
+ data: Any = Field(description='Data of the row')
@@ -0,0 +1,75 @@
1
+ """Timeline chart entities"""
2
+
3
+ import sys
4
+ from typing import Any, Dict, List
5
+
6
+ from pydantic import BaseModel, Field
7
+
8
+ from .chart_alignment import ChartAlignment
9
+ from .timeline_serie import TimelineSerie
10
+
11
+ if sys.version_info >= (3, 11):
12
+ from typing import Self
13
+ else:
14
+ from typing_extensions import Self
15
+
16
+
17
+ class TimelineChart(BaseModel):
18
+ """Timeline chart configuration"""
19
+
20
+ series: List[TimelineSerie] = Field(description='List of series to be displayed in the chart', default_factory=list)
21
+ title: str = Field(description='Title of the chart', default='Chart')
22
+ align: ChartAlignment = Field(description='Alignment of the chart', default=ChartAlignment.CENTER)
23
+
24
+ def render(self: Self) -> Dict[str, Any]:
25
+ """
26
+ Render chart to a graphic Library.
27
+ :param technology: The technology to use to render the chart.
28
+ :return: The configuration of the chart.
29
+ """
30
+ return {'library': 'APEXCHARTS', 'configuration': self._render_apexcharts()}
31
+
32
+ def _render_apexcharts(self: Self) -> Dict[str, Any]:
33
+ """
34
+ Converts the configuration of the chart to Javascript library ApexCharts.
35
+ """
36
+
37
+ series = []
38
+
39
+ for serie in self.series:
40
+ data = []
41
+
42
+ for item in serie.data:
43
+ data.append(
44
+ {
45
+ 'x': item.name,
46
+ 'y': [item.start_at.timestamp() * 1000, item.end_at.timestamp() * 1000],
47
+ 'fillColor': item.color,
48
+ }
49
+ )
50
+
51
+ series.append({'name': serie.label, 'data': data})
52
+
53
+ config = {
54
+ 'series': series,
55
+ 'title': {
56
+ 'text': self.title,
57
+ 'align': self.align.value,
58
+ 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'},
59
+ },
60
+ 'chart': {
61
+ 'type': 'rangeBar',
62
+ 'animations': {'enabled': False},
63
+ 'toolbar': {'show': False},
64
+ 'zoom': {'enabled': False},
65
+ },
66
+ 'xaxis': {'type': 'datetime'},
67
+ 'plotOptions': {
68
+ 'bar': {
69
+ 'horizontal': True,
70
+ }
71
+ },
72
+ 'dataLabels': {'enabled': True},
73
+ }
74
+
75
+ return config