@@ -151,10 +151,14 @@ async function loadList(resource) {
151151( function stats ( ) {
152152 const el = document . getElementById ( "stats" ) ;
153153 if ( ! el ) return ;
154- const order = [ "smartphones" , "tablets" , "watches" , "pdas" , "socs" , "gpus" , "cpus" , "brands" ] ;
154+ const order = [ "games" , "software" , " smartphones", "laptops" , " tablets" , "monitors ", "watches" , "pdas" , "socs" , "gpus" , "cpus" , "brands" ] ;
155155 const label = {
156+ games : "games" ,
157+ software : "software" ,
156158 smartphones : "phones" ,
159+ laptops : "laptops" ,
157160 tablets : "tablets" ,
161+ monitors : "monitors" ,
158162 watches : "watches" ,
159163 pdas : "pdas" ,
160164 socs : "socs" ,
@@ -164,25 +168,20 @@ async function loadList(resource) {
164168 } ;
165169 getJSON ( "v1/index.json" ) . then ( ( m ) => {
166170 el . innerHTML = "" ;
167- for ( const k of order ) {
171+ const keys = [
172+ ...order . filter ( ( key ) => m . collections ?. [ key ] ?. count != null ) ,
173+ ...Object . keys ( m . collections || { } ) . filter ( ( key ) => ! order . includes ( key ) && m . collections [ key ] ?. count != null ) ,
174+ ] ;
175+ for ( const k of keys ) {
168176 const col = m . collections ?. [ k ] ;
169177 const total = col ?. count ;
170178 if ( total == null ) continue ;
171- // "scored / total" when the dump exposes a benchmarked count; else plain total.
172- const scored = col . scored ?? col . benchmarked ?? col . with_scores ?? null ;
173- const num = scored == null ? total : scored ;
174- const den = scored == null ? "" : `<span class="den">/${ total . toLocaleString ( ) } </span>` ;
175179 el . insertAdjacentHTML ( "beforeend" ,
176- `<div class="stat"><div class="n"><span class="num" data-n="${ num } ">0</span>${ den } </div><div class="l">${ label [ k ] } </div></div>` ) ;
180+ `<div class="stat"><div class="n"><span class="num" data-n="${ total } ">0</span></div><div class="l">${ label [ k ] || k } </div></div>` ) ;
177181 }
178- const obs = new IntersectionObserver ( ( entries ) => {
179- entries . forEach ( ( e ) => {
180- if ( ! e . isIntersecting ) return ;
181- el . querySelectorAll ( ".num" ) . forEach ( ( n ) => countUp ( n , + n . dataset . n ) ) ;
182- obs . disconnect ( ) ;
183- } ) ;
184- } , { threshold : .4 } ) ;
185- obs . observe ( el ) ;
182+ // The hero is already in view at first paint. Animate immediately so the
183+ // counters do not remain at zero when IntersectionObserver is delayed.
184+ el . querySelectorAll ( ".num" ) . forEach ( ( n ) => countUp ( n , + n . dataset . n ) ) ;
186185 } ) . catch ( ( ) => {
187186 el . innerHTML = '<div class="stat"><div class="n">—</div><div class="l">build data first</div></div>' ;
188187 } ) ;
@@ -209,10 +208,14 @@ function countUp(node, target, opts = {}) {
209208 const listEl = document . getElementById ( "history-list" ) ;
210209 if ( ! totalEl || ! countsEl || ! chartEl || ! listEl ) return ;
211210
212- const order = [ "smartphones" , "tablets" , "watches" , "pdas" , "socs" , "gpus" , "cpus" , "brands" ] ;
211+ const order = [ "games" , "software" , " smartphones", "laptops" , " tablets" , "monitors ", "watches" , "pdas" , "socs" , "gpus" , "cpus" , "brands" ] ;
213212 const label = {
213+ games : "Games" ,
214+ software : "Software" ,
214215 smartphones : "Phones" ,
216+ laptops : "Laptops" ,
215217 tablets : "Tablets" ,
218+ monitors : "Monitors" ,
216219 watches : "Watches" ,
217220 pdas : "PDAs" ,
218221 socs : "SoCs" ,
@@ -221,8 +224,12 @@ function countUp(node, target, opts = {}) {
221224 brands : "Brands" ,
222225 } ;
223226 const shortLabel = {
227+ games : "games" ,
228+ software : "software" ,
224229 smartphones : "phones" ,
230+ laptops : "laptops" ,
225231 tablets : "tablets" ,
232+ monitors : "monitors" ,
226233 watches : "watches" ,
227234 pdas : "pdas" ,
228235 socs : "socs" ,
@@ -231,9 +238,14 @@ function countUp(node, target, opts = {}) {
231238 brands : "brands" ,
232239 } ;
233240 const dumpPath = "site/public/v1/index.json" ;
234- const countRows = ( manifest ) => order
235- . map ( ( key ) => ( { key, count : manifest . collections ?. [ key ] ?. count } ) )
236- . filter ( ( row ) => row . count != null ) ;
241+ const countRows = ( manifest ) => {
242+ const collections = manifest . collections || { } ;
243+ const keys = [
244+ ...order . filter ( ( key ) => collections [ key ] ?. count != null ) ,
245+ ...Object . keys ( collections ) . filter ( ( key ) => ! order . includes ( key ) && collections [ key ] ?. count != null ) ,
246+ ] ;
247+ return keys . map ( ( key ) => ( { key, count : collections [ key ] . count } ) ) ;
248+ } ;
237249 const totalRecords = ( manifest ) => countRows ( manifest ) . reduce ( ( sum , row ) => sum + row . count , 0 ) ;
238250 const sumByKey = ( rows ) => rows . reduce ( ( out , row ) => {
239251 out [ row . key ] = row . count ;
0 commit comments