Spaces:
Running
Running
update app
Browse files- index.html +44 -23
index.html
CHANGED
|
@@ -748,11 +748,11 @@
|
|
| 748 |
.graph-canvas-wrap {
|
| 749 |
position: relative;
|
| 750 |
margin: 16px;
|
| 751 |
-
padding:
|
| 752 |
background: #ffffff;
|
| 753 |
border: 3px solid #000000;
|
| 754 |
box-shadow: 6px 6px 0 #000000;
|
| 755 |
-
height:
|
| 756 |
}
|
| 757 |
|
| 758 |
#likeCanvas {
|
|
@@ -2148,19 +2148,27 @@
|
|
| 2148 |
const data = getVisibleSeries();
|
| 2149 |
if (!data.length) return;
|
| 2150 |
|
| 2151 |
-
|
| 2152 |
-
const
|
| 2153 |
-
const
|
| 2154 |
-
const
|
| 2155 |
-
const
|
| 2156 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2157 |
|
| 2158 |
const maxDaily = Math.max(1, ...data.map(d => d.total));
|
| 2159 |
const maxCum = Math.max(1, ...data.map(d => d.cumulative));
|
| 2160 |
const minCum = data.length > 1 ? Math.max(0, data[0].cumulative - data[0].total) : 0;
|
| 2161 |
const cumSpan = Math.max(1, maxCum - minCum);
|
| 2162 |
|
| 2163 |
-
state.chartGeom = { padL, padR, padT, padB, plotW, plotH, W, H, data };
|
| 2164 |
|
| 2165 |
const firstDate = data[0].date;
|
| 2166 |
const lastDate = data[data.length - 1].date;
|
|
@@ -2171,6 +2179,7 @@
|
|
| 2171 |
ctx.font = '700 10px "Montserrat", sans-serif';
|
| 2172 |
const gridSteps = 4;
|
| 2173 |
|
|
|
|
| 2174 |
for (let i = 0; i <= gridSteps; i++) {
|
| 2175 |
const frac = i / gridSteps;
|
| 2176 |
const y = padT + plotH - frac * plotH;
|
|
@@ -2188,35 +2197,45 @@
|
|
| 2188 |
ctx.fillStyle = '#000000';
|
| 2189 |
ctx.textAlign = 'right';
|
| 2190 |
ctx.textBaseline = 'middle';
|
| 2191 |
-
ctx.fillText(formatNum(leftVal), padL -
|
| 2192 |
|
| 2193 |
if (state.chartMode === 'combined') {
|
| 2194 |
const rightVal = Math.round(minCum + frac * cumSpan);
|
| 2195 |
ctx.fillStyle = '#000000';
|
| 2196 |
ctx.textAlign = 'left';
|
| 2197 |
-
ctx.fillText(formatNum(rightVal), padL + plotW +
|
| 2198 |
}
|
| 2199 |
}
|
| 2200 |
|
| 2201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2202 |
ctx.fillStyle = '#000000';
|
| 2203 |
ctx.textAlign = 'center';
|
| 2204 |
ctx.textBaseline = 'top';
|
| 2205 |
|
| 2206 |
for (let t = 0; t < tickCount; t++) {
|
| 2207 |
const idx = Math.min(data.length - 1, Math.round((t / Math.max(1, tickCount - 1)) * (data.length - 1)));
|
| 2208 |
-
const x =
|
| 2209 |
ctx.fillText(data[idx].date.slice(5), x, padT + plotH + 10);
|
| 2210 |
}
|
| 2211 |
|
| 2212 |
-
|
| 2213 |
-
const stepX = n > 1 ? plotW / (n - 1) : plotW;
|
| 2214 |
-
const barW = Math.max(2, Math.min(20, (plotW / n) * 0.74));
|
| 2215 |
-
|
| 2216 |
if (state.chartMode === 'combined' || state.chartMode === 'daily') {
|
| 2217 |
data.forEach((d, idx) => {
|
| 2218 |
if (d.total <= 0) return;
|
| 2219 |
-
const cx =
|
| 2220 |
const bh = (d.total / maxDaily) * plotH;
|
| 2221 |
const by = padT + plotH - bh;
|
| 2222 |
|
|
@@ -2231,7 +2250,7 @@
|
|
| 2231 |
} else if (state.chartMode === 'breakdown') {
|
| 2232 |
data.forEach((d, idx) => {
|
| 2233 |
if (d.total <= 0) return;
|
| 2234 |
-
const cx =
|
| 2235 |
let curY = padT + plotH;
|
| 2236 |
|
| 2237 |
const segs = [
|
|
@@ -2255,9 +2274,10 @@
|
|
| 2255 |
});
|
| 2256 |
}
|
| 2257 |
|
|
|
|
| 2258 |
if (state.chartMode === 'combined' || state.chartMode === 'cumulative') {
|
| 2259 |
const pts = data.map((d, idx) => ({
|
| 2260 |
-
x:
|
| 2261 |
y: padT + plotH - ((d.cumulative - minCum) / cumSpan) * plotH,
|
| 2262 |
}));
|
| 2263 |
|
|
@@ -2290,10 +2310,11 @@
|
|
| 2290 |
}
|
| 2291 |
}
|
| 2292 |
|
|
|
|
| 2293 |
if (state.hoverIndex >= 0 && state.hoverIndex < data.length) {
|
| 2294 |
const hi = state.hoverIndex;
|
| 2295 |
const hd = data[hi];
|
| 2296 |
-
const hx =
|
| 2297 |
|
| 2298 |
ctx.strokeStyle = '#000000';
|
| 2299 |
ctx.lineWidth = 1.5;
|
|
@@ -2357,7 +2378,7 @@
|
|
| 2357 |
const mx = e.clientX - rect.left;
|
| 2358 |
const my = e.clientY - rect.top;
|
| 2359 |
|
| 2360 |
-
if (mx < g.padL
|
| 2361 |
state.hoverIndex = -1;
|
| 2362 |
els.graphTooltip.style.display = 'none';
|
| 2363 |
drawLikeGraph();
|
|
@@ -2365,7 +2386,7 @@
|
|
| 2365 |
}
|
| 2366 |
|
| 2367 |
const n = g.data.length;
|
| 2368 |
-
const frac = Math.max(0, Math.min(1, (mx - g.
|
| 2369 |
const idx = n === 1 ? 0 : Math.round(frac * (n - 1));
|
| 2370 |
|
| 2371 |
state.hoverIndex = idx;
|
|
|
|
| 748 |
.graph-canvas-wrap {
|
| 749 |
position: relative;
|
| 750 |
margin: 16px;
|
| 751 |
+
padding: 16px 16px 12px 16px;
|
| 752 |
background: #ffffff;
|
| 753 |
border: 3px solid #000000;
|
| 754 |
box-shadow: 6px 6px 0 #000000;
|
| 755 |
+
height: 380px;
|
| 756 |
}
|
| 757 |
|
| 758 |
#likeCanvas {
|
|
|
|
| 2148 |
const data = getVisibleSeries();
|
| 2149 |
if (!data.length) return;
|
| 2150 |
|
| 2151 |
+
// Generous left/right padding and inner plot inset so Y-axis numbers never touch the bars
|
| 2152 |
+
const padL = 68;
|
| 2153 |
+
const padR = state.chartMode === 'combined' ? 72 : 34;
|
| 2154 |
+
const padT = 24;
|
| 2155 |
+
const padB = 36;
|
| 2156 |
+
const plotW = Math.max(20, W - padL - padR);
|
| 2157 |
+
const plotH = Math.max(20, H - padT - padB);
|
| 2158 |
+
|
| 2159 |
+
const n = data.length;
|
| 2160 |
+
const barW = Math.max(2, Math.min(18, (plotW / Math.max(1, n)) * 0.66));
|
| 2161 |
+
const innerPadX = Math.max(18, Math.ceil(barW / 2) + 12);
|
| 2162 |
+
const dataStartX = padL + innerPadX;
|
| 2163 |
+
const dataW = Math.max(10, plotW - innerPadX * 2);
|
| 2164 |
+
const stepX = n > 1 ? dataW / (n - 1) : 0;
|
| 2165 |
|
| 2166 |
const maxDaily = Math.max(1, ...data.map(d => d.total));
|
| 2167 |
const maxCum = Math.max(1, ...data.map(d => d.cumulative));
|
| 2168 |
const minCum = data.length > 1 ? Math.max(0, data[0].cumulative - data[0].total) : 0;
|
| 2169 |
const cumSpan = Math.max(1, maxCum - minCum);
|
| 2170 |
|
| 2171 |
+
state.chartGeom = { padL, padR, padT, padB, plotW, plotH, dataStartX, dataW, W, H, data };
|
| 2172 |
|
| 2173 |
const firstDate = data[0].date;
|
| 2174 |
const lastDate = data[data.length - 1].date;
|
|
|
|
| 2179 |
ctx.font = '700 10px "Montserrat", sans-serif';
|
| 2180 |
const gridSteps = 4;
|
| 2181 |
|
| 2182 |
+
// Horizontal grid lines & Y-axis labels with extra breathing space
|
| 2183 |
for (let i = 0; i <= gridSteps; i++) {
|
| 2184 |
const frac = i / gridSteps;
|
| 2185 |
const y = padT + plotH - frac * plotH;
|
|
|
|
| 2197 |
ctx.fillStyle = '#000000';
|
| 2198 |
ctx.textAlign = 'right';
|
| 2199 |
ctx.textBaseline = 'middle';
|
| 2200 |
+
ctx.fillText(formatNum(leftVal), padL - 14, y);
|
| 2201 |
|
| 2202 |
if (state.chartMode === 'combined') {
|
| 2203 |
const rightVal = Math.round(minCum + frac * cumSpan);
|
| 2204 |
ctx.fillStyle = '#000000';
|
| 2205 |
ctx.textAlign = 'left';
|
| 2206 |
+
ctx.fillText(formatNum(rightVal), padL + plotW + 14, y);
|
| 2207 |
}
|
| 2208 |
}
|
| 2209 |
|
| 2210 |
+
// Left & Right Y-axis vertical border lines for clean visual separation
|
| 2211 |
+
ctx.strokeStyle = '#000000';
|
| 2212 |
+
ctx.lineWidth = 2;
|
| 2213 |
+
ctx.beginPath();
|
| 2214 |
+
ctx.moveTo(padL, padT);
|
| 2215 |
+
ctx.lineTo(padL, padT + plotH);
|
| 2216 |
+
if (state.chartMode === 'combined') {
|
| 2217 |
+
ctx.moveTo(padL + plotW, padT);
|
| 2218 |
+
ctx.lineTo(padL + plotW, padT + plotH);
|
| 2219 |
+
}
|
| 2220 |
+
ctx.stroke();
|
| 2221 |
+
|
| 2222 |
+
// X-axis date ticks aligned with inset data positions
|
| 2223 |
+
const tickCount = Math.min(data.length, Math.max(2, Math.floor(dataW / 110)));
|
| 2224 |
ctx.fillStyle = '#000000';
|
| 2225 |
ctx.textAlign = 'center';
|
| 2226 |
ctx.textBaseline = 'top';
|
| 2227 |
|
| 2228 |
for (let t = 0; t < tickCount; t++) {
|
| 2229 |
const idx = Math.min(data.length - 1, Math.round((t / Math.max(1, tickCount - 1)) * (data.length - 1)));
|
| 2230 |
+
const x = dataStartX + (n === 1 ? dataW / 2 : idx * stepX);
|
| 2231 |
ctx.fillText(data[idx].date.slice(5), x, padT + plotH + 10);
|
| 2232 |
}
|
| 2233 |
|
| 2234 |
+
// 1. Render Daily Bars inside inset bounds
|
|
|
|
|
|
|
|
|
|
| 2235 |
if (state.chartMode === 'combined' || state.chartMode === 'daily') {
|
| 2236 |
data.forEach((d, idx) => {
|
| 2237 |
if (d.total <= 0) return;
|
| 2238 |
+
const cx = dataStartX + (n === 1 ? dataW / 2 : idx * stepX);
|
| 2239 |
const bh = (d.total / maxDaily) * plotH;
|
| 2240 |
const by = padT + plotH - bh;
|
| 2241 |
|
|
|
|
| 2250 |
} else if (state.chartMode === 'breakdown') {
|
| 2251 |
data.forEach((d, idx) => {
|
| 2252 |
if (d.total <= 0) return;
|
| 2253 |
+
const cx = dataStartX + (n === 1 ? dataW / 2 : idx * stepX);
|
| 2254 |
let curY = padT + plotH;
|
| 2255 |
|
| 2256 |
const segs = [
|
|
|
|
| 2274 |
});
|
| 2275 |
}
|
| 2276 |
|
| 2277 |
+
// 2. Render Cumulative Growth Curve inside inset bounds
|
| 2278 |
if (state.chartMode === 'combined' || state.chartMode === 'cumulative') {
|
| 2279 |
const pts = data.map((d, idx) => ({
|
| 2280 |
+
x: dataStartX + (n === 1 ? dataW / 2 : idx * stepX),
|
| 2281 |
y: padT + plotH - ((d.cumulative - minCum) / cumSpan) * plotH,
|
| 2282 |
}));
|
| 2283 |
|
|
|
|
| 2310 |
}
|
| 2311 |
}
|
| 2312 |
|
| 2313 |
+
// 3. Hover Crosshair & Highlight Dot
|
| 2314 |
if (state.hoverIndex >= 0 && state.hoverIndex < data.length) {
|
| 2315 |
const hi = state.hoverIndex;
|
| 2316 |
const hd = data[hi];
|
| 2317 |
+
const hx = dataStartX + (n === 1 ? dataW / 2 : hi * stepX);
|
| 2318 |
|
| 2319 |
ctx.strokeStyle = '#000000';
|
| 2320 |
ctx.lineWidth = 1.5;
|
|
|
|
| 2378 |
const mx = e.clientX - rect.left;
|
| 2379 |
const my = e.clientY - rect.top;
|
| 2380 |
|
| 2381 |
+
if (mx < g.padL || mx > g.padL + g.plotW || my < g.padT || my > g.padT + g.plotH) {
|
| 2382 |
state.hoverIndex = -1;
|
| 2383 |
els.graphTooltip.style.display = 'none';
|
| 2384 |
drawLikeGraph();
|
|
|
|
| 2386 |
}
|
| 2387 |
|
| 2388 |
const n = g.data.length;
|
| 2389 |
+
const frac = Math.max(0, Math.min(1, (mx - g.dataStartX) / Math.max(1, g.dataW)));
|
| 2390 |
const idx = n === 1 ? 0 : Math.round(frac * (n - 1));
|
| 2391 |
|
| 2392 |
state.hoverIndex = idx;
|