From da1393bc5d7192ed346656ebe58f4d250eb95d1d Mon Sep 17 00:00:00 2001 From: Jan Litzenburger Date: Sun, 20 Jun 2021 00:23:23 +0200 Subject: [PATCH] add virtual horizontal multiplier --- MMM-Jast.js | 2 +- README.md | 40 ++++++++++++++++--------------- src/client/Client.ts | 3 ++- src/models/Config.ts | 1 + templates/HorizontalStockList.njk | 2 ++ 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/MMM-Jast.js b/MMM-Jast.js index 81d3069..67f5dd1 100644 --- a/MMM-Jast.js +++ b/MMM-Jast.js @@ -1 +1 @@ -(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(e){this.config=e,this.currentValueStyle={style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.changeValueStyle={style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.percentStyle={style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}getStockChangeAsString(e){return this.getStockChange(e).toLocaleString(this.config.locale,Object.assign(this.changeValueStyle,{currency:e.summaryDetail.currency}))}getStockChangePercentAsString(e){return this.getStockChangePercent(e).toLocaleString(this.config.locale,this.percentStyle)}getCurrentValueAsString(e){return this.getCurrentValue(e).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.summaryDetail.currency}))}getStockName(e){return e.meta.name||e.price.longName}getDepotValueAsString(e){return e.value.toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangeAsString(e){return(e.value-e.oldValue).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangePercentAsString(e){return((e.value-e.oldValue)/e.oldValue).toLocaleString(this.config.locale,this.percentStyle)}getDepot(e){var t,n,r;let a=[];for(const s of e)try{const e=null===(t=this.config.stocks)||void 0===t?void 0:t.find((e=>{var t;return e.symbol===(null===(t=s.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(n=s.price)||void 0===n?void 0:n.regularMarketPrice)*e.quantity,c=(null===(r=s.price)||void 0===r?void 0:r.regularMarketPreviousClose)*e.quantity,o=a.find((e=>e.currency===s.price.currency));o?(o.value=o.value+t,o.oldValue=o.oldValue+c):a.push({value:t,oldValue:c,currency:s.price.currency})}}catch(e){console.warn("There was a problem calculating the detpot growth",e)}return console.debug("Depot",a),a}}}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}(()=>{const e=n(429);Module.register("MMM-Jast",{defaults:{locale:config.locale||"en-GB",updateIntervalInSeconds:600,useGrouping:!1,currencyStyle:"code",fadeSpeedInSeconds:3.5,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}],scroll:"vertical",maxWidth:"100%",numberDecimalsValues:2,numberDecimalsPercentages:1,showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showDepot:!1,showDepotGrowth:!1,showDepotGrowthPercent:!1},getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){const t=new e.default(this.config);return{config:this.config,stocks:this.stocks,utils:t}},start(){this.nunjucksEnvironment().loaders[0].async=!1,this.nunjucksEnvironment().loaders[0].useCache=!0,this.stocks=[],this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){const e=this;this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{e.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_STOCKS",this.config)},socketNotificationReceived(e,t){"STOCKS_RESULT"===e&&(this.stocks=t,this.updateDom(),console.debug("Stocks",this.stocks))}})})()})(); \ No newline at end of file +(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(e){this.config=e,this.currentValueStyle={style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.changeValueStyle={style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.percentStyle={style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}getStockChangeAsString(e){return this.getStockChange(e).toLocaleString(this.config.locale,Object.assign(this.changeValueStyle,{currency:e.summaryDetail.currency}))}getStockChangePercentAsString(e){return this.getStockChangePercent(e).toLocaleString(this.config.locale,this.percentStyle)}getCurrentValueAsString(e){return this.getCurrentValue(e).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.summaryDetail.currency}))}getStockName(e){return e.meta.name||e.price.longName}getDepotValueAsString(e){return e.value.toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangeAsString(e){return(e.value-e.oldValue).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangePercentAsString(e){return((e.value-e.oldValue)/e.oldValue).toLocaleString(this.config.locale,this.percentStyle)}getDepot(e){var t,n,r;let a=[];for(const s of e)try{const e=null===(t=this.config.stocks)||void 0===t?void 0:t.find((e=>{var t;return e.symbol===(null===(t=s.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(n=s.price)||void 0===n?void 0:n.regularMarketPrice)*e.quantity,c=(null===(r=s.price)||void 0===r?void 0:r.regularMarketPreviousClose)*e.quantity,o=a.find((e=>e.currency===s.price.currency));o?(o.value=o.value+t,o.oldValue=o.oldValue+c):a.push({value:t,oldValue:c,currency:s.price.currency})}}catch(e){console.warn("There was a problem calculating the detpot growth",e)}return console.debug("Depot",a),a}}}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}(()=>{const e=n(429);Module.register("MMM-Jast",{defaults:{locale:config.locale||"en-GB",updateIntervalInSeconds:600,useGrouping:!1,currencyStyle:"code",fadeSpeedInSeconds:3.5,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}],scroll:"vertical",maxWidth:"100%",numberDecimalsValues:2,numberDecimalsPercentages:1,showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showDepot:!1,showDepotGrowth:!1,showDepotGrowthPercent:!1,virtualHorizontalMultiplier:2},getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){const t=new e.default(this.config);return{config:this.config,stocks:this.stocks,utils:t}},start(){this.nunjucksEnvironment().loaders[0].async=!1,this.nunjucksEnvironment().loaders[0].useCache=!0,this.stocks=[],this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){const e=this;this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{e.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_STOCKS",this.config)},socketNotificationReceived(e,t){"STOCKS_RESULT"===e&&(this.stocks=t,this.updateDom(),console.debug("Stocks",this.stocks))}})})()})(); \ No newline at end of file diff --git a/README.md b/README.md index 724bd41..278f7d8 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ To use this module, add it to the modules array in the `MagicMirror/config/confi showDepotGrowth: false, numberDecimalsValues: 2, numberDecimalsPercentages: 1, + virtualHorizontalMultiplier: 2, stocks: [ { name: "BASF", symbol: "BAS.DE", quantity: 10 }, { name: "SAP", symbol: "SAP.DE", quantity: 15 }, @@ -66,25 +67,26 @@ To use this module, add it to the modules array in the `MagicMirror/config/confi } ``` ### Options -| Field | Description | Default | -| -------- | -------- | -------- | -| updateIntervalInSeconds | (Integer) Interval to refresh stock data from server. (min. 120) | 300 | -| fadeSpeedInSeconds | (Integer) Animation speed for ticker. Higher value: vertical -> faster // horizontal -> slower | 3.5 | -| stocks | (Array) Array of stocks to be displayed | Sample set | -| scroll | (String) Animation direction for ticker. Values: none, vertical or horizontal | "vertical" | -| maxWidth | (String) CSS style to limit ticker width for vertical styles | "100%" | -| numberDecimalsValues | (Number) Number of decimals for stock values | 2 | -| numberDecimalsPercentages | (Number) Number of decimals for percentages | 1 | -| currencyStyle | (String) Style of currency. Possible values: "code" (EUR), "symbol" (€), "name" (Euro) | "code" | -| showColors | (Boolean) Colorize positive numbers in green, negatives in red | true | -| showCurrency | (Boolean) Show stocks currency | true | -| showChangePercent | (Boolean) Show stocks change against last close in percent | true | -| showChangeValue | (Boolean) Show stocks change against last close in absolute value | false | -| showChangeValueCurrency | (Boolean) Show currency for change value | false | -| showDepot | (Boolean) Show depot value | false | -| showDepotGrowth | (Boolean) Show depot value growth summary | false | -| showDepotGrowthPercent | (Boolean) Show depot value growth summary in percent | false | -| useGrouping | (Boolean) Add grouping to high value numbers (i.e. BTC 60,000.00 EUR) | false | +| Field | Description | Default | +| -------- | -------- | -------- | +| updateIntervalInSeconds | (Integer) Interval to refresh stock data from server. (min. 120) | 300 | +| fadeSpeedInSeconds | (Integer) Animation speed for ticker. Higher value: vertical -> faster // horizontal -> slower | 3.5 | +| stocks | (Array) Array of stocks to be displayed | Sample set | +| scroll | (String) Animation direction for ticker. Values: none, vertical or horizontal | "vertical" | +| maxWidth | (String) CSS style to limit ticker width for vertical styles | "100%" | +| numberDecimalsValues | (Number) Number of decimals for stock values | 2 | +| numberDecimalsPercentages | (Number) Number of decimals for percentages | 1 | +| currencyStyle | (String) Style of currency. Possible values: "code" (EUR), "symbol" (€), "name" (Euro) | "code" | +| showColors | (Boolean) Colorize positive numbers in green, negatives in red | true | +| showCurrency | (Boolean) Show stocks currency | true | +| showChangePercent | (Boolean) Show stocks change against last close in percent | true | +| showChangeValue | (Boolean) Show stocks change against last close in absolute value | false | +| showChangeValueCurrency | (Boolean) Show currency for change value | false | +| showDepot | (Boolean) Show depot value | false | +| showDepotGrowth | (Boolean) Show depot value growth summary | false | +| showDepotGrowthPercent | (Boolean) Show depot value growth summary in percent | false | +| useGrouping | (Boolean) Add grouping to high value numbers (i.e. BTC 60,000.00 EUR) | false | +| virtualHorizontalMultiplier | (Number) Virtually repeats the stocklist in horizontal mode to avoid whitespaces | 2 | ### Stock Object | Field | Description | Example | diff --git a/src/client/Client.ts b/src/client/Client.ts index e63d992..5695334 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -27,7 +27,8 @@ Module.register("MMM-Jast", { showChangeValueCurrency: false, showDepot: false, showDepotGrowth: false, - showDepotGrowthPercent: false + showDepotGrowthPercent: false, + virtualHorizontalMultiplier: 2 } as Config, getStyles() { diff --git a/src/models/Config.ts b/src/models/Config.ts index 476e97a..a731713 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -18,6 +18,7 @@ export type Config = { showDepot: boolean showDepotGrowth: boolean showDepotGrowthPercent: boolean + virtualHorizontalMultiplier: number } type Stock = { diff --git a/templates/HorizontalStockList.njk b/templates/HorizontalStockList.njk index 9419169..34f1a2b 100755 --- a/templates/HorizontalStockList.njk +++ b/templates/HorizontalStockList.njk @@ -3,6 +3,7 @@ {% macro render(num="1") %}

+ {% for i in range(0, config.virtualHorizontalMultiplier) -%} {% for stock in stocks %} {{ utils.getStockName(stock) }}: {% if utils.getStockChange(stock) > 0 %} @@ -48,6 +49,7 @@ {% endfor %} {% endif %} + {% endfor %}

{% endmacro %}