stats-gl 2.4.2 → 3.0.1
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/dist/main.cjs +122 -55
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +122 -55
- package/dist/main.js.map +1 -1
- package/dist/panel.cjs +42 -19
- package/dist/panel.cjs.map +1 -1
- package/dist/panel.js +42 -19
- package/dist/panel.js.map +1 -1
- package/dist/stats-gl.d.ts +19 -8
- package/lib/main.ts +168 -66
- package/lib/panel.ts +66 -42
- package/package.json +1 -1
package/lib/panel.ts
CHANGED
|
@@ -40,6 +40,7 @@ class Panel {
|
|
|
40
40
|
this.canvas.style.cssText = 'width:90px;height:48px';
|
|
41
41
|
|
|
42
42
|
this.context = this.canvas.getContext('2d');
|
|
43
|
+
|
|
43
44
|
this.initializeCanvas();
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -57,17 +58,17 @@ class Panel {
|
|
|
57
58
|
const endColor: string = this.fg;
|
|
58
59
|
|
|
59
60
|
switch (this.fg.toLowerCase()) {
|
|
60
|
-
case '#0ff':
|
|
61
|
-
startColor = '#006666';
|
|
61
|
+
case '#0ff':
|
|
62
|
+
startColor = '#006666';
|
|
62
63
|
break;
|
|
63
|
-
case '#0f0':
|
|
64
|
-
startColor = '#006600';
|
|
64
|
+
case '#0f0':
|
|
65
|
+
startColor = '#006600';
|
|
65
66
|
break;
|
|
66
|
-
case '#ff0':
|
|
67
|
-
startColor = '#666600';
|
|
67
|
+
case '#ff0':
|
|
68
|
+
startColor = '#666600';
|
|
68
69
|
break;
|
|
69
|
-
case '#e1e1e1':
|
|
70
|
-
startColor = '#666666';
|
|
70
|
+
case '#e1e1e1':
|
|
71
|
+
startColor = '#666666';
|
|
71
72
|
break;
|
|
72
73
|
default:
|
|
73
74
|
startColor = this.bg;
|
|
@@ -83,44 +84,33 @@ class Panel {
|
|
|
83
84
|
private initializeCanvas() {
|
|
84
85
|
if (!this.context) return;
|
|
85
86
|
|
|
87
|
+
this.context.imageSmoothingEnabled = false;
|
|
88
|
+
|
|
86
89
|
this.context.font = 'bold ' + (9 * this.PR) + 'px Helvetica,Arial,sans-serif';
|
|
87
90
|
this.context.textBaseline = 'top';
|
|
88
91
|
|
|
89
|
-
// Create gradient
|
|
90
92
|
this.gradient = this.createGradient();
|
|
91
93
|
|
|
92
|
-
// Fill background
|
|
93
94
|
this.context.fillStyle = this.bg;
|
|
94
95
|
this.context.fillRect(0, 0, this.WIDTH, this.HEIGHT);
|
|
95
96
|
|
|
96
|
-
// Draw text
|
|
97
97
|
this.context.fillStyle = this.fg;
|
|
98
98
|
this.context.fillText(this.name, this.TEXT_X, this.TEXT_Y);
|
|
99
99
|
|
|
100
|
-
// Draw initial graph area
|
|
101
|
-
this.context.fillStyle = this.fg;
|
|
102
|
-
this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT);
|
|
103
100
|
|
|
104
|
-
// Apply semi-transparent background
|
|
105
101
|
this.context.fillStyle = this.bg;
|
|
106
102
|
this.context.globalAlpha = 0.9;
|
|
107
103
|
this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT);
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
valueGraph: number,
|
|
113
|
-
maxValue: number,
|
|
114
|
-
maxGraph: number,
|
|
115
|
-
decimals = 0
|
|
116
|
-
) {
|
|
106
|
+
// Update only text portion
|
|
107
|
+
update(value: number, valueGraph: number, maxValue: number, maxGraph: number, decimals = 0) {
|
|
117
108
|
if (!this.context || !this.gradient) return;
|
|
118
109
|
|
|
119
110
|
const min = Math.min(Infinity, value);
|
|
120
111
|
const max = Math.max(maxValue, value);
|
|
121
|
-
maxGraph = Math.max(maxGraph, valueGraph);
|
|
122
112
|
|
|
123
|
-
// Clear
|
|
113
|
+
// Clear only the text area (from top to GRAPH_Y)
|
|
124
114
|
this.context.globalAlpha = 1;
|
|
125
115
|
this.context.fillStyle = this.bg;
|
|
126
116
|
this.context.fillRect(0, 0, this.WIDTH, this.GRAPH_Y);
|
|
@@ -128,40 +118,74 @@ class Panel {
|
|
|
128
118
|
// Draw text
|
|
129
119
|
this.context.fillStyle = this.fg;
|
|
130
120
|
this.context.fillText(
|
|
131
|
-
`${value.toFixed(decimals)} ${this.name} (${min.toFixed(decimals)}-${parseFloat(
|
|
132
|
-
max.toFixed(decimals)
|
|
133
|
-
)})`,
|
|
121
|
+
`${value.toFixed(decimals)} ${this.name} (${min.toFixed(decimals)}-${parseFloat(max.toFixed(decimals))})`,
|
|
134
122
|
this.TEXT_X,
|
|
135
123
|
this.TEXT_Y
|
|
136
124
|
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Update only graph portion
|
|
128
|
+
updateGraph(valueGraph: number, maxGraph: number) {
|
|
129
|
+
if (!this.context || !this.gradient) return;
|
|
130
|
+
|
|
131
|
+
// Handle zero values appropriately
|
|
132
|
+
if (valueGraph === 0 && maxGraph === 0) {
|
|
133
|
+
maxGraph = 1; // Prevent division by zero
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Ensure maxGraph is valid and values are positive
|
|
137
|
+
maxGraph = Math.max(maxGraph, valueGraph, 0.1);
|
|
138
|
+
valueGraph = Math.max(valueGraph, 0);
|
|
139
|
+
|
|
140
|
+
// Ensure all coordinates are rounded to avoid sub-pixel rendering
|
|
141
|
+
const graphX = Math.round(this.GRAPH_X);
|
|
142
|
+
const graphY = Math.round(this.GRAPH_Y);
|
|
143
|
+
const graphWidth = Math.round(this.GRAPH_WIDTH);
|
|
144
|
+
const graphHeight = Math.round(this.GRAPH_HEIGHT);
|
|
145
|
+
const pr = Math.round(this.PR);
|
|
137
146
|
|
|
138
147
|
// Shift the graph left
|
|
139
148
|
this.context.drawImage(
|
|
140
149
|
this.canvas,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
graphX + pr,
|
|
151
|
+
graphY,
|
|
152
|
+
graphWidth - pr,
|
|
153
|
+
graphHeight,
|
|
154
|
+
graphX,
|
|
155
|
+
graphY,
|
|
156
|
+
graphWidth - pr,
|
|
157
|
+
graphHeight
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Clear only the new column area
|
|
161
|
+
this.context.fillStyle = this.bg;
|
|
162
|
+
this.context.fillRect(
|
|
163
|
+
graphX + graphWidth - pr,
|
|
164
|
+
graphY,
|
|
165
|
+
pr,
|
|
166
|
+
graphHeight
|
|
149
167
|
);
|
|
150
168
|
|
|
151
|
-
//
|
|
152
|
-
const columnHeight =
|
|
169
|
+
// Calculate column height
|
|
170
|
+
const columnHeight = Math.min(
|
|
171
|
+
graphHeight,
|
|
172
|
+
Math.round(valueGraph / maxGraph * graphHeight)
|
|
173
|
+
);
|
|
153
174
|
|
|
175
|
+
// Draw the gradient column
|
|
154
176
|
if (columnHeight > 0) {
|
|
155
|
-
this.context.globalAlpha =
|
|
177
|
+
this.context.globalAlpha = 0.9;
|
|
156
178
|
this.context.fillStyle = this.gradient;
|
|
157
179
|
this.context.fillRect(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
180
|
+
graphX + graphWidth - pr,
|
|
181
|
+
graphY + (graphHeight - columnHeight),
|
|
182
|
+
pr,
|
|
161
183
|
columnHeight
|
|
162
184
|
);
|
|
163
185
|
}
|
|
186
|
+
|
|
187
|
+
this.context.globalAlpha = 1;
|
|
164
188
|
}
|
|
165
189
|
}
|
|
166
190
|
|
|
167
|
-
export { Panel };
|
|
191
|
+
export { Panel };
|