stats-gl 2.4.1 → 3.0.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.
- package/dist/main.cjs +123 -55
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +123 -55
- package/dist/main.js.map +1 -1
- package/dist/panel.cjs +42 -17
- package/dist/panel.cjs.map +1 -1
- package/dist/panel.js +42 -17
- package/dist/panel.js.map +1 -1
- package/dist/stats-gl.d.ts +20 -8
- package/lib/main.ts +169 -63
- package/lib/panel.ts +66 -40
- 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,35 @@ 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
100
|
this.context.fillStyle = this.fg;
|
|
102
101
|
this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT);
|
|
103
102
|
|
|
104
|
-
// Apply semi-transparent background
|
|
105
103
|
this.context.fillStyle = this.bg;
|
|
106
104
|
this.context.globalAlpha = 0.9;
|
|
107
105
|
this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT);
|
|
108
106
|
}
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
valueGraph: number,
|
|
113
|
-
maxValue: number,
|
|
114
|
-
maxGraph: number,
|
|
115
|
-
decimals = 0
|
|
116
|
-
) {
|
|
108
|
+
// Update only text portion
|
|
109
|
+
update(value: number, valueGraph: number, maxValue: number, maxGraph: number, decimals = 0) {
|
|
117
110
|
if (!this.context || !this.gradient) return;
|
|
118
111
|
|
|
119
112
|
const min = Math.min(Infinity, value);
|
|
120
113
|
const max = Math.max(maxValue, value);
|
|
121
|
-
maxGraph = Math.max(maxGraph, valueGraph);
|
|
122
114
|
|
|
123
|
-
// Clear
|
|
115
|
+
// Clear only the text area (from top to GRAPH_Y)
|
|
124
116
|
this.context.globalAlpha = 1;
|
|
125
117
|
this.context.fillStyle = this.bg;
|
|
126
118
|
this.context.fillRect(0, 0, this.WIDTH, this.GRAPH_Y);
|
|
@@ -128,40 +120,74 @@ class Panel {
|
|
|
128
120
|
// Draw text
|
|
129
121
|
this.context.fillStyle = this.fg;
|
|
130
122
|
this.context.fillText(
|
|
131
|
-
`${value.toFixed(decimals)} ${this.name} (${min.toFixed(decimals)}-${parseFloat(
|
|
132
|
-
max.toFixed(decimals)
|
|
133
|
-
)})`,
|
|
123
|
+
`${value.toFixed(decimals)} ${this.name} (${min.toFixed(decimals)}-${parseFloat(max.toFixed(decimals))})`,
|
|
134
124
|
this.TEXT_X,
|
|
135
125
|
this.TEXT_Y
|
|
136
126
|
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Update only graph portion
|
|
130
|
+
updateGraph(valueGraph: number, maxGraph: number) {
|
|
131
|
+
if (!this.context || !this.gradient) return;
|
|
132
|
+
|
|
133
|
+
// Handle zero values appropriately
|
|
134
|
+
if (valueGraph === 0 && maxGraph === 0) {
|
|
135
|
+
maxGraph = 1; // Prevent division by zero
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Ensure maxGraph is valid and values are positive
|
|
139
|
+
maxGraph = Math.max(maxGraph, valueGraph, 0.1);
|
|
140
|
+
valueGraph = Math.max(valueGraph, 0);
|
|
141
|
+
|
|
142
|
+
// Ensure all coordinates are rounded to avoid sub-pixel rendering
|
|
143
|
+
const graphX = Math.round(this.GRAPH_X);
|
|
144
|
+
const graphY = Math.round(this.GRAPH_Y);
|
|
145
|
+
const graphWidth = Math.round(this.GRAPH_WIDTH);
|
|
146
|
+
const graphHeight = Math.round(this.GRAPH_HEIGHT);
|
|
147
|
+
const pr = Math.round(this.PR);
|
|
137
148
|
|
|
138
149
|
// Shift the graph left
|
|
139
150
|
this.context.drawImage(
|
|
140
151
|
this.canvas,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
graphX + pr,
|
|
153
|
+
graphY,
|
|
154
|
+
graphWidth - pr,
|
|
155
|
+
graphHeight,
|
|
156
|
+
graphX,
|
|
157
|
+
graphY,
|
|
158
|
+
graphWidth - pr,
|
|
159
|
+
graphHeight
|
|
149
160
|
);
|
|
150
161
|
|
|
151
|
-
//
|
|
152
|
-
|
|
162
|
+
// Clear only the new column area
|
|
163
|
+
this.context.fillStyle = this.bg;
|
|
164
|
+
this.context.fillRect(
|
|
165
|
+
graphX + graphWidth - pr,
|
|
166
|
+
graphY,
|
|
167
|
+
pr,
|
|
168
|
+
graphHeight
|
|
169
|
+
);
|
|
153
170
|
|
|
171
|
+
// Calculate column height
|
|
172
|
+
const columnHeight = Math.min(
|
|
173
|
+
graphHeight,
|
|
174
|
+
Math.round(valueGraph / maxGraph * graphHeight)
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// Draw the gradient column
|
|
154
178
|
if (columnHeight > 0) {
|
|
155
|
-
this.context.globalAlpha =
|
|
179
|
+
this.context.globalAlpha = 0.9;
|
|
156
180
|
this.context.fillStyle = this.gradient;
|
|
157
181
|
this.context.fillRect(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
182
|
+
graphX + graphWidth - pr,
|
|
183
|
+
graphY + (graphHeight - columnHeight),
|
|
184
|
+
pr,
|
|
161
185
|
columnHeight
|
|
162
186
|
);
|
|
163
187
|
}
|
|
188
|
+
|
|
189
|
+
this.context.globalAlpha = 1;
|
|
164
190
|
}
|
|
165
191
|
}
|
|
166
192
|
|
|
167
|
-
export { Panel };
|
|
193
|
+
export { Panel };
|