From 6ae962439c037341ed352984be435a55377e5827 Mon Sep 17 00:00:00 2001
From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com>
Date: Wed, 15 Mar 2023 19:15:22 -0400
Subject: [PATCH] feat(plugins/community/stock): migrate to d3
---
.../web/statics/embed/placeholders/stock.svg | 131 +++++++++++++-----
source/plugins/community/stock/index.mjs | 12 +-
source/plugins/community/stock/metadata.yml | 2 +-
3 files changed, 100 insertions(+), 45 deletions(-)
diff --git a/source/app/web/statics/embed/placeholders/stock.svg b/source/app/web/statics/embed/placeholders/stock.svg
index e4b60b44..4220bb3e 100644
--- a/source/app/web/statics/embed/placeholders/stock.svg
+++ b/source/app/web/statics/embed/placeholders/stock.svg
@@ -1,34 +1,99 @@
-
-
-
-
+
+
\ No newline at end of file
diff --git a/source/plugins/community/stock/index.mjs b/source/plugins/community/stock/index.mjs
index 3d20489e..5bf1e2cc 100644
--- a/source/plugins/community/stock/index.mjs
+++ b/source/plugins/community/stock/index.mjs
@@ -31,17 +31,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
//Generating chart
console.debug(`metrics/compute/${login}/plugins > stock > generating chart`)
- const chart = await imports.chartist("line", {
- width: 480 * (1 + data.large),
- height: 160,
- showPoint: false,
- axisX: {showGrid: false, labelInterpolationFnc: (value, index) => index % Math.floor(close.length / 4) === 0 ? value : null},
- axisY: {scaleMinSpace: 20},
- showArea: true,
- }, {
- labels: timestamp.map(timestamp => new Intl.DateTimeFormat("en-GB", {month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit"}).format(new Date(timestamp * 1000))),
- series: [close],
- })
+ 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
return {chart, currency, price, previous, delta: price - previous, symbol, company, interval, duration}
diff --git a/source/plugins/community/stock/metadata.yml b/source/plugins/community/stock/metadata.yml
index 29f53a05..108e2c93 100644
--- a/source/plugins/community/stock/metadata.yml
+++ b/source/plugins/community/stock/metadata.yml
@@ -19,7 +19,7 @@ inputs:
type: boolean
default: no
extras:
- - metrics.npm.optional.chartist
+ - metrics.npm.optional.d3
- metrics.api.yahoo.finance
plugin_stock_token: