chore: code formatting

This commit is contained in:
github-actions[bot]
2022-07-21 04:37:55 +00:00
parent 48f4ef79ed
commit aa83b84522
5 changed files with 36 additions and 34 deletions

View File

@@ -1,15 +1,15 @@
//Imports
import { Client as Gmap } from "@googlemaps/google-maps-services-js"
import color from "color"
import * as d3 from "d3"
import D3Node from "d3-node"
import color from "color"
import {Client as Gmap} from "@googlemaps/google-maps-services-js"
/**
* Worldmap
* Mostly ported from https://github.com/dyatko/worldstar
* License: https://raw.githubusercontent.com/dyatko/worldstar/master/LICENSE
*/
export default async function (login, {locations, sample, imports, token}) {
export default async function(login, {locations, sample, imports, token}) {
//Parse geocodes
let stars = new Map()
if (token) {
@@ -20,7 +20,7 @@ export default async function (login, {locations, sample, imports, token}) {
console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > looking for ${location}`)
if (!cache.has(location)) {
try {
const {data:{results}} = await get.geocode({params:{address:location, key:token}})
const {data: {results}} = await get.geocode({params: {address: location, key: token}})
const country = results.at(0).address_components.find(({types}) => types.includes("country"))
cache.set(location, country.short_name ?? country.long_name)
console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > ${location} resolved to ${cache.get(location)}`)
@@ -33,7 +33,9 @@ export default async function (login, {locations, sample, imports, token}) {
stars.set(code, (stars.get(code) ?? 0) + 1)
}
}
else throw {error:{message:"Google Maps API token is not set"}}
else {
throw {error: {message: "Google Maps API token is not set"}}
}
//Generate SVG
const d3n = new D3Node()
@@ -47,10 +49,10 @@ export default async function (login, {locations, sample, imports, token}) {
.data(countries.features)
.join("path")
.attr("id", ({id}) => id)
.style("fill", ({properties:{iso_a2, wb_a2, sov_a3}}) => {
.style("fill", ({properties: {iso_a2, wb_a2, sov_a3}}) => {
const code = iso_a2?.match(/[A-Z]{2}/) ? iso_a2 : wb_a2?.match(/[A-Z]{2}/) ? wb_a2 : sov_a3?.substr(0, 2) ?? ""
const value = stars.get(code)
return color("#216e39").mix(color("#ffffff"), 1 - Math.max(0, splits.indexOf(value))/splits.length).hex()
return color("#216e39").mix(color("#ffffff"), 1 - Math.max(0, splits.indexOf(value)) / splits.length).hex()
})
.style("stroke", "#afafaf")
.style("stroke-width", "0.6px")