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.
- package/LICENSE +21 -21
- package/README.md +1203 -162
- package/framework/appLayout/default/chui_app_layout.js +747 -747
- package/framework/appLayout/default/global_style.css +592 -568
- package/framework/appLayout/default/main_theme_style.css +118 -101
- package/framework/components/chui_accordion/accordion.js +63 -63
- package/framework/components/chui_accordion/styles.css +79 -75
- package/framework/components/chui_badge/badge.js +55 -55
- package/framework/components/chui_badge/styles.css +29 -29
- package/framework/components/chui_button/button.js +48 -48
- package/framework/components/chui_button/styles.css +75 -70
- package/framework/components/chui_calendar/calendar.js +97 -97
- package/framework/components/chui_card/card.js +87 -0
- package/framework/components/chui_card/styles.css +72 -0
- package/framework/components/chui_code/code.js +18 -18
- package/framework/components/chui_code/styles.css +9 -9
- package/framework/components/chui_console/console.js +27 -27
- package/framework/components/chui_console/styles.css +31 -31
- package/framework/components/chui_content_block/content_block.js +51 -51
- package/framework/components/chui_content_block/styles.css +2 -2
- package/framework/components/chui_context_menu/context_menu.js +230 -0
- package/framework/components/chui_context_menu/styles.css +136 -0
- package/framework/components/chui_custom_element/custom_element.js +24 -24
- package/framework/components/chui_details/details.js +85 -85
- package/framework/components/chui_details/styles.css +70 -66
- package/framework/components/chui_fieldset/fieldset.js +40 -40
- package/framework/components/chui_fieldset/styles.css +24 -24
- package/framework/components/chui_form/form.js +40 -40
- package/framework/components/chui_form/styles.css +21 -21
- package/framework/components/chui_graphs/graphs.js +234 -190
- package/framework/components/chui_graphs/styles.css +37 -32
- package/framework/components/chui_hero/hero.js +98 -0
- package/framework/components/chui_hero/styles.css +91 -0
- package/framework/components/chui_html_block/html_block.js +16 -16
- package/framework/components/chui_html_block/styles.css +5 -5
- package/framework/components/chui_hx/hx.js +15 -15
- package/framework/components/chui_hx/styles.css +38 -38
- package/framework/components/chui_icons/icons.js +2144 -2144
- package/framework/components/chui_icons/styles.css +13 -13
- package/framework/components/chui_inputs/chui_check_box/check_box.js +32 -32
- package/framework/components/chui_inputs/chui_check_box/styles.css +91 -86
- package/framework/components/chui_inputs/chui_combo_box/combo_box.js +166 -150
- package/framework/components/chui_inputs/chui_combo_box/styles.css +113 -107
- package/framework/components/chui_inputs/chui_date/date.js +177 -174
- package/framework/components/chui_inputs/chui_date/styles.css +163 -128
- package/framework/components/chui_inputs/chui_email/email.js +61 -61
- package/framework/components/chui_inputs/chui_email/styles.css +69 -71
- package/framework/components/chui_inputs/chui_file/file.js +76 -76
- package/framework/components/chui_inputs/chui_file/styles.css +99 -99
- package/framework/components/chui_inputs/chui_multi_combo_box/multi_combo_box.js +295 -295
- package/framework/components/chui_inputs/chui_multi_combo_box/styles.css +212 -235
- package/framework/components/chui_inputs/chui_number/number.js +108 -108
- package/framework/components/chui_inputs/chui_number/styles.css +84 -84
- package/framework/components/chui_inputs/chui_password/password.js +99 -99
- package/framework/components/chui_inputs/chui_password/styles.css +97 -97
- package/framework/components/chui_inputs/chui_radio_button/radio_button.js +45 -45
- package/framework/components/chui_inputs/chui_radio_button/styles.css +76 -73
- package/framework/components/chui_inputs/chui_select_box/select_box.js +187 -170
- package/framework/components/chui_inputs/chui_select_box/styles.css +123 -117
- package/framework/components/chui_inputs/chui_text/styles.css +83 -84
- package/framework/components/chui_inputs/chui_text/text.js +91 -91
- package/framework/components/chui_inputs/chui_text_area/styles.css +57 -57
- package/framework/components/chui_inputs/chui_text_area/text_area.js +61 -61
- package/framework/components/chui_inputs/chui_toggle/styles.css +66 -61
- package/framework/components/chui_inputs/chui_toggle/toggle.js +36 -36
- package/framework/components/chui_label/label.js +54 -54
- package/framework/components/chui_label/styles.css +11 -11
- package/framework/components/chui_media/audio.js +908 -908
- package/framework/components/chui_media/audio_styles.css +458 -458
- package/framework/components/chui_media/image.js +105 -105
- package/framework/components/chui_media/image_styles.css +61 -61
- package/framework/components/chui_media/video.js +248 -248
- package/framework/components/chui_media/video_styles.css +160 -160
- package/framework/components/chui_menu_bar/menu_bar.js +66 -74
- package/framework/components/chui_menu_bar/styles.css +114 -76
- package/framework/components/chui_modal/modal.js +142 -135
- package/framework/components/chui_modal/styles.css +36 -36
- package/framework/components/chui_notification/notification.js +72 -72
- package/framework/components/chui_notification/notification_download.js +78 -78
- package/framework/components/chui_notification/notification_download_progress.css +119 -123
- package/framework/components/chui_notification/notification_download_progress.js +105 -105
- package/framework/components/chui_notification/notification_update.js +54 -54
- package/framework/components/chui_notification/styles.css +91 -91
- package/framework/components/chui_notification/styles_download.css +85 -85
- package/framework/components/chui_notification/styles_update.css +73 -73
- package/framework/components/chui_paragraph/paragraph.js +14 -14
- package/framework/components/chui_paragraph/styles.css +6 -6
- package/framework/components/chui_popups/popups.js +250 -250
- package/framework/components/chui_popups/styles.css +129 -115
- package/framework/components/chui_progress_bar/progress_bar.js +28 -28
- package/framework/components/chui_progress_bar/styles.css +28 -28
- package/framework/components/chui_radio_group/radio_group.js +57 -57
- package/framework/components/chui_radio_group/styles.css +3 -3
- package/framework/components/chui_slideshow/slideshow.js +75 -75
- package/framework/components/chui_slideshow/styles.css +94 -85
- package/framework/components/chui_spinner/spinner.js +45 -45
- package/framework/components/chui_spinner/styles.css +23 -23
- package/framework/components/chui_table/styles.css +42 -42
- package/framework/components/chui_table/table.js +234 -234
- package/framework/components/chui_tabs/chui_tabs.js +77 -77
- package/framework/components/chui_tabs/styles.css +54 -48
- package/framework/components/chui_text_editor/styles.css +217 -217
- package/framework/components/chui_text_editor/text_editor.js +144 -144
- package/framework/components/chui_text_editor/text_editor_panel.js +568 -568
- package/framework/components/chui_tree_view/styles.css +81 -75
- package/framework/components/chui_tree_view/tree_view.js +90 -90
- package/framework/components/chui_webview/styles.css +27 -27
- package/framework/components/chui_webview/webview.js +103 -103
- package/framework/components/telegram_bot/chui_telegram_bot.js +183 -183
- package/framework/modules/chui_animations/animations.js +121 -121
- package/framework/modules/chui_animations/styles.css +79 -79
- package/framework/modules/chui_fonts.js +7129 -6974
- package/framework/modules/chui_functions.js +106 -78
- package/framework/modules/chui_logger/chui_logger.js +53 -53
- package/framework/modules/chui_page/page.js +86 -86
- package/framework/modules/chui_page/styles.css +9 -9
- package/framework/tray_bar/chui_menu_items.js +48 -48
- package/index.js +570 -555
- package/package.json +51 -46
|
@@ -1,190 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
chui_piechart {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|