From a1e032e4c43a8478c5f8a488ba5b78e739f89702 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:47:47 +0200 Subject: [PATCH] Simplified stock demo. --- demos/stock/demo.html | 5 +-- demos/stock/demo.js | 94 +++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/demos/stock/demo.html b/demos/stock/demo.html index d95bbc7..a273fa7 100644 --- a/demos/stock/demo.html +++ b/demos/stock/demo.html @@ -2,9 +2,8 @@ - - - + + Highcharts Stock Demo - Morningstar Connectors Demos diff --git a/demos/stock/demo.js b/demos/stock/demo.js index d3b8d10..6e37da9 100644 --- a/demos/stock/demo.js +++ b/demos/stock/demo.js @@ -1,59 +1,57 @@ document.getElementById('postman-json').addEventListener( 'change', - async function ( - evt - ) { + async function (evt) { const target = evt.target; - const postmanJSON = JSON.parse(await target.files[0]?.text()); + const postmanJSON = await getPostmanJSON(evt.target); + + if (!postmanJSON) { + return; + } target.parentNode.style.display = 'none'; - Dashboards.board('container', { - dataPool: { - connectors: [{ - id: 'morningstar-dividend', - type: 'MorningstarTimeSeries', - options: { - postman: { - environmentJSON: postmanJSON - }, - series: 'Dividend', - securities: [{ - id: 'F0GBR06KY1', - idType: 'MSID' - }, { - id: 'LU0011963245USD', - idType: 'ISIN' - }], - startDate: '2020-01-01', - endDate: '2024-12-31' - } - }] + const dividendConnector = new MorningstarConnectors.TimeSeriesConnector({ + postman: { + environmentJSON: postmanJSON }, - gui: { - layouts: [{ - id: 'layout-1', - rows: [{ - cells: [{ - id: 'dashboard-col-0' - }] - }] - }] + series: { + type: 'Dividend' }, - components: [{ - renderTo: 'dashboard-col-0', - connector: { - id: 'morningstar-dividend', - columnAssignment: [{ - seriesId: 'F0GBR06KY1', - data: ['Date', 'F0GBR06KY1'] - }, { - seriesId: 'LU0011963245USD', - data: ['Date', 'LU0011963245USD'] - }] - }, - type: 'Highcharts', - chartConstructor: 'stockChart', + securities: [{ + id: 'F0GBR06KY1', + idType: 'MSID' + }, { + id: 'LU0011963245USD', + idType: 'ISIN' + }], + startDate: '2020-01-01', + endDate: '2024-12-31' + }); + + await dividendConnector.load(); + + Highcharts.stockChart('container', { + series: [{ + type: 'line', + table: dividendConnector.dataTable }] }); }); + +async function getPostmanJSON (htmlInputFile) { + let file; + let fileJSON; + + for (file of htmlInputFile.files) { + try { + fileJSON = JSON.parse(await file.text()); + if (MorningstarConnectors.isPostmanEnvironmentJSON(fileJSON)) { + break; + } + } catch (error) { + // fail silently + } + } + + return fileJSON +}