chuijs 3.6.2 → 3.6.4

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 (119) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1203 -162
  3. package/framework/appLayout/default/chui_app_layout.js +747 -747
  4. package/framework/appLayout/default/global_style.css +592 -568
  5. package/framework/appLayout/default/main_theme_style.css +118 -101
  6. package/framework/components/chui_accordion/accordion.js +63 -63
  7. package/framework/components/chui_accordion/styles.css +79 -75
  8. package/framework/components/chui_badge/badge.js +55 -55
  9. package/framework/components/chui_badge/styles.css +29 -29
  10. package/framework/components/chui_button/button.js +48 -48
  11. package/framework/components/chui_button/styles.css +75 -70
  12. package/framework/components/chui_calendar/calendar.js +97 -97
  13. package/framework/components/chui_card/card.js +87 -0
  14. package/framework/components/chui_card/styles.css +72 -0
  15. package/framework/components/chui_code/code.js +18 -18
  16. package/framework/components/chui_code/styles.css +9 -9
  17. package/framework/components/chui_console/console.js +27 -27
  18. package/framework/components/chui_console/styles.css +31 -31
  19. package/framework/components/chui_content_block/content_block.js +51 -51
  20. package/framework/components/chui_content_block/styles.css +2 -2
  21. package/framework/components/chui_context_menu/context_menu.js +230 -0
  22. package/framework/components/chui_context_menu/styles.css +136 -0
  23. package/framework/components/chui_custom_element/custom_element.js +24 -24
  24. package/framework/components/chui_details/details.js +85 -85
  25. package/framework/components/chui_details/styles.css +70 -66
  26. package/framework/components/chui_fieldset/fieldset.js +40 -40
  27. package/framework/components/chui_fieldset/styles.css +24 -24
  28. package/framework/components/chui_form/form.js +40 -40
  29. package/framework/components/chui_form/styles.css +21 -21
  30. package/framework/components/chui_graphs/graphs.js +234 -190
  31. package/framework/components/chui_graphs/styles.css +37 -32
  32. package/framework/components/chui_hero/hero.js +98 -0
  33. package/framework/components/chui_hero/styles.css +91 -0
  34. package/framework/components/chui_html_block/html_block.js +16 -16
  35. package/framework/components/chui_html_block/styles.css +5 -5
  36. package/framework/components/chui_hx/hx.js +15 -15
  37. package/framework/components/chui_hx/styles.css +38 -38
  38. package/framework/components/chui_icons/icons.js +2144 -2144
  39. package/framework/components/chui_icons/styles.css +13 -13
  40. package/framework/components/chui_inputs/chui_check_box/check_box.js +32 -32
  41. package/framework/components/chui_inputs/chui_check_box/styles.css +91 -86
  42. package/framework/components/chui_inputs/chui_combo_box/combo_box.js +166 -150
  43. package/framework/components/chui_inputs/chui_combo_box/styles.css +113 -107
  44. package/framework/components/chui_inputs/chui_date/date.js +177 -174
  45. package/framework/components/chui_inputs/chui_date/styles.css +163 -128
  46. package/framework/components/chui_inputs/chui_email/email.js +61 -61
  47. package/framework/components/chui_inputs/chui_email/styles.css +69 -71
  48. package/framework/components/chui_inputs/chui_file/file.js +76 -76
  49. package/framework/components/chui_inputs/chui_file/styles.css +99 -99
  50. package/framework/components/chui_inputs/chui_multi_combo_box/multi_combo_box.js +295 -295
  51. package/framework/components/chui_inputs/chui_multi_combo_box/styles.css +212 -235
  52. package/framework/components/chui_inputs/chui_number/number.js +108 -108
  53. package/framework/components/chui_inputs/chui_number/styles.css +84 -84
  54. package/framework/components/chui_inputs/chui_password/password.js +99 -99
  55. package/framework/components/chui_inputs/chui_password/styles.css +97 -97
  56. package/framework/components/chui_inputs/chui_radio_button/radio_button.js +45 -45
  57. package/framework/components/chui_inputs/chui_radio_button/styles.css +76 -73
  58. package/framework/components/chui_inputs/chui_select_box/select_box.js +187 -170
  59. package/framework/components/chui_inputs/chui_select_box/styles.css +123 -117
  60. package/framework/components/chui_inputs/chui_text/styles.css +83 -84
  61. package/framework/components/chui_inputs/chui_text/text.js +91 -91
  62. package/framework/components/chui_inputs/chui_text_area/styles.css +57 -57
  63. package/framework/components/chui_inputs/chui_text_area/text_area.js +61 -61
  64. package/framework/components/chui_inputs/chui_toggle/styles.css +66 -61
  65. package/framework/components/chui_inputs/chui_toggle/toggle.js +36 -36
  66. package/framework/components/chui_label/label.js +54 -54
  67. package/framework/components/chui_label/styles.css +11 -11
  68. package/framework/components/chui_media/audio.js +908 -908
  69. package/framework/components/chui_media/audio_styles.css +458 -458
  70. package/framework/components/chui_media/image.js +105 -105
  71. package/framework/components/chui_media/image_styles.css +61 -61
  72. package/framework/components/chui_media/video.js +248 -248
  73. package/framework/components/chui_media/video_styles.css +160 -160
  74. package/framework/components/chui_menu_bar/menu_bar.js +66 -74
  75. package/framework/components/chui_menu_bar/styles.css +114 -76
  76. package/framework/components/chui_modal/modal.js +142 -135
  77. package/framework/components/chui_modal/styles.css +36 -36
  78. package/framework/components/chui_notification/notification.js +72 -72
  79. package/framework/components/chui_notification/notification_download.js +78 -78
  80. package/framework/components/chui_notification/notification_download_progress.css +119 -123
  81. package/framework/components/chui_notification/notification_download_progress.js +105 -105
  82. package/framework/components/chui_notification/notification_update.js +54 -54
  83. package/framework/components/chui_notification/styles.css +91 -91
  84. package/framework/components/chui_notification/styles_download.css +85 -85
  85. package/framework/components/chui_notification/styles_update.css +73 -73
  86. package/framework/components/chui_paragraph/paragraph.js +14 -14
  87. package/framework/components/chui_paragraph/styles.css +6 -6
  88. package/framework/components/chui_popups/popups.js +250 -250
  89. package/framework/components/chui_popups/styles.css +129 -115
  90. package/framework/components/chui_progress_bar/progress_bar.js +28 -28
  91. package/framework/components/chui_progress_bar/styles.css +28 -28
  92. package/framework/components/chui_radio_group/radio_group.js +57 -57
  93. package/framework/components/chui_radio_group/styles.css +3 -3
  94. package/framework/components/chui_slideshow/slideshow.js +75 -75
  95. package/framework/components/chui_slideshow/styles.css +94 -85
  96. package/framework/components/chui_spinner/spinner.js +45 -45
  97. package/framework/components/chui_spinner/styles.css +23 -23
  98. package/framework/components/chui_table/styles.css +42 -42
  99. package/framework/components/chui_table/table.js +234 -234
  100. package/framework/components/chui_tabs/chui_tabs.js +77 -77
  101. package/framework/components/chui_tabs/styles.css +54 -48
  102. package/framework/components/chui_text_editor/styles.css +217 -217
  103. package/framework/components/chui_text_editor/text_editor.js +144 -144
  104. package/framework/components/chui_text_editor/text_editor_panel.js +568 -568
  105. package/framework/components/chui_tree_view/styles.css +81 -75
  106. package/framework/components/chui_tree_view/tree_view.js +90 -90
  107. package/framework/components/chui_webview/styles.css +27 -27
  108. package/framework/components/chui_webview/webview.js +103 -103
  109. package/framework/components/telegram_bot/chui_telegram_bot.js +183 -183
  110. package/framework/modules/chui_animations/animations.js +121 -121
  111. package/framework/modules/chui_animations/styles.css +79 -79
  112. package/framework/modules/chui_fonts.js +7129 -6974
  113. package/framework/modules/chui_functions.js +106 -78
  114. package/framework/modules/chui_logger/chui_logger.js +53 -53
  115. package/framework/modules/chui_page/page.js +86 -86
  116. package/framework/modules/chui_page/styles.css +9 -9
  117. package/framework/tray_bar/chui_menu_items.js +48 -48
  118. package/index.js +570 -555
  119. package/package.json +51 -46
