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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Component: LineProgressBar
|
|
6
|
+
Version: 1.3
|
|
7
|
+
Created: November 2025
|
|
8
|
+
Description: A progress bar component composed of vertical lines.
|
|
9
|
+
|
|
10
|
+
- The lines: lineWidth, lineGap and lineRound ("full": the top and the bottom are half
|
|
11
|
+
circles). headGrow: 1 (default) makes the line at the progress and its two neighbors wider and longer; 0: every
|
|
12
|
+
line is the same. primaryColor: the full lines; secondaryColor: the empty ones.
|
|
13
|
+
- valueBubble: 1 shows the value all the time in a bubble of comp/tooltip.js (load it first) over the last full
|
|
14
|
+
line, its arrow pointing at it (valueBubbleLook: the keys of Tooltip.BUBBLE_LOOK; its color is primaryColor).
|
|
15
|
+
showValueLabel: the small label that shows for a moment when the value changes.
|
|
16
|
+
- animated: 1 (context/basic-js-animated-rules.md): the bubble slides to a new value in 0.25 s
|
|
17
|
+
(a transform from where it is seen, so a quick row of values is one smooth way); it does not slide at the first
|
|
18
|
+
view, with a scroll or a resize, nor when the system asks for reduced motion. setAnimated(0/1).
|
|
19
|
+
- 0% has no full line (one line was full at 0%).
|
|
20
|
+
|
|
21
|
+
USAGE:
|
|
22
|
+
const bar = LineProgressBar({ width: 300, height: 40, showValueLabel: true });
|
|
23
|
+
bar.setProgress(45); // 0 to 100
|
|
24
|
+
const upload = LineProgressBar({ width: 360, height: 36, lineWidth: 6, lineGap: 4, lineRound: "full", headGrow: 0,
|
|
25
|
+
primaryColor: "#7BC362", secondaryColor: "#E2E1DD", valueBubble: 1 }); // thick round lines, a bubble
|
|
26
|
+
upload.setPrimaryColor("#52A8D0");
|
|
27
|
+
|
|
28
|
+
WHY the name: comp/progress-bar.js is the standard "ProgressBar"; this one draws lines.
|
|
29
|
+
|
|
30
|
+
Created by AI (Antigravity Gemini)
|
|
31
|
+
|
|
32
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
33
|
+
|
|
34
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
35
|
+
Licensed under the Apache License, Version 2.0
|
|
36
|
+
SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
"use strict";
|
|
41
|
+
|
|
42
|
+
const LineProgressBarDefaults = {
|
|
43
|
+
width: 300,
|
|
44
|
+
height: 50,
|
|
45
|
+
progress: 0, // 0 to 100
|
|
46
|
+
primaryColor: "indianred", // the full lines
|
|
47
|
+
secondaryColor: "lightgray", // the empty lines
|
|
48
|
+
lineWidth: 1, // px
|
|
49
|
+
lineGap: 3, // px between two lines
|
|
50
|
+
lineRound: 3, // px, or "full": the top and the bottom of a line are half circles
|
|
51
|
+
headGrow: 1, // 1: the line at the progress and its two neighbors are wider and longer; 0: every line the same
|
|
52
|
+
showValueLabel: false, // the value in a small label for a moment when it changes
|
|
53
|
+
valueBubble: 0, // 1: the value all the time in a bubble with an arrow over the last full line (comp/tooltip.js)
|
|
54
|
+
valueBubbleLook: {}, // the keys of Tooltip.BUBBLE_LOOK (its color: primaryColor)
|
|
55
|
+
animated: 0, // 1: the bubble of the value slides to a new value (box.setAnimated(0/1))
|
|
56
|
+
backgroundColor: "transparent",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const LineProgressBar = function (params = {}) {
|
|
60
|
+
|
|
61
|
+
// Merge params
|
|
62
|
+
mergeIntoIfMissing(params, LineProgressBarDefaults);
|
|
63
|
+
|
|
64
|
+
// BOX: Component container
|
|
65
|
+
const box = startObject(params);
|
|
66
|
+
box.clipContent = 0; // WHY: The head of the progress and the value label stand out of the box.
|
|
67
|
+
|
|
68
|
+
// *** PRIVATE VARIABLES:
|
|
69
|
+
const UNIT_WIDTH = box.lineWidth + box.lineGap;
|
|
70
|
+
const LINE_ROUND = (box.lineRound === "full") ? box.lineWidth / 2 : box.lineRound;
|
|
71
|
+
// The line at the progress (the head) and its two neighbors are wider and longer (overhang: px at the top and the bottom).
|
|
72
|
+
const HEAD_LOOK = { width: box.lineWidth * 3, overhang: 2, zIndex: 10, color: "black" };
|
|
73
|
+
const NEIGHBOR_LOOK = { width: box.lineWidth * 2, overhang: 1, zIndex: 5 };
|
|
74
|
+
const VALUE_LABEL_TOP = -25; // Above the lines
|
|
75
|
+
const VALUE_LABEL_SHOW_TIME = 1000; // ms after the last change
|
|
76
|
+
const VALUE_BUBBLE_Z_INDEX = 2; // over the content of the page (and over a Dialog that holds the bar: zIndexAbove)
|
|
77
|
+
// MOTION (animated: 1)
|
|
78
|
+
const MOTION_TIME = "0.25s";
|
|
79
|
+
const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start, a soft stop
|
|
80
|
+
|
|
81
|
+
let totalLines = 0; // follows the width of the box (0 while it is not drawn: a closed tab, a hidden group)
|
|
82
|
+
const lines = [];
|
|
83
|
+
let lineContainer = null;
|
|
84
|
+
|
|
85
|
+
let valueLabel = null;
|
|
86
|
+
let cancelValueLabelHide = null; // The cancel function of the waiting hide (box.after)
|
|
87
|
+
let valueBubble = null;
|
|
88
|
+
let isBubblePlaceWaiting = 0;
|
|
89
|
+
let isCreated = 0; // WHY: nothing moves at the first view
|
|
90
|
+
|
|
91
|
+
// *** PUBLIC VARIABLES:
|
|
92
|
+
box.currentProgress = box.progress;
|
|
93
|
+
|
|
94
|
+
// *** PRIVATE FUNCTIONS:
|
|
95
|
+
const countLines = function () {
|
|
96
|
+
return Math.max(0, Math.floor(box.width / UNIT_WIDTH));
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const createLines = function () {
|
|
100
|
+
|
|
101
|
+
lineContainer = Box({
|
|
102
|
+
width: "100%",
|
|
103
|
+
height: "100%",
|
|
104
|
+
color: "transparent",
|
|
105
|
+
position: "absolute",
|
|
106
|
+
left: 0,
|
|
107
|
+
top: 0,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
buildLines();
|
|
111
|
+
|
|
112
|
+
if (box.showValueLabel) createValueLabel();
|
|
113
|
+
if (box.valueBubble == 1) createValueBubble();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// WHY again on a resize: the lines were made once from the width at create time. A bar made in a closed tab or
|
|
117
|
+
// a hidden group ("100%": width 0) had no lines, and lineContainer.add(...[]) threw: the start() of the page
|
|
118
|
+
// stopped there, with its started boxes left open.
|
|
119
|
+
const buildLines = function () {
|
|
120
|
+
lines.forEach(function (line) { line.remove(); });
|
|
121
|
+
lines.length = 0;
|
|
122
|
+
totalLines = countLines();
|
|
123
|
+
createIn(lineContainer, function () {
|
|
124
|
+
for (let i = 0; i < totalLines; i++) {
|
|
125
|
+
lines.push(Box({
|
|
126
|
+
width: box.lineWidth,
|
|
127
|
+
height: box.height,
|
|
128
|
+
left: i * UNIT_WIDTH,
|
|
129
|
+
top: 0,
|
|
130
|
+
color: box.secondaryColor,
|
|
131
|
+
position: "absolute",
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const createValueLabel = function () {
|
|
138
|
+
valueLabel = Label({
|
|
139
|
+
text: "0%",
|
|
140
|
+
fontSize: 12,
|
|
141
|
+
color: box.primaryColor,
|
|
142
|
+
textColor: "white",
|
|
143
|
+
position: "absolute",
|
|
144
|
+
opacity: 0, // Shown only while the progress changes
|
|
145
|
+
width: "auto",
|
|
146
|
+
height: "auto",
|
|
147
|
+
padding: [6, 2],
|
|
148
|
+
round: 100,
|
|
149
|
+
});
|
|
150
|
+
box.add(valueLabel); // WHY: In the box, not in the line container: it stays over the lines.
|
|
151
|
+
valueLabel.setMotion("opacity 0.3s");
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// How many lines are full (0%: none, 100%: all)
|
|
155
|
+
const getFullCount = function () {
|
|
156
|
+
return Math.round((box.currentProgress / 100) * totalLines);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// The index of the head line: the last full one (-1: no full line)
|
|
160
|
+
const getHeadIndex = function () {
|
|
161
|
+
return getFullCount() - 1;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// A wider line keeps the center of a normal line: it moves left by half of the extra width.
|
|
165
|
+
const getLineLook = function (index, headIndex) {
|
|
166
|
+
const normalLeft = index * UNIT_WIDTH;
|
|
167
|
+
const look = {
|
|
168
|
+
color: (index <= headIndex) ? box.primaryColor : box.secondaryColor,
|
|
169
|
+
width: box.lineWidth,
|
|
170
|
+
overhang: 0,
|
|
171
|
+
zIndex: 0,
|
|
172
|
+
};
|
|
173
|
+
if (box.headGrow == 1) {
|
|
174
|
+
if (index === headIndex) Object.assign(look, HEAD_LOOK);
|
|
175
|
+
if (index === headIndex - 1 || index === headIndex + 1) Object.assign(look, NEIGHBOR_LOOK);
|
|
176
|
+
}
|
|
177
|
+
look.left = normalLeft - (look.width - box.lineWidth) / 2;
|
|
178
|
+
return look;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const paintLines = function (headIndex) {
|
|
182
|
+
for (let i = 0; i < totalLines; i++) {
|
|
183
|
+
const look = getLineLook(i, headIndex);
|
|
184
|
+
const line = lines[i];
|
|
185
|
+
line.color = look.color;
|
|
186
|
+
line.width = look.width;
|
|
187
|
+
line.height = box.height + (look.overhang * 2);
|
|
188
|
+
line.top = -look.overhang;
|
|
189
|
+
line.left = look.left;
|
|
190
|
+
line.round = LINE_ROUND;
|
|
191
|
+
line.opacity = 1;
|
|
192
|
+
line.zIndex = look.zIndex;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// The center of the head line. No head line (no full line, no lines): 0.
|
|
197
|
+
const getHeadCenter = function (headIndex) {
|
|
198
|
+
if (headIndex < 0) return 0;
|
|
199
|
+
const look = getLineLook(headIndex, headIndex);
|
|
200
|
+
return look.left + (look.width / 2);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// The label shows the value over the head line for a short time.
|
|
204
|
+
const showValueLabel = function (headIndex) {
|
|
205
|
+
valueLabel.text = Math.round(box.currentProgress) + "%";
|
|
206
|
+
valueLabel.top = VALUE_LABEL_TOP;
|
|
207
|
+
valueLabel.left = getHeadCenter(headIndex);
|
|
208
|
+
valueLabel.css.transform = "translateX(-50%)"; // WHY: Its center (not its left side) is over the head line.
|
|
209
|
+
valueLabel.opacity = 1;
|
|
210
|
+
valueLabel.color = box.primaryColor;
|
|
211
|
+
|
|
212
|
+
if (cancelValueLabelHide) cancelValueLabelHide();
|
|
213
|
+
cancelValueLabelHide = box.after(VALUE_LABEL_SHOW_TIME, function () {
|
|
214
|
+
valueLabel.opacity = 0;
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// *** THE VALUE BUBBLE (valueBubble: 1): a bubble of comp/tooltip.js on page, over the last full line
|
|
219
|
+
|
|
220
|
+
const createValueBubble = function () {
|
|
221
|
+
if (typeof Tooltip === "undefined") {
|
|
222
|
+
console.warn("LineProgressBar: valueBubble needs comp/tooltip.js (Tooltip).");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const look = Object.assign({ color: box.primaryColor }, box.valueBubbleLook);
|
|
226
|
+
look.zIndex = basic.zIndexAbove(box, VALUE_BUBBLE_Z_INDEX);
|
|
227
|
+
valueBubble = Tooltip.createBubble("", look);
|
|
228
|
+
box.own(valueBubble); // (it is on page: it goes with the bar)
|
|
229
|
+
box.listenTo(window, "scroll", queueBubblePlace, true); // WHY capture: the scroll of a box does not bubble up
|
|
230
|
+
box.onPageResize(placeValueBubble);
|
|
231
|
+
// WHY: a text measured before its font came is narrower; the bubble is placed again when the fonts are ready
|
|
232
|
+
if (document.fonts && document.fonts.status != "loaded") document.fonts.ready.then(placeValueBubble);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// The point of the arrow: the top of the last full line (no full line: the left end of the bar)
|
|
236
|
+
const getBubbleTarget = function () {
|
|
237
|
+
const headIndex = getHeadIndex();
|
|
238
|
+
if (headIndex >= 0) return Tooltip.toPageRect(lines[headIndex]);
|
|
239
|
+
const rect = Tooltip.toPageRect(box);
|
|
240
|
+
return { left: rect.left, top: rect.top, width: 0, height: rect.height };
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const isMotionOn = function () {
|
|
244
|
+
if (box.animated != 1) return false;
|
|
245
|
+
return !(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// The middle of the top of the bubble as it is seen now, in the px of the page (its transform too)
|
|
249
|
+
const getBubblePoint = function () {
|
|
250
|
+
const rect = valueBubble.elem.getBoundingClientRect();
|
|
251
|
+
return Tooltip.toPagePoint(rect.left + rect.width / 2, rect.top);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// The bubble is seen only while the bar is (a closed tab, a box scrolled away).
|
|
255
|
+
// isSliding: a new value: the bubble slides from where it is seen to its new place (animated)
|
|
256
|
+
const placeValueBubble = function (isSliding = false) {
|
|
257
|
+
if (!valueBubble || valueBubble._isRemoved) return;
|
|
258
|
+
const isShown = (totalLines > 0 && Tooltip.isInSight(box));
|
|
259
|
+
const canSlide = (isSliding === true && isCreated && isMotionOn() && valueBubble.visible == 1);
|
|
260
|
+
const from = (canSlide) ? getBubblePoint() : null;
|
|
261
|
+
valueBubble.visible = isShown ? 1 : 0;
|
|
262
|
+
if (!isShown) return;
|
|
263
|
+
if (box.animated == 1) {
|
|
264
|
+
valueBubble.setMotionNow("none");
|
|
265
|
+
valueBubble.css = { transform: "none" };
|
|
266
|
+
}
|
|
267
|
+
valueBubble.label.plainText = Math.round(box.currentProgress) + "%";
|
|
268
|
+
Tooltip.place(valueBubble, getBubbleTarget(), "top");
|
|
269
|
+
if (from) slideBubbleFrom(from);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// WHY a transform (not left / top): only transform and opacity move (the rules); the bubble is put at its new
|
|
273
|
+
// place at once, moved back to where it was seen, and then it goes to its place
|
|
274
|
+
const slideBubbleFrom = function (from) {
|
|
275
|
+
const to = getBubblePoint();
|
|
276
|
+
valueBubble.css = { transform: "translate(" + (from.x - to.x) + "px, " + (from.y - to.y) + "px)" };
|
|
277
|
+
void valueBubble.elem.offsetHeight; // WHY: the start look must be drawn before the motion is turned on
|
|
278
|
+
valueBubble.setMotionNow("transform " + MOTION_TIME + " " + MOTION_EASE);
|
|
279
|
+
valueBubble.css = { transform: "none" };
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// Once a frame while a box scrolls
|
|
283
|
+
const queueBubblePlace = function () {
|
|
284
|
+
if (isBubblePlaceWaiting) return;
|
|
285
|
+
isBubblePlaceWaiting = 1;
|
|
286
|
+
requestAnimationFrame(function () {
|
|
287
|
+
isBubblePlaceWaiting = 0;
|
|
288
|
+
placeValueBubble();
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const updateVisuals = function () {
|
|
293
|
+
const headIndex = getHeadIndex();
|
|
294
|
+
paintLines(headIndex);
|
|
295
|
+
if (box.showValueLabel && valueLabel) showValueLabel(headIndex);
|
|
296
|
+
placeValueBubble(true);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// *** PUBLIC FUNCTIONS:
|
|
300
|
+
box.setProgress = function (val) {
|
|
301
|
+
if (val < 0) val = 0;
|
|
302
|
+
if (val > 100) val = 100;
|
|
303
|
+
box.currentProgress = val;
|
|
304
|
+
updateVisuals();
|
|
305
|
+
};
|
|
306
|
+
// USAGE: get: bar.currentProgress, set: bar.setProgress(60)
|
|
307
|
+
|
|
308
|
+
// The color of the full lines (and of the bubble, when its look has no color of its own)
|
|
309
|
+
box.setPrimaryColor = function (color) {
|
|
310
|
+
box.primaryColor = color;
|
|
311
|
+
if (valueBubble && !box.valueBubbleLook.color) Tooltip.paintBubble(valueBubble, color);
|
|
312
|
+
if (valueLabel) valueLabel.color = color;
|
|
313
|
+
paintLines(getHeadIndex());
|
|
314
|
+
};
|
|
315
|
+
// USAGE: bar.setPrimaryColor("#52A8D0")
|
|
316
|
+
|
|
317
|
+
// The color of the empty lines
|
|
318
|
+
box.setSecondaryColor = function (color) {
|
|
319
|
+
box.secondaryColor = color;
|
|
320
|
+
paintLines(getHeadIndex());
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
box.setAnimated = function (value) {
|
|
324
|
+
box.animated = (value == 1) ? 1 : 0;
|
|
325
|
+
if (box.animated != 1 && valueBubble) {
|
|
326
|
+
valueBubble.setMotionNow("none");
|
|
327
|
+
valueBubble.css = { transform: "none" };
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
// USAGE: bar.setAnimated(1)
|
|
331
|
+
|
|
332
|
+
// *** OBJECT INIT CODE:
|
|
333
|
+
createLines();
|
|
334
|
+
updateVisuals();
|
|
335
|
+
box.onResize(function () {
|
|
336
|
+
if (countLines() !== totalLines) buildLines();
|
|
337
|
+
paintLines(getHeadIndex()); // (not updateVisuals: the value label shows only when the value changes)
|
|
338
|
+
placeValueBubble();
|
|
339
|
+
});
|
|
340
|
+
isCreated = 1;
|
|
341
|
+
|
|
342
|
+
return endObject(box);
|
|
343
|
+
};
|