ozdenui 0.1.0

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 (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/NOTICE +5 -0
  4. data/README.md +242 -0
  5. data/exe/ozdenui +17 -0
  6. data/lib/ozdenui/AGENTS.md +210 -0
  7. data/lib/ozdenui/COMPONENTS.md +3017 -0
  8. data/lib/ozdenui/app.rb +749 -0
  9. data/lib/ozdenui/command.rb +107 -0
  10. data/lib/ozdenui/components.rb +368 -0
  11. data/lib/ozdenui/dialogs.rb +212 -0
  12. data/lib/ozdenui/files.rb +124 -0
  13. data/lib/ozdenui/icon.png +0 -0
  14. data/lib/ozdenui/kit.json +1 -0
  15. data/lib/ozdenui/kit.rb +115 -0
  16. data/lib/ozdenui/look.rb +229 -0
  17. data/lib/ozdenui/objects.rb +652 -0
  18. data/lib/ozdenui/server.rb +270 -0
  19. data/lib/ozdenui/values.rb +273 -0
  20. data/lib/ozdenui/version.rb +15 -0
  21. data/lib/ozdenui/web/basic/LICENSE +14 -0
  22. data/lib/ozdenui/web/basic/basic.min.css +1 -0
  23. data/lib/ozdenui/web/basic/basic.min.js +78 -0
  24. data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
  25. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  26. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  27. data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
  28. data/lib/ozdenui/web/bridge.js +584 -0
  29. data/lib/ozdenui/web/comp/accordion.js +659 -0
  30. data/lib/ozdenui/web/comp/action-button/add.png +0 -0
  31. data/lib/ozdenui/web/comp/action-button.js +521 -0
  32. data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
  33. data/lib/ozdenui/web/comp/app-bar.js +237 -0
  34. data/lib/ozdenui/web/comp/badge.js +292 -0
  35. data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
  36. data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
  37. data/lib/ozdenui/web/comp/canvas.js +652 -0
  38. data/lib/ozdenui/web/comp/chat-view.js +827 -0
  39. data/lib/ozdenui/web/comp/check-box.js +490 -0
  40. data/lib/ozdenui/web/comp/code-editor.js +965 -0
  41. data/lib/ozdenui/web/comp/color-picker.js +636 -0
  42. data/lib/ozdenui/web/comp/context-menu.js +951 -0
  43. data/lib/ozdenui/web/comp/currency-field.js +209 -0
  44. data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
  45. data/lib/ozdenui/web/comp/data-table.js +937 -0
  46. data/lib/ozdenui/web/comp/date-picker.js +1055 -0
  47. data/lib/ozdenui/web/comp/dialog.js +992 -0
  48. data/lib/ozdenui/web/comp/email-field.js +65 -0
  49. data/lib/ozdenui/web/comp/file-picker.js +920 -0
  50. data/lib/ozdenui/web/comp/filters.js +807 -0
  51. data/lib/ozdenui/web/comp/form.js +602 -0
  52. data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
  53. data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
  54. data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
  55. data/lib/ozdenui/web/comp/gauge.js +439 -0
  56. data/lib/ozdenui/web/comp/graph-box.js +3911 -0
  57. data/lib/ozdenui/web/comp/grid-group.js +185 -0
  58. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
  59. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
  60. data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
  61. data/lib/ozdenui/web/comp/image-view.js +598 -0
  62. data/lib/ozdenui/web/comp/item-list.js +1740 -0
  63. data/lib/ozdenui/web/comp/json-editor.js +3221 -0
  64. data/lib/ozdenui/web/comp/json-view.js +597 -0
  65. data/lib/ozdenui/web/comp/label-editor.js +1140 -0
  66. data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
  67. data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
  68. data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
  69. data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
  70. data/lib/ozdenui/web/comp/left-menu.js +548 -0
  71. data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
  72. data/lib/ozdenui/web/comp/loading-screen.js +413 -0
  73. data/lib/ozdenui/web/comp/log-view.js +530 -0
  74. data/lib/ozdenui/web/comp/login-page.js +685 -0
  75. data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
  76. data/lib/ozdenui/web/comp/menu-bar.js +624 -0
  77. data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
  78. data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
  79. data/lib/ozdenui/web/comp/notice.js +229 -0
  80. data/lib/ozdenui/web/comp/number-field.js +128 -0
  81. data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
  82. data/lib/ozdenui/web/comp/page-control.js +762 -0
  83. data/lib/ozdenui/web/comp/page-header.js +191 -0
  84. data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
  85. data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
  86. data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
  87. data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
  88. data/lib/ozdenui/web/comp/password-field.js +192 -0
  89. data/lib/ozdenui/web/comp/period-bar.js +436 -0
  90. data/lib/ozdenui/web/comp/phone-field.js +322 -0
  91. data/lib/ozdenui/web/comp/progress-bar.js +992 -0
  92. data/lib/ozdenui/web/comp/property-panel.js +3639 -0
  93. data/lib/ozdenui/web/comp/radio-button.js +527 -0
  94. data/lib/ozdenui/web/comp/range-slider.js +569 -0
  95. data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
  96. data/lib/ozdenui/web/comp/scroll-area.js +308 -0
  97. data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
  98. data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
  99. data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
  100. data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
  101. data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
  102. data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
  103. data/lib/ozdenui/web/comp/search-input.js +725 -0
  104. data/lib/ozdenui/web/comp/search-results.js +596 -0
  105. data/lib/ozdenui/web/comp/select-box.js +1862 -0
  106. data/lib/ozdenui/web/comp/settings-row.js +299 -0
  107. data/lib/ozdenui/web/comp/side-panel.js +616 -0
  108. data/lib/ozdenui/web/comp/slider-field.js +952 -0
  109. data/lib/ozdenui/web/comp/slider.js +838 -0
  110. data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
  111. data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
  112. data/lib/ozdenui/web/comp/smart-button.js +981 -0
  113. data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
  114. data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
  115. data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
  116. data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
  117. data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
  118. data/lib/ozdenui/web/comp/smart-table.js +1883 -0
  119. data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
  120. data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
  121. data/lib/ozdenui/web/comp/splitter.js +411 -0
  122. data/lib/ozdenui/web/comp/status-bar.js +408 -0
  123. data/lib/ozdenui/web/comp/step-bar.js +345 -0
  124. data/lib/ozdenui/web/comp/stepper.js +753 -0
  125. data/lib/ozdenui/web/comp/tabs.js +1366 -0
  126. data/lib/ozdenui/web/comp/tag-input.js +1107 -0
  127. data/lib/ozdenui/web/comp/tap-effect.js +170 -0
  128. data/lib/ozdenui/web/comp/text-area-field.js +233 -0
  129. data/lib/ozdenui/web/comp/text-field.js +1006 -0
  130. data/lib/ozdenui/web/comp/time-line.js +398 -0
  131. data/lib/ozdenui/web/comp/time-picker.js +1032 -0
  132. data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
  133. data/lib/ozdenui/web/comp/tiny-select.js +322 -0
  134. data/lib/ozdenui/web/comp/tiny-table.js +283 -0
  135. data/lib/ozdenui/web/comp/toast.js +891 -0
  136. data/lib/ozdenui/web/comp/toggle.js +757 -0
  137. data/lib/ozdenui/web/comp/tool-bar.js +760 -0
  138. data/lib/ozdenui/web/comp/tooltip.js +534 -0
  139. data/lib/ozdenui/web/comp/tree-view.js +1179 -0
  140. data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
  141. data/lib/ozdenui/web/comp/ui-standards.js +403 -0
  142. data/lib/ozdenui/web/comp/url-field.js +190 -0
  143. data/lib/ozdenui/web/comp/web-view.js +588 -0
  144. data/lib/ozdenui/web/components.js +123 -0
  145. data/lib/ozdenui/web/index.html +39 -0
  146. data/lib/ozdenui/window.rb +188 -0
  147. data/lib/ozdenui/window_cocoa.rb +221 -0
  148. data/lib/ozdenui.rb +32 -0
  149. metadata +200 -0
@@ -0,0 +1,439 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Gauge - v26.09
6
+
7
+ UI COMPONENT
8
+ - A value drawn on an arc: a full ring (sweepAngle: 360) or a half arc (sweepAngle: 180).
9
+ Both are the same drawing, only the swept angle is different.
10
+ - Parts: the track behind, the bar of the value, an optional marker line (a target, a reserve,
11
+ a limit), the value in the middle, a line under it and a title under the whole gauge.
12
+ - Everything is one SVG, so it stays sharp at every size and the value moves with a CSS
13
+ transition. No image file and no other library is needed.
14
+ - Angles: 0 is the top (12 o'clock) and they grow clockwise. A half arc that opens upwards is
15
+ startAngle: -90, sweepAngle: 180.
16
+ - The drawing area is measured from the arc itself, so a half arc does not leave an empty half.
17
+
18
+ USAGE:
19
+ const battery = Gauge({ width: 180, height: 180, value: 46, subText: "Charging", styleName: "dark" });
20
+ battery.setValue(72);
21
+ battery.setBarColor("#F2B24C");
22
+
23
+ const nozzle = Gauge({
24
+ width: 200, height: 130,
25
+ startAngle: -90, sweepAngle: 180, // half arc
26
+ maxValue: 300, value: 215,
27
+ valueSuffix: "°", titleText: "Nozzle",
28
+ markerValue: 220, // the target line
29
+ });
30
+ nozzle.setMarkerValue(240);
31
+
32
+ Started Date: September 2026
33
+ Webpage: https://bug7a.github.io/js-components/
34
+
35
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
36
+ Licensed under the Apache License, Version 2.0
37
+ SPDX-License-Identifier: Apache-2.0
38
+
39
+ */
40
+
41
+ "use strict";
42
+
43
+ // Default values:
44
+ const GaugeDefaults = {
45
+ key: "0",
46
+ width: 180,
47
+ height: 180,
48
+ value: 0,
49
+ minValue: 0,
50
+ maxValue: 100,
51
+ startAngle: 0, // 0: the top (12 o'clock). They grow clockwise.
52
+ sweepAngle: 360, // 360: a full ring. 180: a half arc.
53
+ radius: 74,
54
+ markerValue: null, // null: no marker line. (A target, a reserve, a limit...)
55
+ valueText: "", // "": the value itself, with decimals and valueSuffix.
56
+ valueSuffix: "%",
57
+ decimals: 0,
58
+ subText: "", // The small line under the value.
59
+ titleText: "", // Under the whole gauge.
60
+ duration: 600, // Length of the animation, in milliseconds.
61
+ ariaLabel: "Gauge",
62
+ onChange: function (self) { },
63
+ styleName: "light", // "light" ("classic": its old name), "dark", "modern" or a name added to Gauge.styles
64
+ style: { // Light style package (default)
65
+ track: {
66
+ color: Black(0.08),
67
+ width: 12,
68
+ },
69
+ bar: {
70
+ color: "cadetblue",
71
+ width: 12,
72
+ roundCap: 1,
73
+ },
74
+ marker: {
75
+ color: Black(0.65),
76
+ width: 3,
77
+ length: 18, // It goes this long across the arc.
78
+ },
79
+ value: {
80
+ fontSize: 38,
81
+ textColor: Black(0.85),
82
+ bold: 1,
83
+ offsetY: null, // null: by itself. (Middle of a ring, over the chord of an arc.)
84
+ },
85
+ sub: {
86
+ fontSize: 13,
87
+ textColor: Black(0.5),
88
+ offsetY: null, // null: right under the value.
89
+ },
90
+ title: {
91
+ fontSize: 13,
92
+ textColor: "", // "": the color of the bar.
93
+ gap: 12, // Space between the gauge and the title.
94
+ },
95
+ },
96
+ };
97
+
98
+ const Gauge = function (params = {}) {
99
+
100
+ // Merge style package: params.style > Gauge.styles[styleName] > GaugeDefaults.style (light)
101
+ basic.applyStylePackage(params, Gauge.styles, GaugeDefaults);
102
+
103
+ // Merge params:
104
+ mergeIntoIfMissing(params, GaugeDefaults);
105
+ params.color = params.color || "transparent";
106
+
107
+ // BOX: Component container
108
+ let box = startObject(params);
109
+
110
+ const _s = box.style;
111
+
112
+ // *** PRIVATE VARIABLES:
113
+
114
+ let svg = null; // The <svg> element
115
+ let elements = {}; // bar, marker, value, sub, title
116
+ const FULL_RING_SWEEP = 359.9; // WHY: A sweep this big is drawn as a full ring (rounding of the angles).
117
+ const VIEW_PADDING = 2; // Extra room around the arc in the viewBox.
118
+ const TEXT_BOTTOM_ROOM = 4; // Room under the baseline of a text.
119
+ const SUB_GAP = 8; // Space between the value and the line under it.
120
+ const RING_VALUE_SHIFT = 0.35; // x the font size: down, to the middle of a ring.
121
+ const ARC_VALUE_SHIFT = 0.25; // x the font size: up, over the chord of an arc.
122
+ const TITLE_BOTTOM_ROOM = 0.4; // x the font size of the title.
123
+ const MARKER_DURATION_RATIO = 0.7; // x duration: the marker turns a bit faster than the bar.
124
+ const COLOR_DURATION_RATIO = 0.6; // x duration: the color change of the bar.
125
+
126
+ // *** PRIVATE FUNCTIONS:
127
+
128
+ // A point on the arc. 0 is the top and the angles grow clockwise.
129
+ const pointOf = function (cx, cy, r, angle) {
130
+ const rad = (angle - 90) * Math.PI / 180;
131
+ return { x: cx + r * Math.cos(rad), y: cy + r * Math.sin(rad) };
132
+ };
133
+
134
+ const isFullRing = function (sweep) {
135
+ return Math.abs(sweep) >= FULL_RING_SWEEP;
136
+ };
137
+
138
+ // The path of the arc. A full circle can not be drawn with one A command, it takes two.
139
+ const arcPath = function (cx, cy, r, start, sweep) {
140
+
141
+ if (isFullRing(sweep)) {
142
+ const a = pointOf(cx, cy, r, start);
143
+ const b = pointOf(cx, cy, r, start + 180);
144
+ return "M" + a.x.toFixed(2) + " " + a.y.toFixed(2) +
145
+ " A" + r + " " + r + " 0 1 1 " + b.x.toFixed(2) + " " + b.y.toFixed(2) +
146
+ " A" + r + " " + r + " 0 1 1 " + a.x.toFixed(2) + " " + a.y.toFixed(2);
147
+ }
148
+
149
+ const a = pointOf(cx, cy, r, start);
150
+ const b = pointOf(cx, cy, r, start + sweep);
151
+ const largeArc = (Math.abs(sweep) > 180) ? 1 : 0;
152
+ const sweepFlag = (sweep > 0) ? 1 : 0;
153
+
154
+ return "M" + a.x.toFixed(2) + " " + a.y.toFixed(2) +
155
+ " A" + r + " " + r + " 0 " + largeArc + " " + sweepFlag + " " + b.x.toFixed(2) + " " + b.y.toFixed(2);
156
+
157
+ };
158
+
159
+ // What the arc really covers. WHY: A half arc in a square box leaves an empty half.
160
+ const arcBounds = function (cx, cy, r, start, sweep) {
161
+
162
+ const from = Math.min(start, start + sweep);
163
+ const to = Math.max(start, start + sweep);
164
+ const points = [pointOf(cx, cy, r, start), pointOf(cx, cy, r, start + sweep)];
165
+
166
+ // The top, right, bottom and left of the circle, when they are inside the sweep.
167
+ for (let angle = -720; angle <= 720; angle += 90) {
168
+ if (angle >= from && angle <= to) points.push(pointOf(cx, cy, r, angle));
169
+ }
170
+
171
+ return {
172
+ minX: Math.min.apply(null, points.map(function (p) { return p.x; })),
173
+ maxX: Math.max.apply(null, points.map(function (p) { return p.x; })),
174
+ minY: Math.min.apply(null, points.map(function (p) { return p.y; })),
175
+ maxY: Math.max.apply(null, points.map(function (p) { return p.y; })),
176
+ };
177
+
178
+ };
179
+
180
+ // 0..1: where the value is between minValue and maxValue.
181
+ const ratioOf = function (value) {
182
+ const span = box.maxValue - box.minValue;
183
+ if (!span) return 0;
184
+ return Math.max(0, Math.min(1, (value - box.minValue) / span));
185
+ };
186
+
187
+ const angleOf = function (value) {
188
+ return box.startAngle + box.sweepAngle * ratioOf(value);
189
+ };
190
+
191
+ const textOfValue = function () {
192
+ if (box.valueText !== "") return box.valueText;
193
+ return Number(box.value).toFixed(box.decimals) + box.valueSuffix;
194
+ };
195
+
196
+ // The y of the value text, from the middle of the arc.
197
+ const valueOffsetOf = function () {
198
+ if (_s.value.offsetY !== null) return _s.value.offsetY;
199
+ if (isFullRing(box.sweepAngle)) return _s.value.fontSize * RING_VALUE_SHIFT;
200
+ return -_s.value.fontSize * ARC_VALUE_SHIFT;
201
+ };
202
+
203
+ const subOffsetOf = function (valueOffset) {
204
+ if (_s.sub.offsetY !== null) return _s.sub.offsetY;
205
+ return valueOffset + _s.sub.fontSize + SUB_GAP;
206
+ };
207
+
208
+ // The viewBox and the places of the texts.
209
+ const measureView = function (cx, cy) {
210
+
211
+ const r = box.radius;
212
+ const strokeMax = Math.max(_s.track.width, _s.bar.width);
213
+ const markerRoom = (box.markerValue === null) ? 0 : _s.marker.length / 2;
214
+ const pad = strokeMax / 2 + markerRoom + VIEW_PADDING;
215
+
216
+ const bounds = arcBounds(cx, cy, r, box.startAngle, box.sweepAngle);
217
+
218
+ const view = {
219
+ minX: bounds.minX - pad,
220
+ maxX: bounds.maxX + pad,
221
+ minY: bounds.minY - pad,
222
+ maxY: bounds.maxY + pad,
223
+ valueOffset: valueOffsetOf(),
224
+ subOffset: 0,
225
+ titleY: 0,
226
+ };
227
+ view.subOffset = subOffsetOf(view.valueOffset);
228
+
229
+ // The texts live around the middle of the arc, they can be lower than the arc itself.
230
+ if (box.subText) view.maxY = Math.max(view.maxY, cy + view.subOffset + TEXT_BOTTOM_ROOM);
231
+ if (box.valueText !== "" || box.value !== null) view.maxY = Math.max(view.maxY, cy + view.valueOffset + TEXT_BOTTOM_ROOM);
232
+
233
+ if (box.titleText) {
234
+ view.titleY = view.maxY + _s.title.gap;
235
+ view.maxY = view.titleY + _s.title.fontSize * TITLE_BOTTOM_ROOM;
236
+ }
237
+
238
+ return view;
239
+
240
+ };
241
+
242
+ // The marker is drawn at the top and turned to its own angle.
243
+ const markerHtmlOf = function (cx, cy) {
244
+
245
+ if (box.markerValue === null) return "";
246
+
247
+ const r = box.radius;
248
+ return "<line class='gauge-marker' x1='" + cx + "' y1='" + (cy - r - _s.marker.length / 2) + "' x2='" + cx + "' y2='" + (cy - r + _s.marker.length / 2) + "'" +
249
+ " stroke='" + _s.marker.color + "' stroke-width='" + _s.marker.width + "' stroke-linecap='round'" +
250
+ " style='transition: transform " + (box.duration * MARKER_DURATION_RATIO) + "ms'/>";
251
+
252
+ };
253
+
254
+ const titleHtmlOf = function (cx, titleY) {
255
+
256
+ if (!box.titleText) return "";
257
+
258
+ const titleColor = _s.title.textColor || _s.bar.color;
259
+ return "<text class='gauge-title' x='" + cx + "' y='" + titleY + "' text-anchor='middle'" +
260
+ " style='fill:" + titleColor + "; font-size:" + _s.title.fontSize + "px'></text>";
261
+
262
+ };
263
+
264
+ // Writes the whole SVG again. (Only when a size or a style changed.)
265
+ const build = function () {
266
+
267
+ const cx = 0, cy = 0;
268
+ const view = measureView(cx, cy);
269
+
270
+ const path = arcPath(cx, cy, box.radius, box.startAngle, box.sweepAngle);
271
+ const cap = (_s.bar.roundCap) ? "round" : "butt";
272
+
273
+ box.elem.innerHTML =
274
+ "<svg viewBox='" + view.minX.toFixed(2) + " " + view.minY.toFixed(2) + " " + (view.maxX - view.minX).toFixed(2) + " " + (view.maxY - view.minY).toFixed(2) + "'" +
275
+ " style='display:block; width:100%; height:100%; overflow:visible' role='img' aria-label='" + box.ariaLabel + "'>" +
276
+
277
+ "<path d='" + path + "' fill='none' stroke='" + _s.track.color + "' stroke-width='" + _s.track.width + "' stroke-linecap='" + cap + "'/>" +
278
+
279
+ "<path class='gauge-bar' d='" + path + "' fill='none' stroke='" + _s.bar.color + "' stroke-width='" + _s.bar.width + "'" +
280
+ " stroke-linecap='" + cap + "' pathLength='100' stroke-dasharray='0 100'" +
281
+ " style='transition: stroke-dasharray " + box.duration + "ms, stroke " + (box.duration * COLOR_DURATION_RATIO) + "ms'/>" +
282
+
283
+ markerHtmlOf(cx, cy) +
284
+
285
+ "<text class='gauge-value' x='" + cx + "' y='" + (cy + view.valueOffset) + "' text-anchor='middle'" +
286
+ " style='fill:" + _s.value.textColor + "; font-size:" + _s.value.fontSize + "px;" + ((_s.value.bold) ? " font-weight:bold;" : "") + "'></text>" +
287
+
288
+ "<text class='gauge-sub' x='" + cx + "' y='" + (cy + view.subOffset) + "' text-anchor='middle'" +
289
+ " style='fill:" + _s.sub.textColor + "; font-size:" + _s.sub.fontSize + "px'></text>" +
290
+
291
+ titleHtmlOf(cx, view.titleY) +
292
+
293
+ "</svg>";
294
+
295
+ svg = box.elem.querySelector("svg");
296
+ elements = {
297
+ bar: svg.querySelector(".gauge-bar"),
298
+ marker: svg.querySelector(".gauge-marker"),
299
+ value: svg.querySelector(".gauge-value"),
300
+ sub: svg.querySelector(".gauge-sub"),
301
+ title: svg.querySelector(".gauge-title"),
302
+ };
303
+
304
+ paint();
305
+
306
+ };
307
+
308
+ // Writes the values into the SVG that is already there.
309
+ const paint = function () {
310
+
311
+ if (!elements.bar) return;
312
+
313
+ elements.bar.setAttribute("stroke-dasharray", (ratioOf(box.value) * 100).toFixed(2) + " 100");
314
+ elements.value.textContent = textOfValue();
315
+ elements.sub.textContent = box.subText;
316
+ if (elements.title) elements.title.textContent = box.titleText;
317
+
318
+ if (elements.marker) {
319
+ const angle = angleOf(box.markerValue);
320
+ elements.marker.setAttribute("transform", "rotate(" + angle.toFixed(2) + " 0 0)");
321
+ }
322
+
323
+ };
324
+
325
+ // *** PUBLIC FUNCTIONS:
326
+
327
+ box.setValue = function (value, silent = 0) {
328
+ if (value === box.value) return; // the same value: nothing to draw, no onChange
329
+ box.value = value;
330
+ paint();
331
+ if (!silent) box.onChange(box);
332
+ };
333
+ // USAGE: get: gauge.value, set: gauge.setValue(72)
334
+
335
+ box.setMarkerValue = function (value) {
336
+ const wasOff = (box.markerValue === null);
337
+ box.markerValue = value;
338
+ const isOff = (value === null);
339
+ if (wasOff !== isOff) {
340
+ build(); // The marker appeared or went away.
341
+ return;
342
+ }
343
+ paint();
344
+ };
345
+
346
+ box.setBarColor = function (color) {
347
+ _s.bar.color = color;
348
+ if (elements.bar) elements.bar.setAttribute("stroke", color);
349
+ if (elements.title && !_s.title.textColor) elements.title.style.fill = color;
350
+ };
351
+
352
+ box.setValueText = function (text) {
353
+ box.valueText = text;
354
+ paint();
355
+ };
356
+
357
+ box.setValueSuffix = function (text) {
358
+ box.valueSuffix = text;
359
+ paint();
360
+ };
361
+
362
+ box.setSubText = function (text) {
363
+ const wasEmpty = !box.subText;
364
+ box.subText = text;
365
+ if (wasEmpty !== !text) {
366
+ build(); // The drawing area changes with it.
367
+ return;
368
+ }
369
+ paint();
370
+ };
371
+
372
+ box.setTitleText = function (text) {
373
+ const wasEmpty = !box.titleText;
374
+ box.titleText = text;
375
+ if (wasEmpty !== !text) {
376
+ build();
377
+ return;
378
+ }
379
+ paint();
380
+ };
381
+
382
+ box.setRange = function (minValue, maxValue) {
383
+ box.minValue = minValue;
384
+ box.maxValue = maxValue;
385
+ paint();
386
+ };
387
+
388
+ // Draws the whole gauge again. (After a style was changed by hand.)
389
+ box.refresh = function () {
390
+ build();
391
+ };
392
+
393
+
394
+ // *** OBJECT VIEW:
395
+
396
+ box.position = box.position || "relative";
397
+
398
+ // *** OBJECT INIT CODE:
399
+
400
+ build();
401
+
402
+ return endObject(box);
403
+
404
+ };
405
+
406
+ // *** STYLE PACKAGES:
407
+ // USAGE: Gauge({ styleName: "dark" })
408
+ // USAGE: Gauge({ styleName: "dark", style: { track: { color: "tomato" } } }) // Change only some keys.
409
+ // USAGE: Gauge({ style: Gauge.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
410
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
411
+ // USAGE: Gauge.styles.myStyle = { track: { color: "red" } };
412
+
413
+ Gauge.styles = {
414
+
415
+ // On a light card.
416
+ light: GaugeDefaults.style,
417
+
418
+ // On a dark card. The same colors as the "dark" Tabs, Stepper and SidePanel.
419
+ dark: {
420
+ track: { color: "rgba(255, 255, 255, 0.07)", width: 12 },
421
+ bar: { color: "#65A293", width: 12, roundCap: 1 },
422
+ marker: { color: "rgba(255, 255, 255, 0.85)", width: 3, length: 18 },
423
+ value: { fontSize: 38, textColor: "rgba(255, 255, 255, 0.95)", bold: 1, offsetY: null },
424
+ sub: { fontSize: 13, textColor: "rgba(255, 255, 255, 0.5)", offsetY: null },
425
+ title: { fontSize: 13, textColor: "", gap: 12 },
426
+ },
427
+
428
+ // Thinner, round, cadetblue. The same colors as the modern Tabs and Stepper.
429
+ modern: {
430
+ track: { color: "#DFECEC", width: 10 },
431
+ bar: { color: "cadetblue", width: 10, roundCap: 1 },
432
+ marker: { color: "#2F5F61", width: 3, length: 16 },
433
+ value: { fontSize: 36, textColor: "#2F5F61", bold: 1, offsetY: null },
434
+ sub: { fontSize: 13, textColor: "#6E9A9B", offsetY: null },
435
+ title: { fontSize: 13, textColor: "", gap: 12 },
436
+ },
437
+
438
+ };
439
+ Gauge.styles.classic = Gauge.styles.light; // the old name of light: the pages made with it keep their look