@@ -1,190 +1,234 @@
1
- let { Notification } = require('../chui_notification/notification')
2
-
3
- class BarGraph {
4
- #canvas = document.createElement('canvas');
5
- #options = undefined;
6
- constructor(options) {
7
- require('../../modules/chui_functions').setStyles(__dirname + "/styles.css", 'chUiJS_Canvas');
8
- this.#options = options;
9
- let colors = options.colors;
10
- let data_lenght = 0;
11
- let datz = [];
12
- let labelz = [];
13
- for (let test in this.#options.data) {
14
- data_lenght++;
15
- datz.push(this.#options.data[test]);
16
- labelz.push(test);
17
- }
18
- let height = Math.max.apply(null, datz);
19
- height = height / 100;
20
- height = Math.ceil(height) * 100;
21
- let zz = 4;
22
- let width = (150 * data_lenght) - 75;
23
- let max = height;
24
- this.#canvas.setAttribute("width", width+70);
25
- this.#canvas.setAttribute("height", height+70);
26
- let ctx = this.#canvas.getContext('2d');
27
-
28
- ctx.strokeStyle = '#8e8e93'
29
- ctx.lineWidth = 1.5;
30
- ctx.beginPath();
31
- ctx.moveTo(35, 35);
32
- ctx.lineTo(35, height + 35);
33
- ctx.lineTo(width + 35, height + 35);
34
- ctx.stroke();
35
-
36
- let shag = max / zz;
37
-
38
- ctx.fillStyle = "#8e8e93";
39
- let test = (height + 35) / shag + 1;
40
- for(let i = 0; i < test; i++) {
41
- let testzz = i * shag;
42
- if (testzz < max || testzz === max) {
43
- ctx.font = `bold 14px Arial`;
44
- ctx.textBaseline = 'middle';
45
- ctx.fillText(testzz, 0, (height + 35 - i * shag));
46
- ctx.beginPath();
47
- ctx.moveTo(35, height + 35 - i * shag);
48
- ctx.lineTo(30, height + 35 - i * shag);
49
- ctx.stroke();
50
- }
51
- }
52
-
53
- let i = 0;
54
- for (test in this.#options.data) {
55
- ctx.font = `bold 14px Arial`;
56
- ctx.fillText(test, 35 + i * 150, height + 60);
57
- i++;
58
- }
59
-
60
-
61
- let rects = [];
62
- i = 0;
63
- for (test in this.#options.data) {
64
- let dp = this.#options.data[test];
65
- rects.push({x: 35 + i * 150, y: height + 35 - dp, w: 75, h: dp})
66
- i++;
67
- }
68
- i = 0;
69
- let r;
70
- while(r = rects[i++]) {
71
- ctx.fillStyle = `${colors[i-1]}`;
72
- ctx.fillRect(r.x, r.y, r.w, r.h);
73
- }
74
-
75
- this.#canvas.onclick = function(e) {
76
- let rect = this.getBoundingClientRect(), x = e.clientX - rect.left, y = e.clientY - rect.top, i = 0, r;
77
- while(r = rects[i++]) {
78
- ctx.fillStyle = `${colors[i-1]}`;
79
- ctx.beginPath();
80
- ctx.rect(r.x, r.y, r.w, r.h);
81
- if (ctx.isPointInPath(x, y)) {
82
- new Notification(`${labelz[i-1]} [${datz[i-1]}]`).show();
83
- ctx.fillStyle = ctx.isPointInPath(x, y) ? "#1676f3" : "#1676f3";
84
- }
85
- ctx.closePath();
86
- ctx.fill();
87
- }
88
- };
89
- }
90
- set() {
91
- return this.#canvas;
92
- }
93
- }
94
-
95
- class PieGraph {
96
- #chui_piechart = document.createElement('chui_piechart');
97
- #canvas = document.createElement('canvas');
98
- #options = undefined;
99
- #ctx = this.#canvas.getContext("2d");
100
- #colors = undefined;
101
- constructor(options) {
102
-
103
- this.#canvas.width = 400;
104
- this.#canvas.height = 400;
105
- this.#options = options;
106
-
107
- this.#colors = options.colors;
108
-
109
- let total_value = 0;
110
- let color_index = 0;
111
- for (let categ in this.#options.data){
112
- let val = this.#options.data[categ];
113
- total_value += val;
114
- }
115
-
116
- let start_angle = 0;
117
- for (let categ in this.#options.data){
118
- let val = this.#options.data[categ];
119
- let slice_angle = 2 * Math.PI * val / total_value;
120
-
121
- drawPieSlice(
122
- this.#ctx,
123
- this.#canvas.width/2,
124
- this.#canvas.height/2,
125
- Math.min(this.#canvas.width/2,this.#canvas.height/2),
126
- start_angle,
127
- start_angle+slice_angle,
128
- this.#colors[color_index%this.#colors.length]
129
- );
130
-
131
- start_angle += slice_angle;
132
- color_index++;
133
- }
134
- /*if (this.#options.doughnutHoleSize){
135
- drawPieSlice(
136
- this.#ctx,
137
- this.#canvas.width/2,
138
- this.#canvas.height/2,
139
- this.#options.doughnutHoleSize * Math.min(this.#canvas.width/2,this.#canvas.height/2),
140
- 0,
141
- 2 * Math.PI,
142
- "rgba(0, 0, 200, 0.5)"
143
- );
144
- }*/
145
- start_angle = 0;
146
- for (let categ in this.#options.data){
147
- let val = this.#options.data[categ];
148
- let slice_angle = 2 * Math.PI * val / total_value;
149
- let pieRadius = Math.min(this.#canvas.width / 2, this.#canvas.height / 2);
150
- let offset = (pieRadius * 0.3) / 2;
151
- let labelX = this.#canvas.width / 2 + (offset + pieRadius / 2) * Math.cos(start_angle + slice_angle / 2);
152
- let labelY = this.#canvas.height / 2 + (offset + pieRadius / 2) * Math.sin(start_angle + slice_angle / 2);
153
- let labelText = Math.round(100 * val / total_value);
154
- this.#ctx.fillStyle = "white";
155
- this.#ctx.font = "bold 17px Arial";
156
- this.#ctx.fillText(`${labelText}%`, labelX, labelY+10);
157
- start_angle += slice_angle;
158
- }
159
- let legends = document.createElement('legends');
160
- if (this.#options.legend){
161
- color_index = 0;
162
- for (let categ in this.#options.data){
163
- let legend = document.createElement('legend');
164
- let color = document.createElement('legend_color');
165
- let label = document.createElement('legend_label');
166
- color.style.background = `${this.#colors[color_index++]}`;
167
- label.innerHTML = categ;
168
- legend.appendChild(color);
169
- legend.appendChild(label);
170
- legends.appendChild(legend);
171
- }
172
- }
173
- this.#chui_piechart.appendChild(this.#canvas);
174
- this.#chui_piechart.appendChild(legends);
175
- }
176
- set() {
177
- return this.#chui_piechart;
178
- }
179
- }
180
- function drawPieSlice(ctx, centerX, centerY, radius, startAngle, endAngle, color) {
181
- ctx.fillStyle = color;
182
- ctx.beginPath();
183
- ctx.moveTo(centerX , centerY);
184
- ctx.arc(centerX, centerY, radius, startAngle, endAngle);
185
- ctx.closePath();
186
- ctx.fill();
187
- }
188
-
189
- exports.BarGraph = BarGraph;
190
- exports.PieGraph = PieGraph;
1
+ const { Notification } = require('../chui_notification/notification');
2
+ const { setStyles } = require('../../modules/chui_functions');
3
+
4
+ const STYLES_ID = 'chUiJS_Canvas';
5
+ const AXIS_COLOR = '#8e8e93';
6
+ const LABEL_FONT = 'bold 14px Arial';
7
+ const Y_AXIS_STEPS = 4;
8
+ const PLOT_HEIGHT = 240;
9
+ const CATEGORY_WIDTH = 150;
10
+ const BAR_WIDTH = 75;
11
+ const BAR_FALLBACK_COLOR = '#1676f3';
12
+ const PADDING = { top: 20, right: 20, bottom: 50, left: 50 };
13
+ const PIE_SIZE = 400;
14
+
15
+ /** Подбирает «круглый» масштаб оси: максимум и шаг между делениями. */
16
+ function getAxisScale(maxValue) {
17
+ if (!(maxValue > 0)) return { max: Y_AXIS_STEPS, step: 1 };
18
+ const rawStep = maxValue / Y_AXIS_STEPS;
19
+ const magnitude = Math.pow(10, Math.floor(Math.log10(rawStep)));
20
+ const step = Math.ceil(rawStep / magnitude) * magnitude;
21
+ return { max: step * Y_AXIS_STEPS, step: step };
22
+ }
23
+
24
+ /** Форматирует подпись оси без лишних нулей после запятой. */
25
+ function formatAxisLabel(value) {
26
+ return Number(value.toFixed(2)).toString();
27
+ }
28
+
29
+ /** Приводит canvas к физическому разрешению экрана, сохраняя рисование в CSS-пикселях. */
30
+ function prepareCanvas(canvas, cssWidth, cssHeight) {
31
+ const ratio = window.devicePixelRatio || 1;
32
+ canvas.width = cssWidth * ratio;
33
+ canvas.height = cssHeight * ratio;
34
+ canvas.style.width = cssWidth + 'px';
35
+ canvas.style.height = cssHeight + 'px';
36
+ const ctx = canvas.getContext('2d');
37
+ ctx.scale(ratio, ratio);
38
+ return ctx;
39
+ }
40
+
41
+ class BarGraph {
42
+ #canvas = document.createElement('canvas');
43
+ #options = undefined;
44
+ #bars = [];
45
+
46
+ constructor(options) {
47
+ setStyles(__dirname + '/styles.css', STYLES_ID);
48
+ this.#options = options;
49
+ this.#draw();
50
+ this.#bindPointer();
51
+ }
52
+
53
+ #draw() {
54
+ const data = this.#options.data || {};
55
+ const colors = this.#options.colors || [];
56
+ const labels = Object.keys(data);
57
+ const values = labels.map((label) => Number(data[label]) || 0);
58
+ const scale = getAxisScale(Math.max.apply(null, values.length ? values : [0]));
59
+
60
+ const plotWidth = labels.length * CATEGORY_WIDTH;
61
+ const cssWidth = PADDING.left + plotWidth + PADDING.right;
62
+ const cssHeight = PADDING.top + PLOT_HEIGHT + PADDING.bottom;
63
+ const ctx = prepareCanvas(this.#canvas, cssWidth, cssHeight);
64
+
65
+ this.#drawAxes(ctx, plotWidth, scale);
66
+ this.#drawBars(ctx, labels, values, scale, colors);
67
+ }
68
+
69
+ #drawAxes(ctx, plotWidth, scale) {
70
+ const originX = PADDING.left;
71
+ const originY = PADDING.top;
72
+ const bottomY = originY + PLOT_HEIGHT;
73
+
74
+ ctx.strokeStyle = AXIS_COLOR;
75
+ ctx.lineWidth = 1.5;
76
+ ctx.beginPath();
77
+ ctx.moveTo(originX, originY);
78
+ ctx.lineTo(originX, bottomY);
79
+ ctx.lineTo(originX + plotWidth, bottomY);
80
+ ctx.stroke();
81
+
82
+ ctx.font = LABEL_FONT;
83
+ ctx.fillStyle = AXIS_COLOR;
84
+ ctx.textAlign = 'right';
85
+ ctx.textBaseline = 'middle';
86
+ for (let i = 0; i <= Y_AXIS_STEPS; i++) {
87
+ const y = bottomY - (i / Y_AXIS_STEPS) * PLOT_HEIGHT;
88
+ ctx.fillText(formatAxisLabel(i * scale.step), originX - 6, y);
89
+ ctx.beginPath();
90
+ ctx.moveTo(originX, y);
91
+ ctx.lineTo(originX - 5, y);
92
+ ctx.stroke();
93
+ }
94
+ }
95
+
96
+ #drawBars(ctx, labels, values, scale, colors) {
97
+ const bottomY = PADDING.top + PLOT_HEIGHT;
98
+ this.#bars = [];
99
+ ctx.textAlign = 'center';
100
+ ctx.textBaseline = 'top';
101
+ for (let i = 0; i < labels.length; i++) {
102
+ const barHeight = (values[i] / scale.max) * PLOT_HEIGHT;
103
+ const x = PADDING.left + i * CATEGORY_WIDTH + (CATEGORY_WIDTH - BAR_WIDTH) / 2;
104
+ const bar = { index: i, x: x, y: bottomY - barHeight, w: BAR_WIDTH, h: barHeight };
105
+ this.#bars.push(bar);
106
+
107
+ ctx.fillStyle = colors[i % colors.length] || BAR_FALLBACK_COLOR;
108
+ ctx.fillRect(bar.x, bar.y, bar.w, bar.h);
109
+
110
+ ctx.fillStyle = AXIS_COLOR;
111
+ ctx.fillText(labels[i], bar.x + bar.w / 2, bottomY + 10);
112
+ }
113
+ }
114
+
115
+ #bindPointer() {
116
+ this.#canvas.style.cursor = 'pointer';
117
+ this.#canvas.addEventListener('click', (event) => {
118
+ const bar = this.#findBar(event);
119
+ if (bar === null) return;
120
+ const data = this.#options.data || {};
121
+ const labels = Object.keys(data);
122
+ new Notification({
123
+ title: labels[bar.index],
124
+ text: String(data[labels[bar.index]]),
125
+ showTime: 3000,
126
+ }).show();
127
+ });
128
+ }
129
+
130
+ #findBar(event) {
131
+ const rect = this.#canvas.getBoundingClientRect();
132
+ const x = event.clientX - rect.left;
133
+ const y = event.clientY - rect.top;
134
+ for (let bar of this.#bars) {
135
+ if (x >= bar.x && x <= bar.x + bar.w && y >= bar.y && y <= bar.y + bar.h) return bar;
136
+ }
137
+ return null;
138
+ }
139
+
140
+ set() {
141
+ return this.#canvas;
142
+ }
143
+ }
144
+
145
+ class PieGraph {
146
+ #chui_piechart = document.createElement('chui_piechart');
147
+ #canvas = document.createElement('canvas');
148
+ #options = undefined;
149
+
150
+ constructor(options) {
151
+ setStyles(__dirname + '/styles.css', STYLES_ID);
152
+ this.#options = options;
153
+ const ctx = prepareCanvas(this.#canvas, PIE_SIZE, PIE_SIZE);
154
+ this.#drawSlices(ctx);
155
+ this.#chui_piechart.appendChild(this.#canvas);
156
+ if (options.legend) this.#chui_piechart.appendChild(this.#buildLegend());
157
+ }
158
+
159
+ #drawSlices(ctx) {
160
+ const data = this.#options.data || {};
161
+ const colors = this.#options.colors || [];
162
+ const labels = Object.keys(data);
163
+ const total = labels.reduce((sum, label) => sum + (Number(data[label]) || 0), 0);
164
+ if (total <= 0) return;
165
+
166
+ const center = PIE_SIZE / 2;
167
+ let startAngle = 0;
168
+ for (let i = 0; i < labels.length; i++) {
169
+ const value = Number(data[labels[i]]) || 0;
170
+ const sliceAngle = 2 * Math.PI * value / total;
171
+ drawPieSlice(ctx, center, center, center, startAngle, startAngle + sliceAngle, colors[i % colors.length]);
172
+ this.#drawPercentage(ctx, center, startAngle, sliceAngle, value, total);
173
+ startAngle += sliceAngle;
174
+ }
175
+ this.#drawDoughnutHole(ctx, center);
176
+ }
177
+
178
+ #drawPercentage(ctx, center, startAngle, sliceAngle, value, total) {
179
+ const labelRadius = center * 0.65;
180
+ const angle = startAngle + sliceAngle / 2;
181
+ ctx.fillStyle = 'white';
182
+ ctx.font = LABEL_FONT;
183
+ ctx.textAlign = 'center';
184
+ ctx.textBaseline = 'middle';
185
+ ctx.fillText(`${Math.round(100 * value / total)}%`, center + labelRadius * Math.cos(angle), center + labelRadius * Math.sin(angle));
186
+ }
187
+
188
+ #drawDoughnutHole(ctx, center) {
189
+ const holeSize = this.#options.doughnutHoleSize;
190
+ if (!(holeSize > 0) || holeSize >= 1) return;
191
+ ctx.save();
192
+ ctx.globalCompositeOperation = 'destination-out';
193
+ ctx.beginPath();
194
+ ctx.arc(center, center, center * holeSize, 0, 2 * Math.PI);
195
+ ctx.closePath();
196
+ ctx.fill();
197
+ ctx.restore();
198
+ }
199
+
200
+ #buildLegend() {
201
+ const data = this.#options.data || {};
202
+ const colors = this.#options.colors || [];
203
+ const legends = document.createElement('legends');
204
+ let index = 0;
205
+ for (let label in data) {
206
+ const legend = document.createElement('legend');
207
+ const color = document.createElement('legend_color');
208
+ const text = document.createElement('legend_label');
209
+ color.style.background = colors[index % colors.length];
210
+ text.innerHTML = label;
211
+ legend.appendChild(color);
212
+ legend.appendChild(text);
213
+ legends.appendChild(legend);
214
+ index++;
215
+ }
216
+ return legends;
217
+ }
218
+
219
+ set() {
220
+ return this.#chui_piechart;
221
+ }
222
+ }
223
+
224
+ function drawPieSlice(ctx, centerX, centerY, radius, startAngle, endAngle, color) {
225
+ ctx.fillStyle = color;
226
+ ctx.beginPath();
227
+ ctx.moveTo(centerX, centerY);
228
+ ctx.arc(centerX, centerY, radius, startAngle, endAngle);
229
+ ctx.closePath();
230
+ ctx.fill();
231
+ }
232
+
233
+ exports.BarGraph = BarGraph;
234
+ exports.PieGraph = PieGraph;
@@ -1,33 +1,38 @@
1
- canvas {
2
- "background": "var(--main_background)",
3
- "height": "max-content",
4
- "width": "max-content",
5
- "border-radius": "var(--border_radius)",
6
- "margin": "var(--margin)",
7
- }
8
-
9
- chui_piechart {
10
- "display": "flex",
11
- "align-items": "center",
12
- }
13
-
14
- legends {
15
- "margin": "15px"
16
- }
17
-
18
- legend {
19
- "display": "flex",
20
- "align-items": "center",
21
- }
22
-
23
- legend_color {
24
- "width": "20px",
25
- "height": "20px",
26
- "border-radius": "var(--border_radius)"
27
- }
28
-
29
- legend_label {
30
- "color": "var(--text_color)",
31
- "font-weight": "400",
32
- "margin": "var(--margin)"
1
+ canvas {
2
+ background: var(--element_background_2);
3
+ height: max-content;
4
+ width: max-content;
5
+ border-radius: var(--border_radius);
6
+ margin: var(--margin);
7
+ }
8
+
9
+ chui_piechart {
10
+ display: flex;
11
+ align-items: center;
12
+ flex-wrap: wrap;
13
+ }
14
+
15
+ legends {
16
+ display: flex;
17
+ flex-direction: column;
18
+ margin: 15px;
19
+ }
20
+
21
+ legend {
22
+ display: flex;
23
+ align-items: center;
24
+ margin: 2px 0;
25
+ }
26
+
27
+ legend_color {
28
+ width: 20px;
29
+ height: 20px;
30
+ flex-shrink: 0;
31
+ border-radius: var(--border_radius);
32
+ }
33
+
34
+ legend_label {
35
+ color: var(--text_color);
36
+ font-weight: 400;
37
+ margin: var(--margin);
33
38
  }
@@ -0,0 +1,98 @@
1
+ const {Icon} = require("../chui_icons/icons");
2
+
3
+ class Hero {
4
+ #chui_hero = document.createElement("chui_hero");
5
+ #head;
6
+ #badge;
7
+ #titles;
8
+ #title;
9
+ #description;
10
+ #stats;
11
+ constructor(options = {
12
+ id: String(),
13
+ title: String(),
14
+ description: String(),
15
+ icon: String(),
16
+ stats: [],
17
+ style: String(),
18
+ width: String(),
19
+ height: String()
20
+ }) {
21
+ require("../../modules/chui_functions").setStyles(__dirname + "/styles.css", 'chUiJS_Hero');
22
+ if (options.id !== undefined) this.#chui_hero.id = options.id;
23
+ if (options.style !== undefined) this.#chui_hero.classList.add(options.style);
24
+ if (options.width !== undefined) this.#chui_hero.style.width = options.width;
25
+ if (options.height !== undefined) this.#chui_hero.style.height = options.height;
26
+ if (options.icon !== undefined) this.setIcon(options.icon);
27
+ if (options.title !== undefined) this.setTitle(options.title);
28
+ if (options.description !== undefined) this.setDescription(options.description);
29
+ if (options.stats !== undefined) for (let stat of options.stats) this.addStat(stat.value, stat.label);
30
+ }
31
+ // GET
32
+ getId() { return this.#chui_hero.id; }
33
+ getTitle() { return this.#title === undefined ? "" : this.#title.innerText; }
34
+ getDescription() { return this.#description === undefined ? "" : this.#description.innerText; }
35
+ // SET
36
+ setId(id = String()) { this.#chui_hero.id = id; }
37
+ setStyle(style = String()) { this.#chui_hero.classList.add(style); }
38
+ setWidth(width = String()) { this.#chui_hero.style.width = width; }
39
+ setHeight(height = String()) { this.#chui_hero.style.height = height; }
40
+ setIcon(icon = String()) {
41
+ if (this.#badge === undefined) {
42
+ this.#badge = document.createElement("hero_badge");
43
+ this.#headNode().prepend(this.#badge);
44
+ }
45
+ this.#badge.innerHTML = new Icon(icon, "28px").getHTML();
46
+ }
47
+ setTitle(text = String()) {
48
+ if (this.#title === undefined) {
49
+ this.#title = document.createElement("hero_title");
50
+ this.#titlesNode().appendChild(this.#title);
51
+ }
52
+ this.#title.innerText = text;
53
+ }
54
+ setDescription(text = String()) {
55
+ if (this.#description === undefined) {
56
+ this.#description = document.createElement("hero_description");
57
+ this.#titlesNode().appendChild(this.#description);
58
+ }
59
+ this.#description.innerText = text;
60
+ }
61
+ // FUNCTIONS
62
+ addStat(value = String(), label = String()) {
63
+ let stat = document.createElement("hero_stat");
64
+ let stat_value = document.createElement("hero_stat_value");
65
+ let stat_label = document.createElement("hero_stat_label");
66
+ stat_value.innerText = value;
67
+ stat_label.innerText = label;
68
+ stat.append(stat_value, stat_label);
69
+ this.#statsNode().appendChild(stat);
70
+ }
71
+ clearStats() { this.#statsNode().innerHTML = ""; }
72
+ // Шапка и статистика создаются при первом обращении, шапка всегда стоит выше
73
+ #headNode() {
74
+ if (this.#head === undefined) {
75
+ this.#head = document.createElement("hero_head");
76
+ this.#chui_hero.prepend(this.#head);
77
+ }
78
+ return this.#head;
79
+ }
80
+ #titlesNode() {
81
+ if (this.#titles === undefined) {
82
+ this.#titles = document.createElement("hero_titles");
83
+ this.#headNode().appendChild(this.#titles);
84
+ }
85
+ return this.#titles;
86
+ }
87
+ #statsNode() {
88
+ if (this.#stats === undefined) {
89
+ this.#stats = document.createElement("hero_stats");
90
+ this.#chui_hero.appendChild(this.#stats);
91
+ }
92
+ return this.#stats;
93
+ }
94
+ // RENDER
95
+ set() { return this.#chui_hero; }
96
+ }
97
+
98
+ exports.Hero = Hero