@@ -288,6 +288,7 @@ type PaletteRankEntry = {
288288 key : string
289289 label : string
290290 total : number
291+ excludedFromRank ?: boolean
291292}
292293
293294function formatDatasetTooltip ( projectName : string | undefined ) : string | undefined {
@@ -330,16 +331,40 @@ function buildPaletteColorsByDownloadRank(
330331 const colorsByKey = new Map < string , string > ( )
331332 if ( palette . length === 0 ) return colorsByKey
332333
333- const sortedEntries = [ ...entries ] . sort (
334- ( a , b ) => b . total - a . total || a . label . localeCompare ( b . label ) || a . key . localeCompare ( b . key ) ,
335- )
334+ const compareEntries = ( a : PaletteRankEntry , b : PaletteRankEntry ) =>
335+ b . total - a . total || a . label . localeCompare ( b . label ) || a . key . localeCompare ( b . key )
336+ const rankedEntries = entries . filter ( ( entry ) => ! entry . excludedFromRank ) . sort ( compareEntries )
337+ const excludedEntries = entries . filter ( ( entry ) => entry . excludedFromRank ) . sort ( compareEntries )
338+ const sortedEntries = [ ...rankedEntries , ...excludedEntries ]
339+
336340 sortedEntries . forEach ( ( entry , index ) => {
337341 colorsByKey . set ( entry . key , getPaletteColorForIndex ( index , palette ) )
338342 } )
339343
340344 return colorsByKey
341345}
342346
347+ function isExcludedFromPaletteRank ( breakdownValues : readonly string [ ] ) : boolean {
348+ return breakdownValues . some (
349+ ( value ) =>
350+ isUnknownAnalyticsBreakdownValue ( value ) || isNoDependentAnalyticsBreakdownValue ( value ) ,
351+ )
352+ }
353+
354+ function buildPaletteRankEntry (
355+ key : string ,
356+ breakdownValues : readonly string [ ] ,
357+ total : number ,
358+ formatLabel : ( breakdownValues : readonly string [ ] ) => string ,
359+ ) : PaletteRankEntry {
360+ return {
361+ key,
362+ label : formatLabel ( breakdownValues ) ,
363+ total,
364+ excludedFromRank : isExcludedFromPaletteRank ( breakdownValues ) ,
365+ }
366+ }
367+
343368export function getMetricValue (
344369 point : Labrinth . Analytics . v3 . ProjectAnalytics ,
345370 activeStat : AnalyticsDashboardStat ,
@@ -499,11 +524,14 @@ export function buildChartDatasets(
499524 } )
500525
501526 const colorsByBreakdown = buildPaletteColorsByDownloadRank (
502- Array . from ( dataByBreakdown . keys ( ) ) . map ( ( breakdownKey ) => ( {
503- key : breakdownKey ,
504- label : formatChartBreakdownLabels ( breakdownValuesByKey . get ( breakdownKey ) ?? [ ] ) ,
505- total : downloadTotalsByBreakdown . get ( breakdownKey ) ?? 0 ,
506- } ) ) ,
527+ Array . from ( dataByBreakdown . keys ( ) ) . map ( ( breakdownKey ) =>
528+ buildPaletteRankEntry (
529+ breakdownKey ,
530+ breakdownValuesByKey . get ( breakdownKey ) ?? [ ] ,
531+ downloadTotalsByBreakdown . get ( breakdownKey ) ?? 0 ,
532+ formatChartBreakdownLabels ,
533+ ) ,
534+ ) ,
507535 palette ,
508536 )
509537
@@ -675,11 +703,14 @@ export function buildChartDatasets(
675703 } )
676704
677705 const colorsByBreakdown = buildPaletteColorsByDownloadRank (
678- Array . from ( dataByProjectBreakdown . keys ( ) ) . map ( ( breakdownKey ) => ( {
679- key : breakdownKey ,
680- label : formatChartBreakdownLabels ( breakdownValuesByKey . get ( breakdownKey ) ?? [ ] ) ,
681- total : downloadTotalsByProjectBreakdown . get ( breakdownKey ) ?? 0 ,
682- } ) ) ,
706+ Array . from ( dataByProjectBreakdown . keys ( ) ) . map ( ( breakdownKey ) =>
707+ buildPaletteRankEntry (
708+ breakdownKey ,
709+ breakdownValuesByKey . get ( breakdownKey ) ?? [ ] ,
710+ downloadTotalsByProjectBreakdown . get ( breakdownKey ) ?? 0 ,
711+ formatChartBreakdownLabels ,
712+ ) ,
713+ ) ,
683714 palette ,
684715 )
685716
0 commit comments