Introducing metrics insights! (#228)
This commit is contained in:
@@ -31,4 +31,5 @@ It is also possible to use a predefined set of colors from [colorsets.json](colo
|
||||
plugin_languages_colors: "0:orange, javascript:#ff0000, ..." # Make most used languages orange and JavaScript red
|
||||
plugin_languages_details: bytes-size, percentage # Additionally display total bytes size and percentage
|
||||
plugin_languages_threshold: 2% # Hides all languages less than 2%
|
||||
plugin_languages_limit: 8 # Display up to 8 languages
|
||||
```
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {ignored, skipped, colors, details, threshold} = imports.metadata.plugins.languages.inputs({data, account, q})
|
||||
let {ignored, skipped, colors, details, threshold, limit} = imports.metadata.plugins.languages.inputs({data, account, q})
|
||||
threshold = (Number(threshold.replace(/%$/, ""))||0)/100
|
||||
if (!limit)
|
||||
limit = Infinity
|
||||
|
||||
//Custom colors
|
||||
const colorsets = JSON.parse(`${await imports.fs.readFile(`${imports.__module(import.meta.url)}/colorsets.json`)}`)
|
||||
if (`${colors}` in colorsets)
|
||||
if ((`${colors}` in colorsets)&&(limit <= 8))
|
||||
colors = colorsets[`${colors}`]
|
||||
colors = Object.fromEntries(decodeURIComponent(colors).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x).map(x => x.split(":").map(x => x.trim())))
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > custom colors ${JSON.stringify(colors)}`)
|
||||
@@ -42,7 +44,7 @@
|
||||
|
||||
//Compute languages stats
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > computing stats`)
|
||||
languages.favorites = Object.entries(languages.stats).sort(([_an, a], [_bn, b]) => b - a).slice(0, 8).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0})).filter(({value}) => value/languages.total > threshold)
|
||||
languages.favorites = Object.entries(languages.stats).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0})).filter(({value}) => value/languages.total > threshold)
|
||||
const visible = {total:Object.values(languages.favorites).map(({size}) => size).reduce((a, b) => a + b, 0)}
|
||||
for (let i = 0; i < languages.favorites.length; i++) {
|
||||
languages.favorites[i].value /= visible.total
|
||||
|
||||
@@ -30,11 +30,21 @@ inputs:
|
||||
default: ""
|
||||
example: my-repo-1, my-repo-2, owner/repo-3 ...
|
||||
|
||||
# Number of languages to display
|
||||
# Set to 0 to disable limitations
|
||||
plugin_languages_limit:
|
||||
description: Maximum number of languages to display
|
||||
type: number
|
||||
default: 8
|
||||
min: 0
|
||||
max: 8
|
||||
|
||||
# Overrides default languages colors
|
||||
# Use `${n}:${color}` to change the color of the n-th most used language (e.g. "0:red" to make your most used language red)
|
||||
# Use `${language}:${color}` to change the color of named language (e.g. "javascript:red" to make JavaScript language red, language case is ignored)
|
||||
# Use a value from `colorsets.json` to use a predefined set of colors
|
||||
# Both hexadecimal and named colors are supported
|
||||
# This cannot be used when "plugin_languages_limit" is greater than 8
|
||||
plugin_languages_colors:
|
||||
description: Custom languages colors
|
||||
type: array
|
||||
|
||||
Reference in New Issue
Block a user