tokenskyline 0.1.0 → 0.1.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/README.md +3 -0
- package/package.json +3 -2
- package/template.html +57 -27
package/README.md
CHANGED
|
@@ -84,8 +84,11 @@ npx tokenskyline
|
|
|
84
84
|
```bash
|
|
85
85
|
npm test # smoke test; CI runs it on Linux, macOS and Windows with Node 18 and 22
|
|
86
86
|
npm run demo # writes and opens tokenskyline-<year>-demo.html
|
|
87
|
+
npm run variants # builds 8 data shapes into test/out/
|
|
87
88
|
```
|
|
88
89
|
|
|
90
|
+
Then serve the repo folder (`python3 -m http.server`) and open `test/fit.html`: it loads every data shape at 10 desktop screen sizes, in Chinese and English, 3D and flat, and checks that the chart and its caption fit on the first screen, the page never scrolls sideways, and the 3D chart takes at least 28% of the screen height. All 240 combinations pass.
|
|
91
|
+
|
|
89
92
|
`template.html` is the whole page. The CLI inlines the data into it in place of `<script src="data/data.js"></script>`.
|
|
90
93
|
|
|
91
94
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenskyline",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Your year of AI coding as a 3D token skyline. One command reads local logs of Claude Code, Codex, Gemini/Antigravity, Hermes, Cursor, OpenCode and 60+ tools and writes a single HTML file: GitHub-style contribution graph, flat or 3D.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "node test/check.mjs",
|
|
43
|
-
"demo": "node bin/tokenskyline.mjs --demo"
|
|
43
|
+
"demo": "node bin/tokenskyline.mjs --demo",
|
|
44
|
+
"variants": "node test/variants.mjs"
|
|
44
45
|
},
|
|
45
46
|
"repository": {
|
|
46
47
|
"type": "git",
|
package/template.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*{box-sizing:border-box}
|
|
22
22
|
[hidden]{display:none!important}
|
|
23
23
|
body{background:var(--bg);color:var(--ink);font-family:var(--f-body);font-size:14px;line-height:1.5}
|
|
24
|
-
.wrap{max-width:1120px;margin:0 auto;padding-block:40px 64px;padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));display:grid;gap:40px}
|
|
24
|
+
.wrap{max-width:max(1120px,min(82vw,1800px));margin:0 auto;padding-block:clamp(18px,4vh,40px) 64px;padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));display:grid;gap:clamp(22px,4.5vh,40px)}
|
|
25
25
|
.num{font-family:var(--f-mono);font-variant-numeric:tabular-nums}
|
|
26
26
|
.eyebrow{font-family:var(--f-mono);font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:var(--muted);display:flex;flex-wrap:wrap;gap:4px 8px;align-items:baseline}
|
|
27
27
|
.cmd{margin-left:auto;font-family:var(--f-mono);font-size:12px;letter-spacing:0;text-transform:none;color:var(--ink);border:1px solid var(--ink);padding:1px 7px}
|
|
@@ -30,9 +30,18 @@ body{background:var(--bg);color:var(--ink);font-family:var(--f-body);font-size:1
|
|
|
30
30
|
h1,h2{font-family:var(--f-display);font-weight:700;margin:0;text-wrap:balance}
|
|
31
31
|
|
|
32
32
|
/* 顶部 */
|
|
33
|
-
.head{display:grid;gap:18px}
|
|
33
|
+
.head{display:grid;gap:clamp(10px,1.8vh,18px)}
|
|
34
34
|
.hero{display:flex;flex-wrap:wrap;align-items:flex-end;gap:12px 40px;justify-content:space-between}
|
|
35
|
-
.
|
|
35
|
+
.heroL{min-width:0;max-width:min(100%,560px)}
|
|
36
|
+
.heroR{flex:1 1 420px;min-width:0;display:grid;gap:10px;align-content:end}
|
|
37
|
+
.heroR .legend{margin-inline:-9px}
|
|
38
|
+
.chartbox{display:grid;grid-template-columns:minmax(0,1fr)}
|
|
39
|
+
.chartbox.side{grid-template-columns:minmax(250px,290px) minmax(0,1fr);gap:24px;align-items:center}
|
|
40
|
+
.kpiOver .kpis{grid-template-columns:repeat(2,minmax(0,1fr));gap:14px 18px}
|
|
41
|
+
.kpiOver .kpi b{font-size:18px}
|
|
42
|
+
.kpiOver .kpi .sub{font-size:10.5px}
|
|
43
|
+
#bigSub{overflow-wrap:anywhere}
|
|
44
|
+
.big{font-family:var(--f-display);font-weight:700;font-size:clamp(44px,min(10vw,11vh),104px);line-height:.9;letter-spacing:-.03em}
|
|
36
45
|
.big small{font-size:.32em;letter-spacing:0;font-weight:500;margin-left:.25em;color:var(--muted)}
|
|
37
46
|
.kpis{display:grid;grid-template-columns:repeat(4,auto);gap:4px 28px}
|
|
38
47
|
.kpi{display:grid;gap:2px}
|
|
@@ -41,7 +50,11 @@ h1,h2{font-family:var(--f-display);font-weight:700;margin:0;text-wrap:balance}
|
|
|
41
50
|
.kpi .sub{font-family:var(--f-mono);font-size:11px;font-variant-numeric:tabular-nums;border-top:1px solid var(--rule);padding-top:3px;margin-top:2px}
|
|
42
51
|
.share{display:flex;height:10px;width:100%;background:var(--empty)}
|
|
43
52
|
.share i{display:block;height:100%}
|
|
44
|
-
.legend{display:flex;flex-wrap:wrap;gap:6px
|
|
53
|
+
.legend{display:flex;flex-wrap:wrap;gap:2px 6px;font-size:12px;color:var(--muted);margin-inline:-9px}
|
|
54
|
+
.legend .tool{font-size:12px;padding:3px 9px}
|
|
55
|
+
.legend .tool b{color:var(--ink);font-weight:500}
|
|
56
|
+
.legend .more{color:var(--ink);text-decoration:underline;text-underline-offset:3px}
|
|
57
|
+
.legend .tool[aria-pressed="false"]{text-decoration:line-through;text-decoration-color:var(--rule)}
|
|
45
58
|
.legend span{display:inline-flex;align-items:center;gap:6px}
|
|
46
59
|
.legend i{width:9px;height:9px;display:inline-block}
|
|
47
60
|
|
|
@@ -99,14 +112,14 @@ svg text{fill:var(--muted);font-family:var(--f-mono);font-size:10px}
|
|
|
99
112
|
</style>
|
|
100
113
|
|
|
101
114
|
<div class="wrap">
|
|
102
|
-
<header class="head">
|
|
115
|
+
<header class="head" id="head">
|
|
103
116
|
<div class="eyebrow"><span id="yr"></span> · <span id="brand"></span> · <span id="upd"></span><span class="cmd">npx tokenskyline</span></div>
|
|
104
117
|
<div class="hero">
|
|
105
|
-
<div>
|
|
118
|
+
<div class="heroL">
|
|
106
119
|
<div class="big" id="bigNum">—</div>
|
|
107
120
|
<div class="note" id="bigSub"></div>
|
|
108
121
|
</div>
|
|
109
|
-
<div class="kpis" id="kpis"></div>
|
|
122
|
+
<div class="heroR" id="heroR"><div class="kpis" id="kpis"></div></div>
|
|
110
123
|
</div>
|
|
111
124
|
<div class="share" id="share"></div>
|
|
112
125
|
<div class="legend" id="shareLegend"></div>
|
|
@@ -124,10 +137,8 @@ svg text{fill:var(--muted);font-family:var(--f-mono);font-size:10px}
|
|
|
124
137
|
<div class="seg" role="group" id="gRange">
|
|
125
138
|
<button id="rData" aria-pressed="true"></button><button id="rYear" aria-pressed="false"></button>
|
|
126
139
|
</div>
|
|
127
|
-
<div class="grow"></div>
|
|
128
|
-
<div class="tools" id="tools"></div>
|
|
129
140
|
</div>
|
|
130
|
-
<div class="scroll" id="mainScroll"><div id="w2d" hidden><svg id="grid2d"></svg></div><canvas id="cv3"></canvas></div>
|
|
141
|
+
<div class="chartbox"><div class="kpiOver" id="kpiOver" hidden></div><div class="scroll" id="mainScroll"><div id="w2d" hidden><svg id="grid2d"></svg></div><canvas id="cv3"></canvas></div></div>
|
|
131
142
|
<div class="scale" id="scale"></div>
|
|
132
143
|
</section>
|
|
133
144
|
|
|
@@ -159,7 +170,7 @@ const L=ZH?{
|
|
|
159
170
|
usd:"估算美元", none:"未选", estCost:"按官方价估算", perDay:"日均", cacheShare:"缓存读占", allTok:"全部 token",
|
|
160
171
|
days:n=>n+" 天", activeDays:"有用量的日子", since:d=>d+" 起有记录", streak:"最长连续", peak:"最猛一天", led:n=>n+"主导",
|
|
161
172
|
scale2d:"格内分段 = 各家当天占比 · 深浅按分位五档", cuts:"分界", scale3d:"柱高 = 当天真实用量 · 柱内分段 = 各家当天占比",
|
|
162
|
-
rowTip:n=>"点击:在图 1 里加上或去掉 "+n, from:d=>d+" 起", main:"主力", total:"合计", noRec:"没有记录",
|
|
173
|
+
rowTip:n=>"点击:在图 1 里加上或去掉 "+n, more:n=>"+"+n+" 家", from:d=>d+" 起", main:"主力", total:"合计", noRec:"没有记录",
|
|
163
174
|
wd:["一","","三","","五","","日"], weekStart:1,
|
|
164
175
|
foot:(cover,gap)=>`
|
|
165
176
|
<div><b>数据从哪来</b> 本机各家 AI 工具的日志,由开源工具 tokscale 读取,数据只在本机,不上传。每次运行都会把每天的数存进一份本地底账,日志被清理后,统计过的日子不会丢。</div>
|
|
@@ -174,7 +185,7 @@ const L=ZH?{
|
|
|
174
185
|
usd:"est. USD", none:"none", estCost:"at list prices", perDay:"per day", cacheShare:"cache reads", allTok:"all tokens",
|
|
175
186
|
days:n=>n+(n===1?" day":" days"), activeDays:"active days", since:d=>"since "+d, streak:"longest streak", peak:"busiest day", led:n=>"mostly "+n,
|
|
176
187
|
scale2d:"cell split = each tool's share that day · shade = quintile", cuts:"cuts", scale3d:"bar height = real usage that day · segments = each tool's share",
|
|
177
|
-
rowTip:n=>"Click to add or remove "+n+" in fig. 1", from:d=>"since "+d, main:"top model", total:"Total", noRec:"no usage",
|
|
188
|
+
rowTip:n=>"Click to add or remove "+n+" in fig. 1", more:n=>"+"+n+" more", from:d=>"since "+d, main:"top model", total:"Total", noRec:"no usage",
|
|
178
189
|
wd:["","Mon","","Wed","","Fri",""], weekStart:0,
|
|
179
190
|
foot:(cover,gap)=>`
|
|
180
191
|
<div><b>Where the data comes from</b> Local logs of your AI coding tools, read by the open-source tokscale. Nothing leaves your machine. Every run saves each day's totals to a local ledger, so days stay counted after the tools delete their logs.</div>
|
|
@@ -288,8 +299,11 @@ function renderHead(){
|
|
|
288
299
|
].map(([b,s,t])=>`<div class="kpi"><b>${b}</b><span>${s}</span><span class="sub">${t}</span></div>`).join("");
|
|
289
300
|
const sum=Object.values(perTool).reduce((a,b)=>a+b,0)||1;
|
|
290
301
|
$("share").innerHTML=TOOLS.filter(t=>on.has(t.k)).map(t=>`<i style="width:${perTool[t.k]/sum*100}%;background:var(--c-${t.k})" title="${t.n}"></i>`).join("");
|
|
291
|
-
|
|
292
|
-
|
|
302
|
+
const LMAX=8, all=S.legendAll||TOOLS.length<=LMAX, shown=all?TOOLS:TOOLS.slice(0,LMAX-1); // 工具太多时图例只列前 7 家,免得把顶部撑高
|
|
303
|
+
$("shareLegend").innerHTML=shown.map(t=>{const o=on.has(t.k);
|
|
304
|
+
return `<button class="tool" data-k="${t.k}" aria-pressed="${o}" title="${L.rowTip(t.n)}"><i style="background:var(--c-${t.k})"></i>${t.n}`+
|
|
305
|
+
(o?` <b class="num">${(perTool[t.k]/sum*100).toFixed(1)}%</b> <span class="num">${fmt(perTool[t.k])}</span>`:"")+`</button>`}).join("")+
|
|
306
|
+
(all?"":`<button class="tool more" id="legMore">${L.more(TOOLS.length-shown.length)}</button>`);
|
|
293
307
|
}
|
|
294
308
|
|
|
295
309
|
// ---------- 平面网格(SVG) ----------
|
|
@@ -334,22 +348,32 @@ let hexes=[];
|
|
|
334
348
|
function draw3D(dates){
|
|
335
349
|
const cv=$("cv3"), box=$("mainScroll");
|
|
336
350
|
const weeks=Math.ceil(dates.length/7);
|
|
337
|
-
const az=(weeks>30?
|
|
351
|
+
const az=(weeks>30?20:24)*Math.PI/180, el=32*Math.PI/180; // 视角偏平:同样高度下格子更大
|
|
338
352
|
const uxW=Math.cos(az), uyW=Math.sin(az)*Math.sin(el), uxD=-Math.sin(az), uyD=Math.cos(az)*Math.sin(el);
|
|
339
|
-
const W=Math.max(
|
|
340
|
-
|
|
353
|
+
const W=Math.max(480,box.clientWidth), padL=40, padR=72;
|
|
354
|
+
let step=(W-padL-padR)/(weeks*uxW+7*Math.abs(uxD));
|
|
355
|
+
// 一屏放下:格子和柱高一起缩,直到整张图塞进"图顶到窗口底"的剩余高度
|
|
356
|
+
const top=box.getBoundingClientRect().top+scrollY;
|
|
357
|
+
const budget=Math.max(220,innerHeight-top-62);
|
|
358
|
+
const mhCap=Math.max(200,budget*.45); // 大屏上柱子也能长高
|
|
359
|
+
step=Math.min(step,Math.max(34,budget/11));
|
|
360
|
+
const mhOf=s=>Math.min(mhCap,Math.max(80,s*5));
|
|
361
|
+
const need=s=>(weeks*uyW+7*uyD)*s+mhOf(s)+plDepth+60;
|
|
362
|
+
const plDepth=6;
|
|
363
|
+
while(step>6&&need(step)>budget)step*=.94;
|
|
341
364
|
const span=step*(weeks*uxW+7*Math.abs(uxD));
|
|
342
|
-
const cR=.8, plD=
|
|
365
|
+
const cR=.8, plD=plDepth, pad=.35;
|
|
343
366
|
const vals=dates.map(d=>dayParts(ymd(d),S.on).reduce((s,p)=>s+p[1],0));
|
|
344
367
|
const maxV=Math.max(...vals,0);
|
|
345
|
-
const maxH=
|
|
368
|
+
const maxH=mhOf(step);
|
|
346
369
|
const hOf=v=>v>0&&maxV>0?Math.max(3.5,v/maxV*maxH):0; // 柱高 = 真实比例
|
|
347
370
|
const ox=(W-span)/2+7*Math.abs(uxD)*step+ (padL-padR)/2;
|
|
348
371
|
const rawY=(w,d,z)=>w*uyW*step+d*uyD*step-z;
|
|
349
372
|
let minY=Math.min(rawY(-pad,-pad,0),rawY(weeks,-pad,maxH));
|
|
350
373
|
dates.forEach((d,i)=>{const y=rawY(Math.floor(i/7),i%7,hOf(vals[i]));if(y<minY)minY=y});
|
|
351
374
|
const maxY=rawY(weeks-.2+pad,7-.2+pad,0)+plD+24;
|
|
352
|
-
const
|
|
375
|
+
const sideH=$("kpiOver").hidden?0:$("kpiOver").offsetHeight;
|
|
376
|
+
const H0=Math.ceil(18-minY+maxY+10), H=Math.max(H0,sideH), oy=18-minY+(H-H0)/2; // 不矮于左侧指标栏,图在其中垂直居中
|
|
353
377
|
const dpr=Math.min(devicePixelRatio||1,3);
|
|
354
378
|
cv.width=W*dpr;cv.height=H*dpr;cv.style.width=W+"px";cv.style.height=H+"px";
|
|
355
379
|
const g=cv.getContext("2d");g.setTransform(dpr,0,0,dpr,0,0);g.clearRect(0,0,W,H);
|
|
@@ -410,14 +434,23 @@ function renderRows(dates){
|
|
|
410
434
|
}
|
|
411
435
|
|
|
412
436
|
// ---------- 渲染 ----------
|
|
437
|
+
function placeLayout(){
|
|
438
|
+
const wide=S.view==="3d"&&innerWidth>=980;
|
|
439
|
+
// 立体 + 宽屏:指标竖排在图左侧一栏(永不和图重叠),份额条和图例上到大数字右边
|
|
440
|
+
if(wide){ $("heroR").append($("share"),$("shareLegend")); $("kpiOver").append($("kpis")); $("kpiOver").hidden=false }
|
|
441
|
+
else { $("heroR").append($("kpis")); $("head").append($("share"),$("shareLegend")); $("kpiOver").hidden=true }
|
|
442
|
+
document.querySelector(".chartbox").classList.toggle("side",wide);
|
|
443
|
+
}
|
|
413
444
|
function render(){
|
|
445
|
+
placeLayout();
|
|
414
446
|
readColors();
|
|
415
447
|
const dates=rangeDates();
|
|
416
448
|
renderHead();
|
|
417
449
|
const box=$("mainScroll");
|
|
418
450
|
if(S.view==="2d"){
|
|
419
451
|
$("w2d").hidden=false;$("cv3").hidden=true;
|
|
420
|
-
const
|
|
452
|
+
const room=Math.max(160,innerHeight-(box.getBoundingClientRect().top+scrollY)-62);
|
|
453
|
+
const r=gridSVG($("grid2d"),dates,S.on,{width:box.clientWidth,min:9,max:Math.min(S.range==="year"?20:46,Math.floor((room-16)/7)),labels:true});
|
|
421
454
|
const cut=r.lv.cut||[];
|
|
422
455
|
$("scale").innerHTML=`${L.scale2d} ${[1,2,3,4,5].map(l=>`<i style="background:${mix(C.ink,C.empty,LV[l]*.85)}"></i>`).join("")} <span class="num">${L.cuts} ${cut.map(fmt).join(" / ")}</span>`;
|
|
423
456
|
}else{
|
|
@@ -461,14 +494,11 @@ seg(["v3d","v2d"],"view",["3d","2d"]);
|
|
|
461
494
|
seg(["mTotal","mNoCache","mCost"],"metric",["total","nocache","cost"]);
|
|
462
495
|
seg(["rData","rYear"],"range",["data","year"]);
|
|
463
496
|
$("v3d").setAttribute("aria-pressed",S.view==="3d");$("v2d").setAttribute("aria-pressed",S.view==="2d");
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
document.querySelectorAll(".tool").forEach(x=>x.setAttribute("aria-pressed",S.on.has(x.dataset.k)));render()}
|
|
467
|
-
$("tools").addEventListener("click",e=>{const b=e.target.closest(".tool");if(b)toggle(b.dataset.k)});
|
|
497
|
+
function toggle(k){if(S.on.has(k)){if(S.on.size===1)return;S.on.delete(k)}else S.on.add(k);render()}
|
|
498
|
+
$("shareLegend").addEventListener("click",e=>{if(e.target.closest(".more")){S.legendAll=true;render();return}const b=e.target.closest(".tool");if(b)toggle(b.dataset.k)});
|
|
468
499
|
$("rows").addEventListener("click",e=>{const r=e.target.closest(".row");if(r)toggle(r.dataset.k)});
|
|
469
500
|
// 双击某家 = 只看它
|
|
470
|
-
$("
|
|
471
|
-
document.querySelectorAll(".tool").forEach(x=>x.setAttribute("aria-pressed",S.on.has(x.dataset.k)));render()});
|
|
501
|
+
$("shareLegend").addEventListener("dblclick",e=>{const b=e.target.closest(".tool");if(!b)return;S.on=new Set([b.dataset.k]);render()});
|
|
472
502
|
|
|
473
503
|
const g=new Date(D.generatedAt);
|
|
474
504
|
$("brand").textContent=L.brand;
|