chore: code formatting
This commit is contained in:
@@ -822,7 +822,7 @@ export const Graph = {
|
|||||||
/**Basic Graph */
|
/**Basic Graph */
|
||||||
graph(type, data, {area = true, points = true, text = true, low = NaN, high = NaN, match = null, labels = null, width = 480, height = 315, ticks = 0} = {}) {
|
graph(type, data, {area = true, points = true, text = true, low = NaN, high = NaN, match = null, labels = null, width = 480, height = 315, ticks = 0} = {}) {
|
||||||
//Generate SVG
|
//Generate SVG
|
||||||
const margin = {top:10, left:10, right:10, bottom:45}
|
const margin = {top: 10, left: 10, right: 10, bottom: 45}
|
||||||
const d3n = new D3node()
|
const d3n = new D3node()
|
||||||
const svg = d3n.createSVG(width, height)
|
const svg = d3n.createSVG(width, height)
|
||||||
|
|
||||||
@@ -862,7 +862,7 @@ export const Graph = {
|
|||||||
.range([margin.left, height - margin.top - margin.bottom])
|
.range([margin.left, height - margin.top - margin.bottom])
|
||||||
svg.append("g")
|
svg.append("g")
|
||||||
.attr("transform", `translate(${margin.left},${margin.top})`)
|
.attr("transform", `translate(${margin.left},${margin.top})`)
|
||||||
.call(d3.axisRight(y).ticks(Math.round(height/50)).tickSize(width - margin.left - margin.right))
|
.call(d3.axisRight(y).ticks(Math.round(height / 50)).tickSize(width - margin.left - margin.right))
|
||||||
.call(g => g.select(".domain").remove())
|
.call(g => g.select(".domain").remove())
|
||||||
.call(g => g.selectAll(".tick line").attr("stroke-opacity", 0.5).attr("stroke-dasharray", "2,2"))
|
.call(g => g.selectAll(".tick line").attr("stroke-opacity", 0.5).attr("stroke-dasharray", "2,2"))
|
||||||
.call(g => g.selectAll(".tick text").attr("x", 0).attr("dy", -4))
|
.call(g => g.selectAll(".tick text").attr("x", 0).attr("dy", -4))
|
||||||
@@ -883,7 +883,7 @@ export const Graph = {
|
|||||||
d3.line()
|
d3.line()
|
||||||
.curve(d3.curveLinear)
|
.curve(d3.curveLinear)
|
||||||
.x(d => x(d[0]))
|
.x(d => x(d[0]))
|
||||||
.y(d => y(d[1]))
|
.y(d => y(d[1])),
|
||||||
)
|
)
|
||||||
.attr("fill", "transparent")
|
.attr("fill", "transparent")
|
||||||
.attr("stroke", "#87ceeb")
|
.attr("stroke", "#87ceeb")
|
||||||
@@ -932,7 +932,7 @@ export const Graph = {
|
|||||||
.selectAll("text")
|
.selectAll("text")
|
||||||
.data(yticked)
|
.data(yticked)
|
||||||
.join("text")
|
.join("text")
|
||||||
.attr("transform", `translate(${margin.left},${margin.top-4})`)
|
.attr("transform", `translate(${margin.left},${margin.top - 4})`)
|
||||||
.attr("x", d => x(d[0]))
|
.attr("x", d => x(d[0]))
|
||||||
.attr("y", d => y(d[1]))
|
.attr("y", d => y(d[1]))
|
||||||
.text(d => d[2] ? d[2] : "")
|
.text(d => d[2] ? d[2] : "")
|
||||||
@@ -955,12 +955,12 @@ export const Graph = {
|
|||||||
|
|
||||||
//Construct arcs
|
//Construct arcs
|
||||||
const color = d3.scaleOrdinal(K, d3.schemeSpectral[K.length])
|
const color = d3.scaleOrdinal(K, d3.schemeSpectral[K.length])
|
||||||
const arcs = d3.pie().padAngle(1/radius).sort(null).value(i => V[i])(I)
|
const arcs = d3.pie().padAngle(1 / radius).sort(null).value(i => V[i])(I)
|
||||||
const arc = d3.arc().innerRadius(0).outerRadius(radius)
|
const arc = d3.arc().innerRadius(0).outerRadius(radius)
|
||||||
const labels = d3.arc().innerRadius(radius/2).outerRadius(radius/2)
|
const labels = d3.arc().innerRadius(radius / 2).outerRadius(radius / 2)
|
||||||
|
|
||||||
svg.append("g")
|
svg.append("g")
|
||||||
.attr("transform", `translate(${width/2},${height/2})`)
|
.attr("transform", `translate(${width / 2},${height / 2})`)
|
||||||
.attr("stroke", "white")
|
.attr("stroke", "white")
|
||||||
.attr("stroke-width", 1)
|
.attr("stroke-width", 1)
|
||||||
.attr("stroke-linejoin", "round")
|
.attr("stroke-linejoin", "round")
|
||||||
@@ -973,7 +973,7 @@ export const Graph = {
|
|||||||
.text(d => `${K[d.data]}\n${V[d.data]}`)
|
.text(d => `${K[d.data]}\n${V[d.data]}`)
|
||||||
|
|
||||||
svg.append("g")
|
svg.append("g")
|
||||||
.attr("transform", `translate(${width/2},${height/2})`)
|
.attr("transform", `translate(${width / 2},${height / 2})`)
|
||||||
.attr("font-family", "sans-serif")
|
.attr("font-family", "sans-serif")
|
||||||
.attr("font-size", 12)
|
.attr("font-size", 12)
|
||||||
.attr("text-anchor", "middle")
|
.attr("text-anchor", "middle")
|
||||||
@@ -996,5 +996,5 @@ export const Graph = {
|
|||||||
.text(d => d)
|
.text(d => d)
|
||||||
|
|
||||||
return d3n.svgString()
|
return d3n.svgString()
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
|
|
||||||
//Generating chart
|
//Generating chart
|
||||||
console.debug(`metrics/compute/${login}/plugins > stock > generating chart`)
|
console.debug(`metrics/compute/${login}/plugins > stock > generating chart`)
|
||||||
const chart = imports.Graph.timeline(close.map((y, i) => ({x:new Date(timestamp[i]*1000), y})), {low:Math.min(...close), high:Math.max(...close), points:false, text:false, width: 480 * (1 + data.large), height:200})
|
const chart = imports.Graph.timeline(close.map((y, i) => ({x: new Date(timestamp[i] * 1000), y})), {low: Math.min(...close), high: Math.max(...close), points: false, text: false, width: 480 * (1 + data.large), height: 200})
|
||||||
|
|
||||||
//Results
|
//Results
|
||||||
return {chart, currency, price, previous, delta: price - previous, symbol, company, interval, duration}
|
return {chart, currency, price, previous, delta: price - previous, symbol, company, interval, duration}
|
||||||
|
|||||||
@@ -120,14 +120,14 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
|||||||
if ((["graph", "chartist"].includes(_charts)) && (imports.metadata.plugins.habits.extras("charts.type", {extras}))) {
|
if ((["graph", "chartist"].includes(_charts)) && (imports.metadata.plugins.habits.extras("charts.type", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > habits > generating charts`)
|
console.debug(`metrics/compute/${login}/plugins > habits > generating charts`)
|
||||||
habits.charts = await Promise.all([
|
habits.charts = await Promise.all([
|
||||||
{type: "line", data: {...empty(24), ...Object.fromEntries(Object.entries(habits.commits.hours).filter(([k]) => !Number.isNaN(+k)))}, ticks:24, low: 0, high: habits.commits.hours.max},
|
{type: "line", data: {...empty(24), ...Object.fromEntries(Object.entries(habits.commits.hours).filter(([k]) => !Number.isNaN(+k)))}, ticks: 24, low: 0, high: habits.commits.hours.max},
|
||||||
{type: "line", data: {...empty(7), ...Object.fromEntries(Object.entries(habits.commits.days).filter(([k]) => !Number.isNaN(+k)))}, ticks:7, low: 0, high: habits.commits.days.max, labels:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], half: true},
|
{type: "line", data: {...empty(7), ...Object.fromEntries(Object.entries(habits.commits.days).filter(([k]) => !Number.isNaN(+k)))}, ticks: 7, low: 0, high: habits.commits.days.max, labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], half: true},
|
||||||
{type: "pie", data: Object.fromEntries(Object.entries(habits.linguist.languages).map(([k, v]) => [k, (100*v).toFixed(2)])), colors:habits.linguist.colors, half: true},
|
{type: "pie", data: Object.fromEntries(Object.entries(habits.linguist.languages).map(([k, v]) => [k, (100 * v).toFixed(2)])), colors: habits.linguist.colors, half: true},
|
||||||
].map(({type, data, high, low, ticks, colors = null, labels = null, half = false}) => {
|
].map(({type, data, high, low, ticks, colors = null, labels = null, half = false}) => {
|
||||||
const width = 480 * (half ? 0.45 : 1)
|
const width = 480 * (half ? 0.45 : 1)
|
||||||
const height = 160
|
const height = 160
|
||||||
if (type === "line")
|
if (type === "line")
|
||||||
return imports.Graph.line(Object.entries(data).map(([x, y]) => ({x:+x, y})), {low, high, ticks, labels, width, height})
|
return imports.Graph.line(Object.entries(data).map(([x, y]) => ({x: +x, y})), {low, high, ticks, labels, width, height})
|
||||||
console.log(data)
|
console.log(data)
|
||||||
if (type === "pie")
|
if (type === "pie")
|
||||||
return imports.Graph.pie(data, {colors, width, height})
|
return imports.Graph.pie(data, {colors, width, height})
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
|||||||
//Load inputs
|
//Load inputs
|
||||||
let {days, charts: _charts, "charts.type": _charts_type, worldmap: _worldmap, "worldmap.sample": _worldmap_sample} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
let {days, charts: _charts, "charts.type": _charts_type, worldmap: _worldmap, "worldmap.sample": _worldmap_sample} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
||||||
if (!days) {
|
if (!days) {
|
||||||
days = Math.abs(parseInt((new Date() - new Date(data.user.createdAt))/1000/60/60/24))
|
days = Math.abs(parseInt((new Date() - new Date(data.user.createdAt)) / 1000 / 60 / 60 / 24))
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > set days to ${days}`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > set days to ${days}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +67,11 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
|||||||
let charts = _charts ? true : null
|
let charts = _charts ? true : null
|
||||||
if ((["graph", "chartist"].includes(_charts_type)) && (imports.metadata.plugins.stargazers.extras("charts.type", {extras}))) {
|
if ((["graph", "chartist"].includes(_charts_type)) && (imports.metadata.plugins.stargazers.extras("charts.type", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
||||||
charts = await Promise.all([{data: total, low: total.min, high: total.max}, {data: increments, low: 0, high: increments.max, sign: true}].map(({data: {dates: set}, low, high, sign = false}) =>
|
charts = await Promise.all(
|
||||||
imports.Graph.timeline(Object.entries(set).map(([x, y]) => ({x:new Date(x), y, text:imports.format(y, {sign})})), {low, high,
|
[{data: total, low: total.min, high: total.max}, {data: increments, low: 0, high: increments.max, sign: true}].map(({data: {dates: set}, low, high, sign = false}) =>
|
||||||
match:(data, ticks) => data.filter(([x]) => ticks.map(t => t.toISOString().slice(0, 10)).includes(x.toISOString().slice(0, 10))),
|
imports.Graph.timeline(Object.entries(set).map(([x, y]) => ({x: new Date(x), y, text: imports.format(y, {sign})})), {low, high, match: (data, ticks) => data.filter(([x]) => ticks.map(t => t.toISOString().slice(0, 10)).includes(x.toISOString().slice(0, 10)))})
|
||||||
})
|
),
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generating worldmap
|
//Generating worldmap
|
||||||
|
|||||||
Reference in New Issue
Block a user