@oanda/labs-instruments-price-chart-widget 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +124 -0
- package/codegen.ts +2 -5
- package/dist/main/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js +6 -2
- package/dist/main/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/Main.js +32 -16
- package/dist/main/InstrumentsPriceChartWidget/Main.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/components/Chart.js +4 -2
- package/dist/main/InstrumentsPriceChartWidget/components/Chart.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/components/TimeZoneLabel.js +29 -0
- package/dist/main/InstrumentsPriceChartWidget/components/TimeZoneLabel.js.map +1 -0
- package/dist/main/InstrumentsPriceChartWidget/components/formatters.js +50 -11
- package/dist/main/InstrumentsPriceChartWidget/components/formatters.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/components/getOption.js +13 -13
- package/dist/main/InstrumentsPriceChartWidget/components/getOption.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/components/types.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/config.js +14 -7
- package/dist/main/InstrumentsPriceChartWidget/config.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/render.js +10 -2
- package/dist/main/InstrumentsPriceChartWidget/render.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/types.js.map +1 -1
- package/dist/main/InstrumentsPriceChartWidget/utils.js +12 -0
- package/dist/main/InstrumentsPriceChartWidget/utils.js.map +1 -0
- package/dist/main/gql/{mock/getPriceCandles.js → priceCandles.js} +9 -8
- package/dist/main/gql/priceCandles.js.map +1 -0
- package/dist/main/gql/types/gql.js +1 -1
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +53 -24
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/translations/sources/en.json +2 -1
- package/dist/module/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js +6 -2
- package/dist/module/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/Main.js +33 -17
- package/dist/module/InstrumentsPriceChartWidget/Main.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/components/Chart.js +4 -2
- package/dist/module/InstrumentsPriceChartWidget/components/Chart.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/components/TimeZoneLabel.js +21 -0
- package/dist/module/InstrumentsPriceChartWidget/components/TimeZoneLabel.js.map +1 -0
- package/dist/module/InstrumentsPriceChartWidget/components/formatters.js +47 -9
- package/dist/module/InstrumentsPriceChartWidget/components/formatters.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/components/getOption.js +14 -14
- package/dist/module/InstrumentsPriceChartWidget/components/getOption.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/components/types.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/config.js +14 -7
- package/dist/module/InstrumentsPriceChartWidget/config.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/render.js +11 -3
- package/dist/module/InstrumentsPriceChartWidget/render.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/types.js.map +1 -1
- package/dist/module/InstrumentsPriceChartWidget/utils.js +4 -0
- package/dist/module/InstrumentsPriceChartWidget/utils.js.map +1 -0
- package/dist/module/gql/{mock/getPriceCandles.js → priceCandles.js} +9 -8
- package/dist/module/gql/priceCandles.js.map +1 -0
- package/dist/module/gql/types/gql.js +1 -1
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +52 -23
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/module/translations/sources/en.json +2 -1
- package/dist/types/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.d.ts +1 -1
- package/dist/types/InstrumentsPriceChartWidget/Main.d.ts +1 -1
- package/dist/types/InstrumentsPriceChartWidget/components/Chart.d.ts +1 -1
- package/dist/types/InstrumentsPriceChartWidget/components/TimeZoneLabel.d.ts +2 -0
- package/dist/types/InstrumentsPriceChartWidget/components/formatters.d.ts +5 -1
- package/dist/types/InstrumentsPriceChartWidget/components/types.d.ts +6 -4
- package/dist/types/InstrumentsPriceChartWidget/config.d.ts +5 -3
- package/dist/types/InstrumentsPriceChartWidget/types.d.ts +5 -1
- package/dist/types/InstrumentsPriceChartWidget/utils.d.ts +3 -0
- package/dist/types/gql/priceCandles.d.ts +2 -0
- package/dist/types/gql/types/gql.d.ts +4 -3
- package/dist/types/gql/types/graphql.d.ts +31 -27
- package/package.json +5 -3
- package/src/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.tsx +7 -1
- package/src/InstrumentsPriceChartWidget/Main.tsx +45 -19
- package/src/InstrumentsPriceChartWidget/components/Chart.tsx +2 -1
- package/src/InstrumentsPriceChartWidget/components/TimeZoneLabel.tsx +24 -0
- package/src/InstrumentsPriceChartWidget/components/formatters.ts +72 -13
- package/src/InstrumentsPriceChartWidget/components/getOption.ts +20 -21
- package/src/InstrumentsPriceChartWidget/components/types.ts +6 -4
- package/src/InstrumentsPriceChartWidget/config.ts +16 -7
- package/src/InstrumentsPriceChartWidget/render.tsx +12 -2
- package/src/InstrumentsPriceChartWidget/types.ts +5 -1
- package/src/InstrumentsPriceChartWidget/utils.ts +16 -0
- package/src/gql/{mock/getPriceCandles.ts → priceCandles.ts} +8 -7
- package/src/gql/types/gql.ts +4 -4
- package/src/gql/types/graphql.ts +62 -37
- package/src/translations/sources/en.json +2 -1
- package/test/Main.test.tsx +6 -2
- package/test/mocks/chartMock.ts +201 -37
- package/dist/main/InstrumentsPriceChartWidget/getPriceCandlesMock.js +0 -83
- package/dist/main/InstrumentsPriceChartWidget/getPriceCandlesMock.js.map +0 -1
- package/dist/main/gql/mock/getPriceCandles.js.map +0 -1
- package/dist/main/gql/mock/schema.graphqls +0 -62
- package/dist/module/InstrumentsPriceChartWidget/getPriceCandlesMock.js +0 -76
- package/dist/module/InstrumentsPriceChartWidget/getPriceCandlesMock.js.map +0 -1
- package/dist/module/gql/mock/getPriceCandles.js.map +0 -1
- package/dist/module/gql/mock/schema.graphqls +0 -62
- package/dist/types/InstrumentsPriceChartWidget/getPriceCandlesMock.d.ts +0 -9
- package/dist/types/gql/mock/getPriceCandles.d.ts +0 -2
- package/src/InstrumentsPriceChartWidget/getPriceCandlesMock.tsx +0 -75
- package/src/gql/mock/schema.graphqls +0 -62
|
@@ -1,39 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useQuery } from '@apollo/client';
|
|
2
|
+
import { ChartError, Spinner, SpinnerSize, TimeUnitSwitch } from '@oanda/labs-widget-common';
|
|
2
3
|
import React, { useState } from 'react';
|
|
4
|
+
import { priceCandles } from '../gql/priceCandles';
|
|
5
|
+
import { TimeSpan } from '../gql/types/graphql';
|
|
3
6
|
import { Chart } from './components/Chart';
|
|
7
|
+
import { TimeZoneLabel } from './components/TimeZoneLabel';
|
|
4
8
|
import { timeUnitConfig } from './config';
|
|
5
|
-
import {
|
|
6
|
-
import { TimeSpanSubset } from './types';
|
|
9
|
+
import { getCandles, getGranularityForTimeSpan } from './utils';
|
|
7
10
|
const Main = _ref => {
|
|
8
11
|
let {
|
|
9
|
-
division
|
|
12
|
+
division,
|
|
13
|
+
instrument,
|
|
14
|
+
dataSource
|
|
10
15
|
} = _ref;
|
|
11
|
-
const [selectedTimeUnit, setSelectedTimeUnit] = useState(
|
|
16
|
+
const [selectedTimeUnit, setSelectedTimeUnit] = useState(TimeSpan.Day_1);
|
|
12
17
|
const {
|
|
13
18
|
loading,
|
|
14
19
|
data,
|
|
15
20
|
error
|
|
16
|
-
} =
|
|
17
|
-
|
|
21
|
+
} = useQuery(priceCandles, {
|
|
22
|
+
variables: {
|
|
23
|
+
dataSource,
|
|
24
|
+
division,
|
|
25
|
+
instrument,
|
|
26
|
+
granularity: getGranularityForTimeSpan(selectedTimeUnit),
|
|
27
|
+
timeSpan: selectedTimeUnit
|
|
28
|
+
},
|
|
29
|
+
fetchPolicy: 'cache-and-network'
|
|
18
30
|
});
|
|
19
|
-
const
|
|
31
|
+
const candles = getCandles(data);
|
|
32
|
+
const showError = candles?.length === 0 || !candles || !!error;
|
|
20
33
|
return React.createElement("div", {
|
|
21
34
|
"data-testid": "instruments-price-chart-wrapper"
|
|
22
|
-
}, loading && React.createElement("div", {
|
|
23
|
-
className: "lw-mb-[50px] lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary"
|
|
24
|
-
}, React.createElement(Spinner, {
|
|
25
|
-
size: SpinnerSize.lg
|
|
26
|
-
})), !loading && !showError && React.createElement("div", {
|
|
27
|
-
"data-testid": "instruments-price-chart-widget"
|
|
28
35
|
}, React.createElement("div", {
|
|
29
36
|
className: "lw-flex lw-pt-2"
|
|
30
37
|
}, React.createElement(TimeUnitSwitch, {
|
|
31
38
|
callback: setSelectedTimeUnit,
|
|
32
39
|
options: timeUnitConfig,
|
|
33
40
|
selected: selectedTimeUnit
|
|
34
|
-
})), React.createElement(
|
|
35
|
-
|
|
36
|
-
}
|
|
41
|
+
})), loading && React.createElement("div", {
|
|
42
|
+
className: "lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary"
|
|
43
|
+
}, React.createElement(Spinner, {
|
|
44
|
+
size: SpinnerSize.lg
|
|
45
|
+
})), !loading && showError && React.createElement("div", {
|
|
46
|
+
className: "lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary"
|
|
47
|
+
}, React.createElement(ChartError, null)), !loading && !showError && React.createElement("div", {
|
|
48
|
+
"data-testid": "instruments-price-chart-widget"
|
|
49
|
+
}, React.createElement(Chart, {
|
|
50
|
+
timeSpan: selectedTimeUnit,
|
|
51
|
+
values: candles
|
|
52
|
+
})), React.createElement(TimeZoneLabel, null));
|
|
37
53
|
};
|
|
38
54
|
export { Main };
|
|
39
55
|
//# sourceMappingURL=Main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Main.js","names":["Spinner","SpinnerSize","TimeUnitSwitch","React","useState","Chart","timeUnitConfig","
|
|
1
|
+
{"version":3,"file":"Main.js","names":["useQuery","ChartError","Spinner","SpinnerSize","TimeUnitSwitch","React","useState","priceCandles","TimeSpan","Chart","TimeZoneLabel","timeUnitConfig","getCandles","getGranularityForTimeSpan","Main","_ref","division","instrument","dataSource","selectedTimeUnit","setSelectedTimeUnit","Day_1","loading","data","error","variables","granularity","timeSpan","fetchPolicy","candles","showError","length","createElement","className","callback","options","selected","size","lg","values"],"sources":["../../../src/InstrumentsPriceChartWidget/Main.tsx"],"sourcesContent":["import { useQuery } from '@apollo/client';\nimport {\n ChartError,\n Spinner,\n SpinnerSize,\n TimeUnitSwitch,\n} from '@oanda/labs-widget-common';\nimport React, { useState } from 'react';\n\nimport { priceCandles } from '../gql/priceCandles';\nimport {\n type PriceCandlesQuery,\n type PriceCandlesQueryVariables,\n TimeSpan,\n} from '../gql/types/graphql';\nimport { Chart } from './components/Chart';\nimport { TimeZoneLabel } from './components/TimeZoneLabel';\nimport { timeUnitConfig } from './config';\nimport { type MainProps } from './types';\nimport { getCandles, getGranularityForTimeSpan } from './utils';\n\nconst Main = ({ division, instrument, dataSource }: MainProps) => {\n const [selectedTimeUnit, setSelectedTimeUnit] = useState(TimeSpan.Day_1);\n\n const { loading, data, error } = useQuery<\n PriceCandlesQuery,\n PriceCandlesQueryVariables\n >(priceCandles, {\n variables: {\n dataSource,\n division,\n instrument,\n granularity: getGranularityForTimeSpan(selectedTimeUnit),\n timeSpan: selectedTimeUnit,\n },\n fetchPolicy: 'cache-and-network',\n });\n\n const candles = getCandles(data);\n const showError = candles?.length === 0 || !candles || !!error;\n\n return (\n <div data-testid=\"instruments-price-chart-wrapper\">\n <div className=\"lw-flex lw-pt-2\">\n <TimeUnitSwitch<TimeSpan>\n callback={setSelectedTimeUnit}\n options={timeUnitConfig}\n selected={selectedTimeUnit}\n />\n </div>\n\n {loading && (\n <div className=\"lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary\">\n <Spinner size={SpinnerSize.lg} />\n </div>\n )}\n\n {!loading && showError && (\n <div className=\"lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary\">\n <ChartError />\n </div>\n )}\n\n {!loading && !showError && (\n <div data-testid=\"instruments-price-chart-widget\">\n <Chart timeSpan={selectedTimeUnit} values={candles} />\n </div>\n )}\n <TimeZoneLabel />\n </div>\n );\n};\n\nexport { Main };\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,SACEC,UAAU,EACVC,OAAO,EACPC,WAAW,EACXC,cAAc,QACT,2BAA2B;AAClC,OAAOC,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AAEvC,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAGEC,QAAQ,QACH,sBAAsB;AAC7B,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,cAAc,QAAQ,UAAU;AAEzC,SAASC,UAAU,EAAEC,yBAAyB,QAAQ,SAAS;AAE/D,MAAMC,IAAI,GAAGC,IAAA,IAAqD;EAAA,IAApD;IAAEC,QAAQ;IAAEC,UAAU;IAAEC;EAAsB,CAAC,GAAAH,IAAA;EAC3D,MAAM,CAACI,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGd,QAAQ,CAACE,QAAQ,CAACa,KAAK,CAAC;EAExE,MAAM;IAAEC,OAAO;IAAEC,IAAI;IAAEC;EAAM,CAAC,GAAGxB,QAAQ,CAGvCO,YAAY,EAAE;IACdkB,SAAS,EAAE;MACTP,UAAU;MACVF,QAAQ;MACRC,UAAU;MACVS,WAAW,EAAEb,yBAAyB,CAACM,gBAAgB,CAAC;MACxDQ,QAAQ,EAAER;IACZ,CAAC;IACDS,WAAW,EAAE;EACf,CAAC,CAAC;EAEF,MAAMC,OAAO,GAAGjB,UAAU,CAACW,IAAI,CAAC;EAChC,MAAMO,SAAS,GAAGD,OAAO,EAAEE,MAAM,KAAK,CAAC,IAAI,CAACF,OAAO,IAAI,CAAC,CAACL,KAAK;EAE9D,OACEnB,KAAA,CAAA2B,aAAA;IAAK,eAAY;EAAiC,GAChD3B,KAAA,CAAA2B,aAAA;IAAKC,SAAS,EAAC;EAAiB,GAC9B5B,KAAA,CAAA2B,aAAA,CAAC5B,cAAc;IACb8B,QAAQ,EAAEd,mBAAoB;IAC9Be,OAAO,EAAExB,cAAe;IACxByB,QAAQ,EAAEjB;EAAiB,CAC5B,CACE,CAAC,EAELG,OAAO,IACNjB,KAAA,CAAA2B,aAAA;IAAKC,SAAS,EAAC;EAAmG,GAChH5B,KAAA,CAAA2B,aAAA,CAAC9B,OAAO;IAACmC,IAAI,EAAElC,WAAW,CAACmC;EAAG,CAAE,CAC7B,CACN,EAEA,CAAChB,OAAO,IAAIQ,SAAS,IACpBzB,KAAA,CAAA2B,aAAA;IAAKC,SAAS,EAAC;EAAmG,GAChH5B,KAAA,CAAA2B,aAAA,CAAC/B,UAAU,MAAE,CACV,CACN,EAEA,CAACqB,OAAO,IAAI,CAACQ,SAAS,IACrBzB,KAAA,CAAA2B,aAAA;IAAK,eAAY;EAAgC,GAC/C3B,KAAA,CAAA2B,aAAA,CAACvB,KAAK;IAACkB,QAAQ,EAAER,gBAAiB;IAACoB,MAAM,EAAEV;EAAQ,CAAE,CAClD,CACN,EACDxB,KAAA,CAAA2B,aAAA,CAACtB,aAAa,MAAE,CACb,CAAC;AAEV,CAAC;AAED,SAASI,IAAI","ignoreList":[]}
|
|
@@ -12,7 +12,8 @@ echarts.registerTheme('dark_theme', getChartTheme(Theme.Dark));
|
|
|
12
12
|
echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
|
|
13
13
|
export const Chart = _ref => {
|
|
14
14
|
let {
|
|
15
|
-
values
|
|
15
|
+
values,
|
|
16
|
+
timeSpan
|
|
16
17
|
} = _ref;
|
|
17
18
|
const {
|
|
18
19
|
isDark
|
|
@@ -27,7 +28,8 @@ export const Chart = _ref => {
|
|
|
27
28
|
option: getOption({
|
|
28
29
|
values,
|
|
29
30
|
isDark,
|
|
30
|
-
lang
|
|
31
|
+
lang,
|
|
32
|
+
timeSpan
|
|
31
33
|
})
|
|
32
34
|
});
|
|
33
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","names":["BaseChart","getChartTheme","Theme","useLayoutProvider","useLocale","CustomChart","LineChart","DatasetComponent","GraphicComponent","GridSimpleComponent","TooltipComponent","echarts","CanvasRenderer","React","CHART_HEIGHT","getOption","use","registerTheme","Dark","Light","Chart","_ref","values","isDark","lang","createElement","chartHeight","option"],"sources":["../../../../src/InstrumentsPriceChartWidget/components/Chart.tsx"],"sourcesContent":["import {\n BaseChart,\n getChartTheme,\n Theme,\n useLayoutProvider,\n} from '@oanda/labs-widget-common';\nimport { useLocale } from '@oanda/mono-i18n';\nimport { CustomChart, LineChart } from 'echarts/charts';\nimport {\n DatasetComponent,\n GraphicComponent,\n GridSimpleComponent,\n TooltipComponent,\n} from 'echarts/components';\nimport * as echarts from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport React from 'react';\n\nimport { CHART_HEIGHT } from './constants';\nimport { getOption } from './getOption';\nimport type { ChartProps } from './types';\n\necharts.use([\n GridSimpleComponent,\n GraphicComponent,\n LineChart,\n DatasetComponent,\n CustomChart,\n CanvasRenderer,\n TooltipComponent,\n]);\n\necharts.registerTheme('dark_theme', getChartTheme(Theme.Dark));\necharts.registerTheme('light_theme', getChartTheme(Theme.Light));\n\nexport const Chart = ({ values }: ChartProps) => {\n const { isDark } = useLayoutProvider();\n const { lang } = useLocale();\n\n return (\n <BaseChart\n chartHeight={CHART_HEIGHT}\n echarts={echarts}\n isDark={isDark}\n option={getOption({\n values,\n isDark,\n lang,\n })}\n />\n );\n};\n"],"mappings":"AAAA,SACEA,SAAS,EACTC,aAAa,EACbC,KAAK,EACLC,iBAAiB,QACZ,2BAA2B;AAClC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,WAAW,EAAEC,SAAS,QAAQ,gBAAgB;AACvD,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,mBAAmB,EACnBC,gBAAgB,QACX,oBAAoB;AAC3B,OAAO,KAAKC,OAAO,MAAM,cAAc;AACvC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,YAAY,QAAQ,aAAa;AAC1C,SAASC,SAAS,QAAQ,aAAa;AAGvCJ,OAAO,CAACK,GAAG,CAAC,CACVP,mBAAmB,EACnBD,gBAAgB,EAChBF,SAAS,EACTC,gBAAgB,EAChBF,WAAW,EACXO,cAAc,EACdF,gBAAgB,CACjB,CAAC;AAEFC,OAAO,CAACM,aAAa,CAAC,YAAY,EAAEhB,aAAa,CAACC,KAAK,CAACgB,IAAI,CAAC,CAAC;AAC9DP,OAAO,CAACM,aAAa,CAAC,aAAa,EAAEhB,aAAa,CAACC,KAAK,CAACiB,KAAK,CAAC,CAAC;AAEhE,OAAO,MAAMC,KAAK,GAAGC,IAAA,
|
|
1
|
+
{"version":3,"file":"Chart.js","names":["BaseChart","getChartTheme","Theme","useLayoutProvider","useLocale","CustomChart","LineChart","DatasetComponent","GraphicComponent","GridSimpleComponent","TooltipComponent","echarts","CanvasRenderer","React","CHART_HEIGHT","getOption","use","registerTheme","Dark","Light","Chart","_ref","values","timeSpan","isDark","lang","createElement","chartHeight","option"],"sources":["../../../../src/InstrumentsPriceChartWidget/components/Chart.tsx"],"sourcesContent":["import {\n BaseChart,\n getChartTheme,\n Theme,\n useLayoutProvider,\n} from '@oanda/labs-widget-common';\nimport { useLocale } from '@oanda/mono-i18n';\nimport { CustomChart, LineChart } from 'echarts/charts';\nimport {\n DatasetComponent,\n GraphicComponent,\n GridSimpleComponent,\n TooltipComponent,\n} from 'echarts/components';\nimport * as echarts from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport React from 'react';\n\nimport { CHART_HEIGHT } from './constants';\nimport { getOption } from './getOption';\nimport type { ChartProps } from './types';\n\necharts.use([\n GridSimpleComponent,\n GraphicComponent,\n LineChart,\n DatasetComponent,\n CustomChart,\n CanvasRenderer,\n TooltipComponent,\n]);\n\necharts.registerTheme('dark_theme', getChartTheme(Theme.Dark));\necharts.registerTheme('light_theme', getChartTheme(Theme.Light));\n\nexport const Chart = ({ values, timeSpan }: ChartProps) => {\n const { isDark } = useLayoutProvider();\n const { lang } = useLocale();\n\n return (\n <BaseChart\n chartHeight={CHART_HEIGHT}\n echarts={echarts}\n isDark={isDark}\n option={getOption({\n values,\n isDark,\n lang,\n timeSpan,\n })}\n />\n );\n};\n"],"mappings":"AAAA,SACEA,SAAS,EACTC,aAAa,EACbC,KAAK,EACLC,iBAAiB,QACZ,2BAA2B;AAClC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,WAAW,EAAEC,SAAS,QAAQ,gBAAgB;AACvD,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,mBAAmB,EACnBC,gBAAgB,QACX,oBAAoB;AAC3B,OAAO,KAAKC,OAAO,MAAM,cAAc;AACvC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,YAAY,QAAQ,aAAa;AAC1C,SAASC,SAAS,QAAQ,aAAa;AAGvCJ,OAAO,CAACK,GAAG,CAAC,CACVP,mBAAmB,EACnBD,gBAAgB,EAChBF,SAAS,EACTC,gBAAgB,EAChBF,WAAW,EACXO,cAAc,EACdF,gBAAgB,CACjB,CAAC;AAEFC,OAAO,CAACM,aAAa,CAAC,YAAY,EAAEhB,aAAa,CAACC,KAAK,CAACgB,IAAI,CAAC,CAAC;AAC9DP,OAAO,CAACM,aAAa,CAAC,aAAa,EAAEhB,aAAa,CAACC,KAAK,CAACiB,KAAK,CAAC,CAAC;AAEhE,OAAO,MAAMC,KAAK,GAAGC,IAAA,IAAsC;EAAA,IAArC;IAAEC,MAAM;IAAEC;EAAqB,CAAC,GAAAF,IAAA;EACpD,MAAM;IAAEG;EAAO,CAAC,GAAGrB,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEsB;EAAK,CAAC,GAAGrB,SAAS,CAAC,CAAC;EAE5B,OACES,KAAA,CAAAa,aAAA,CAAC1B,SAAS;IACR2B,WAAW,EAAEb,YAAa;IAC1BH,OAAO,EAAEA,OAAQ;IACjBa,MAAM,EAAEA,MAAO;IACfI,MAAM,EAAEb,SAAS,CAAC;MAChBO,MAAM;MACNE,MAAM;MACNC,IAAI;MACJF;IACF,CAAC;EAAE,CACJ,CAAC;AAEN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useLocale } from '@oanda/mono-i18n';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
const getBrowserOffsetLabel = () => {
|
|
4
|
+
const parts = new Intl.DateTimeFormat(undefined, {
|
|
5
|
+
timeZoneName: 'longOffset'
|
|
6
|
+
}).formatToParts(new Date());
|
|
7
|
+
const tzPart = parts.find(p => p.type === 'timeZoneName');
|
|
8
|
+
return tzPart ? tzPart.value : '';
|
|
9
|
+
};
|
|
10
|
+
export const TimeZoneLabel = () => {
|
|
11
|
+
const {
|
|
12
|
+
lang
|
|
13
|
+
} = useLocale();
|
|
14
|
+
return React.createElement("span", {
|
|
15
|
+
className: "lw-ml-1 lw-font-sans lw-text-xs lw-font-bold",
|
|
16
|
+
"data-testid": "timezone-label"
|
|
17
|
+
}, `${lang('timezone_display', {
|
|
18
|
+
timezone: getBrowserOffsetLabel()
|
|
19
|
+
})}`);
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=TimeZoneLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeZoneLabel.js","names":["useLocale","React","getBrowserOffsetLabel","parts","Intl","DateTimeFormat","undefined","timeZoneName","formatToParts","Date","tzPart","find","p","type","value","TimeZoneLabel","lang","createElement","className","timezone"],"sources":["../../../../src/InstrumentsPriceChartWidget/components/TimeZoneLabel.tsx"],"sourcesContent":["import { useLocale } from '@oanda/mono-i18n';\nimport React from 'react';\n\nconst getBrowserOffsetLabel = (): string => {\n const parts = new Intl.DateTimeFormat(undefined, {\n timeZoneName: 'longOffset',\n }).formatToParts(new Date());\n\n const tzPart = parts.find((p) => p.type === 'timeZoneName');\n return tzPart ? tzPart.value : '';\n};\n\nexport const TimeZoneLabel = () => {\n const { lang } = useLocale();\n\n return (\n <span\n className=\"lw-ml-1 lw-font-sans lw-text-xs lw-font-bold\"\n data-testid=\"timezone-label\"\n >{`${lang('timezone_display', {\n timezone: getBrowserOffsetLabel(),\n })}`}</span>\n );\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,OAAOC,KAAK,MAAM,OAAO;AAEzB,MAAMC,qBAAqB,GAAGA,CAAA,KAAc;EAC1C,MAAMC,KAAK,GAAG,IAAIC,IAAI,CAACC,cAAc,CAACC,SAAS,EAAE;IAC/CC,YAAY,EAAE;EAChB,CAAC,CAAC,CAACC,aAAa,CAAC,IAAIC,IAAI,CAAC,CAAC,CAAC;EAE5B,MAAMC,MAAM,GAAGP,KAAK,CAACQ,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,IAAI,KAAK,cAAc,CAAC;EAC3D,OAAOH,MAAM,GAAGA,MAAM,CAACI,KAAK,GAAG,EAAE;AACnC,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,MAAM;IAAEC;EAAK,CAAC,GAAGhB,SAAS,CAAC,CAAC;EAE5B,OACEC,KAAA,CAAAgB,aAAA;IACEC,SAAS,EAAC,8CAA8C;IACxD,eAAY;EAAgB,GAC5B,GAAGF,IAAI,CAAC,kBAAkB,EAAE;IAC5BG,QAAQ,EAAEjB,qBAAqB,CAAC;EAClC,CAAC,CAAC,EAAS,CAAC;AAEhB,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const
|
|
3
|
-
const
|
|
4
|
-
return
|
|
5
|
-
hour: 'numeric',
|
|
6
|
-
hour12: true
|
|
7
|
-
});
|
|
1
|
+
import { TimeSpan } from '../../gql/types/graphql';
|
|
2
|
+
export const showSplitLine = (index, total) => {
|
|
3
|
+
const interval = Math.max(1, Math.floor(total / 6));
|
|
4
|
+
return index % interval === 0;
|
|
8
5
|
};
|
|
6
|
+
const showChartIntervalLabel = (timeSpan, values, index) => {
|
|
7
|
+
const date = new Date(values[index].point);
|
|
8
|
+
const labelInterval = Math.max(1, Math.floor(values.length / 6));
|
|
9
|
+
if (timeSpan === TimeSpan.Month_6 || timeSpan === TimeSpan.Year_1 || timeSpan === TimeSpan.Year_5) {
|
|
10
|
+
const prev = index > 0 ? new Date(values[index - 1].point) : null;
|
|
11
|
+
const monthChanged = !prev || date.getMonth() !== prev.getMonth() || date.getFullYear() !== prev.getFullYear();
|
|
12
|
+
return monthChanged;
|
|
13
|
+
}
|
|
14
|
+
return index % labelInterval === 0;
|
|
15
|
+
};
|
|
16
|
+
export const labelFormatter = (timeSpan, values) => (_, index) => {
|
|
17
|
+
const date = new Date(values[index].point);
|
|
18
|
+
if (!showChartIntervalLabel(timeSpan, values, index)) return '';
|
|
19
|
+
switch (timeSpan) {
|
|
20
|
+
case TimeSpan.Day_1:
|
|
21
|
+
const hour = date.getHours();
|
|
22
|
+
return `${String(hour).padStart(2, '0')}:00`;
|
|
23
|
+
case TimeSpan.Week_1:
|
|
24
|
+
case TimeSpan.Month_1:
|
|
25
|
+
return date.toLocaleDateString(undefined, {
|
|
26
|
+
day: '2-digit',
|
|
27
|
+
month: 'short'
|
|
28
|
+
});
|
|
29
|
+
case TimeSpan.Month_6:
|
|
30
|
+
case TimeSpan.Year_1:
|
|
31
|
+
case TimeSpan.Year_5:
|
|
32
|
+
return date.toLocaleDateString(undefined, {
|
|
33
|
+
month: 'short'
|
|
34
|
+
});
|
|
35
|
+
default:
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const chartDateTimeFormat = iso => new Date(iso).toLocaleString(undefined, {
|
|
40
|
+
year: 'numeric',
|
|
41
|
+
month: '2-digit',
|
|
42
|
+
day: '2-digit',
|
|
43
|
+
hour: '2-digit',
|
|
44
|
+
minute: '2-digit',
|
|
45
|
+
hour12: false
|
|
46
|
+
});
|
|
9
47
|
export const tooltipFormatter = _ref => {
|
|
10
48
|
let {
|
|
11
49
|
lang,
|
|
@@ -16,9 +54,9 @@ export const tooltipFormatter = _ref => {
|
|
|
16
54
|
high,
|
|
17
55
|
close,
|
|
18
56
|
low,
|
|
19
|
-
|
|
57
|
+
point
|
|
20
58
|
} = data;
|
|
21
|
-
const date = chartDateTimeFormat(
|
|
59
|
+
const date = chartDateTimeFormat(point);
|
|
22
60
|
return `
|
|
23
61
|
<div style="display:flex; flex-direction:column;">
|
|
24
62
|
<span style="margin-bottom:5px;">${date}</span>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","names":["
|
|
1
|
+
{"version":3,"file":"formatters.js","names":["TimeSpan","showSplitLine","index","total","interval","Math","max","floor","showChartIntervalLabel","timeSpan","values","date","Date","point","labelInterval","length","Month_6","Year_1","Year_5","prev","monthChanged","getMonth","getFullYear","labelFormatter","_","Day_1","hour","getHours","String","padStart","Week_1","Month_1","toLocaleDateString","undefined","day","month","chartDateTimeFormat","iso","toLocaleString","year","minute","hour12","tooltipFormatter","_ref","lang","data","open","high","close","low","toFixed"],"sources":["../../../../src/InstrumentsPriceChartWidget/components/formatters.ts"],"sourcesContent":["import { TimeSpan } from '../../gql/types/graphql';\nimport type { TooltipFormatterParams } from './types';\n\nexport const showSplitLine = (index: number, total: number): boolean => {\n const interval = Math.max(1, Math.floor(total / 6));\n return index % interval === 0;\n};\n\nconst showChartIntervalLabel = (\n timeSpan: TimeSpan,\n values: { point: string }[],\n index: number\n): boolean => {\n const date = new Date(values[index].point);\n const labelInterval = Math.max(1, Math.floor(values.length / 6));\n\n if (\n timeSpan === TimeSpan.Month_6 ||\n timeSpan === TimeSpan.Year_1 ||\n timeSpan === TimeSpan.Year_5\n ) {\n const prev = index > 0 ? new Date(values[index - 1].point) : null;\n const monthChanged =\n !prev ||\n date.getMonth() !== prev.getMonth() ||\n date.getFullYear() !== prev.getFullYear();\n\n return monthChanged;\n }\n\n return index % labelInterval === 0;\n};\n\nexport const labelFormatter =\n (timeSpan: TimeSpan, values: { point: string }[]) =>\n (_: string, index: number): string => {\n const date = new Date(values[index].point);\n\n if (!showChartIntervalLabel(timeSpan, values, index)) return '';\n\n switch (timeSpan) {\n case TimeSpan.Day_1:\n const hour = date.getHours();\n return `${String(hour).padStart(2, '0')}:00`;\n\n case TimeSpan.Week_1:\n case TimeSpan.Month_1:\n return date.toLocaleDateString(undefined, {\n day: '2-digit',\n month: 'short',\n });\n\n case TimeSpan.Month_6:\n case TimeSpan.Year_1:\n case TimeSpan.Year_5:\n return date.toLocaleDateString(undefined, {\n month: 'short',\n });\n\n default:\n return '';\n }\n };\n\nconst chartDateTimeFormat = (iso: string) =>\n new Date(iso).toLocaleString(undefined, {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n hour12: false,\n });\n\nexport const tooltipFormatter = ({ lang, data }: TooltipFormatterParams) => {\n const { open, high, close, low, point } = data;\n const date = chartDateTimeFormat(point);\n\n return `\n <div style=\"display:flex; flex-direction:column;\">\n <span style=\"margin-bottom:5px;\">${date}</span>\n ${lang('open')}: ${open.toFixed(4)}<br />\n ${lang('high')}: ${high.toFixed(4)}<br />\n ${lang('low')}: ${low.toFixed(4)}<br />\n ${lang('close')}: ${close.toFixed(4)}\n </div>\n `;\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,yBAAyB;AAG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9C,MAAMlC,IAAI,GAAGyB,mBAAmB,CAACvB,KAAK,CAAC;EAEvC,OAAO;AACT;AACA,yCAAyCF,IAAI;AAC7C,QAAQiC,IAAI,CAAC,MAAM,CAAC,KAAKE,IAAI,CAACI,OAAO,CAAC,CAAC,CAAC;AACxC,QAAQN,IAAI,CAAC,MAAM,CAAC,KAAKG,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC;AACxC,QAAQN,IAAI,CAAC,KAAK,CAAC,KAAKK,GAAG,CAACC,OAAO,CAAC,CAAC,CAAC;AACtC,QAAQN,IAAI,CAAC,OAAO,CAAC,KAAKI,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC;AAC1C;AACA,GAAG;AACH,CAAC","ignoreList":[]}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { colorPalette, getGridLines, getLineCommons } from '@oanda/labs-widget-common';
|
|
2
2
|
import { CHART_HEIGHT, CHART_INTERVAL, CHART_WIDTH, X_LABEL_SIZE, Y_LABEL_SIZE_DESKTOP } from './constants';
|
|
3
|
-
import {
|
|
3
|
+
import { labelFormatter, showSplitLine, tooltipFormatter } from './formatters';
|
|
4
4
|
export const getOption = _ref => {
|
|
5
5
|
let {
|
|
6
6
|
values,
|
|
7
7
|
isDark,
|
|
8
|
-
lang
|
|
8
|
+
lang,
|
|
9
|
+
timeSpan
|
|
9
10
|
} = _ref;
|
|
10
|
-
const priceValues = values.map(d => d.
|
|
11
|
-
const timestamps = values.map(d => dailyFormatter(d.time));
|
|
12
|
-
const labelInterval = Math.max(1, Math.floor(timestamps.length / 6));
|
|
11
|
+
const priceValues = values.map(d => d.high);
|
|
13
12
|
const gridLines = getGridLines({
|
|
14
13
|
isDark,
|
|
15
14
|
chartWidth: CHART_WIDTH,
|
|
@@ -19,6 +18,7 @@ export const getOption = _ref => {
|
|
|
19
18
|
bottomLeftBox: false
|
|
20
19
|
});
|
|
21
20
|
return {
|
|
21
|
+
animation: false,
|
|
22
22
|
tooltip: {
|
|
23
23
|
trigger: 'axis',
|
|
24
24
|
axisPointer: {
|
|
@@ -36,18 +36,18 @@ export const getOption = _ref => {
|
|
|
36
36
|
xAxis: {
|
|
37
37
|
type: 'category',
|
|
38
38
|
boundaryGap: false,
|
|
39
|
-
data:
|
|
39
|
+
data: values.map(d => d.point),
|
|
40
40
|
axisTick: {
|
|
41
41
|
show: false
|
|
42
42
|
},
|
|
43
43
|
axisLabel: {
|
|
44
|
-
|
|
45
|
-
interval:
|
|
46
|
-
formatter: (
|
|
44
|
+
padding: [0, 0, 0, 30],
|
|
45
|
+
interval: 'auto',
|
|
46
|
+
formatter: labelFormatter(timeSpan, values)
|
|
47
47
|
},
|
|
48
48
|
splitLine: {
|
|
49
49
|
show: true,
|
|
50
|
-
interval: index => index
|
|
50
|
+
interval: index => showSplitLine(index, values.length)
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
yAxis: {
|
|
@@ -63,7 +63,7 @@ export const getOption = _ref => {
|
|
|
63
63
|
show: false
|
|
64
64
|
},
|
|
65
65
|
axisLabel: {
|
|
66
|
-
margin:
|
|
66
|
+
margin: 10,
|
|
67
67
|
formatter: value => {
|
|
68
68
|
const dataMin = Math.floor(Math.min(...priceValues) * 100) / 100;
|
|
69
69
|
const dataMax = Math.ceil(Math.max(...priceValues) * 100) / 100;
|
|
@@ -81,9 +81,9 @@ export const getOption = _ref => {
|
|
|
81
81
|
name: 'price-close',
|
|
82
82
|
type: 'line',
|
|
83
83
|
data: values.map(d => ({
|
|
84
|
-
value: d.
|
|
85
|
-
...d
|
|
86
|
-
time: d.
|
|
84
|
+
value: d.high,
|
|
85
|
+
...d,
|
|
86
|
+
time: d.point
|
|
87
87
|
})),
|
|
88
88
|
smooth: true,
|
|
89
89
|
symbol: 'none',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOption.js","names":["colorPalette","getGridLines","getLineCommons","CHART_HEIGHT","CHART_INTERVAL","CHART_WIDTH","X_LABEL_SIZE","Y_LABEL_SIZE_DESKTOP","
|
|
1
|
+
{"version":3,"file":"getOption.js","names":["colorPalette","getGridLines","getLineCommons","CHART_HEIGHT","CHART_INTERVAL","CHART_WIDTH","X_LABEL_SIZE","Y_LABEL_SIZE_DESKTOP","labelFormatter","showSplitLine","tooltipFormatter","getOption","_ref","values","isDark","lang","timeSpan","priceValues","map","d","high","gridLines","chartWidth","chartHeight","xLabelsSize","yLabelSize","bottomLeftBox","animation","tooltip","trigger","axisPointer","axis","formatter","params","p","Array","isArray","data","xAxis","type","boundaryGap","point","axisTick","show","axisLabel","padding","interval","splitLine","index","length","yAxis","position","min","value","Math","floor","max","ceil","axisLine","margin","dataMin","dataMax","toFixed","series","name","time","smooth","symbol","lineStyle","color","navyBlue","width","areaStyle","x","y","x2","y2","colorStops","offset","brightBlue30","brightBlue","grid","top","left","right","bottom","graphic","shape","x1","y1"],"sources":["../../../../src/InstrumentsPriceChartWidget/components/getOption.ts"],"sourcesContent":["import {\n colorPalette,\n getGridLines,\n getLineCommons,\n} from '@oanda/labs-widget-common';\n\nimport {\n CHART_HEIGHT,\n CHART_INTERVAL,\n CHART_WIDTH,\n X_LABEL_SIZE,\n Y_LABEL_SIZE_DESKTOP,\n} from './constants';\nimport { labelFormatter, showSplitLine, tooltipFormatter } from './formatters';\nimport type { ChartValue, GetOptionType } from './types';\n\nexport const getOption: GetOptionType = ({\n values,\n isDark,\n lang,\n timeSpan,\n}) => {\n const priceValues = values.map((d) => d.high);\n\n const gridLines = getGridLines({\n isDark,\n chartWidth: CHART_WIDTH,\n chartHeight: CHART_HEIGHT,\n xLabelsSize: X_LABEL_SIZE,\n yLabelSize: Y_LABEL_SIZE_DESKTOP,\n bottomLeftBox: false,\n });\n\n return {\n animation: false,\n tooltip: {\n trigger: 'axis',\n axisPointer: {\n axis: 'x',\n },\n formatter: (params) => {\n const p = Array.isArray(params) ? params[0] : params;\n const data = p.data as {\n point: string;\n open: number;\n high: number;\n low: number;\n close: number;\n };\n\n return tooltipFormatter({ lang, data });\n },\n },\n xAxis: {\n type: 'category',\n boundaryGap: false,\n data: values.map((d) => d.point),\n axisTick: { show: false },\n axisLabel: {\n padding: [0, 0, 0, 30],\n interval: 'auto',\n formatter: labelFormatter(timeSpan, values),\n },\n splitLine: {\n show: true,\n interval: (index: number) => showSplitLine(index, values.length),\n },\n },\n yAxis: {\n type: 'value',\n position: 'right',\n min: (value: ChartValue) =>\n Math.floor(value.min * 100) / 100 - CHART_INTERVAL,\n max: (value: ChartValue) =>\n Math.ceil(value.max * 100) / 100 + CHART_INTERVAL,\n interval: CHART_INTERVAL,\n axisLine: { show: false },\n axisTick: { show: false },\n axisLabel: {\n margin: 10,\n formatter: (value: number) => {\n const dataMin = Math.floor(Math.min(...priceValues) * 100) / 100;\n const dataMax = Math.ceil(Math.max(...priceValues) * 100) / 100;\n if (value < dataMin || value > dataMax) {\n return '';\n }\n return value.toFixed(2);\n },\n },\n splitLine: {\n show: true,\n },\n },\n series: [\n {\n name: 'price-close',\n type: 'line',\n data: values.map((d) => ({\n value: d.high,\n ...d,\n time: d.point,\n })),\n smooth: true,\n symbol: 'none',\n lineStyle: {\n color: colorPalette.navyBlue,\n width: 2,\n },\n areaStyle: {\n color: {\n type: 'linear',\n x: 0,\n y: 0,\n x2: 0,\n y2: 1,\n colorStops: [\n { offset: 0, color: colorPalette.brightBlue30 },\n { offset: 1, color: colorPalette.brightBlue },\n ],\n },\n },\n },\n ],\n grid: [\n {\n name: 'main-grid',\n top: 0,\n left: 0,\n right: `${Y_LABEL_SIZE_DESKTOP}px`,\n bottom: `${X_LABEL_SIZE}px`,\n },\n ],\n graphic: [\n ...gridLines,\n {\n ...getLineCommons(isDark),\n top: 0,\n right: 0,\n shape: {\n x1: 0,\n y1: 0,\n x2: 0,\n y2: 0,\n },\n },\n ],\n };\n};\n"],"mappings":"AAAA,SACEA,YAAY,EACZC,YAAY,EACZC,cAAc,QACT,2BAA2B;AAElC,SACEC,YAAY,EACZC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZ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js","names":[],"sources":["../../../../src/InstrumentsPriceChartWidget/components/types.ts"],"sourcesContent":["import type { EChartsOption } from 'echarts';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/InstrumentsPriceChartWidget/components/types.ts"],"sourcesContent":["import type { EChartsOption } from 'echarts';\n\nimport type { Candle, TimeSpan } from '../../gql/types/graphql';\n\nexport interface ChartProps {\n values: Candle[];\n timeSpan: TimeSpan;\n}\n\nexport interface GetOptionProps {\n values: Candle[];\n isDark: boolean;\n lang: (label: string) => string;\n timeSpan: TimeSpan;\n}\n\nexport type GetOptionType = (props: GetOptionProps) => EChartsOption;\n\nexport interface ChartValue {\n min: number;\n max: number;\n}\n\nexport interface TooltipData {\n point: string;\n open: number;\n high: number;\n low: number;\n close: number;\n}\n\nexport interface TooltipFormatterParams {\n data: TooltipData;\n lang: (label: string) => string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Granularity, TimeSpan } from '../gql/types/graphql';
|
|
2
2
|
const timeUnitConfig = [{
|
|
3
|
-
value:
|
|
3
|
+
value: TimeSpan.Day_1,
|
|
4
4
|
label: '1d',
|
|
5
5
|
tooltipLabel: {
|
|
6
6
|
translationKey: 'day',
|
|
7
7
|
count: 1
|
|
8
8
|
}
|
|
9
9
|
}, {
|
|
10
|
-
value:
|
|
10
|
+
value: TimeSpan.Week_1,
|
|
11
11
|
label: '1w',
|
|
12
12
|
tooltipLabel: {
|
|
13
13
|
translationKey: 'week',
|
|
14
14
|
count: 1
|
|
15
15
|
}
|
|
16
16
|
}, {
|
|
17
|
-
value:
|
|
17
|
+
value: TimeSpan.Month_1,
|
|
18
18
|
label: '1m',
|
|
19
19
|
tooltipLabel: {
|
|
20
20
|
translationKey: 'month',
|
|
21
21
|
count: 1
|
|
22
22
|
}
|
|
23
23
|
}, {
|
|
24
|
-
value:
|
|
24
|
+
value: TimeSpan.Month_6,
|
|
25
25
|
label: '6m',
|
|
26
26
|
tooltipLabel: {
|
|
27
27
|
translationKey: 'month',
|
|
28
28
|
count: 6
|
|
29
29
|
}
|
|
30
30
|
}, {
|
|
31
|
-
value:
|
|
31
|
+
value: TimeSpan.Year_1,
|
|
32
32
|
label: '1y',
|
|
33
33
|
tooltipLabel: {
|
|
34
34
|
translationKey: 'year',
|
|
35
35
|
count: 1
|
|
36
36
|
}
|
|
37
37
|
}];
|
|
38
|
-
|
|
38
|
+
const granularityForTimeSpan = {
|
|
39
|
+
[TimeSpan.Day_1]: Granularity.H1,
|
|
40
|
+
[TimeSpan.Week_1]: Granularity.H4,
|
|
41
|
+
[TimeSpan.Month_1]: Granularity.D1,
|
|
42
|
+
[TimeSpan.Month_6]: Granularity.D1,
|
|
43
|
+
[TimeSpan.Year_1]: Granularity.D1
|
|
44
|
+
};
|
|
45
|
+
export { granularityForTimeSpan, timeUnitConfig };
|
|
39
46
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["
|
|
1
|
+
{"version":3,"file":"config.js","names":["Granularity","TimeSpan","timeUnitConfig","value","Day_1","label","tooltipLabel","translationKey","count","Week_1","Month_1","Month_6","Year_1","granularityForTimeSpan","H1","H4","D1"],"sources":["../../../src/InstrumentsPriceChartWidget/config.ts"],"sourcesContent":["import { Granularity, TimeSpan } from '../gql/types/graphql';\nimport type { TimeSpanSubset } from './types';\n\nconst timeUnitConfig = [\n {\n value: TimeSpan.Day_1,\n label: '1d',\n tooltipLabel: {\n translationKey: 'day',\n count: 1,\n },\n },\n {\n value: TimeSpan.Week_1,\n label: '1w',\n tooltipLabel: {\n translationKey: 'week',\n count: 1,\n },\n },\n {\n value: TimeSpan.Month_1,\n label: '1m',\n tooltipLabel: {\n translationKey: 'month',\n count: 1,\n },\n },\n\n {\n value: TimeSpan.Month_6,\n label: '6m',\n tooltipLabel: {\n translationKey: 'month',\n count: 6,\n },\n },\n {\n value: TimeSpan.Year_1,\n label: '1y',\n tooltipLabel: {\n translationKey: 'year',\n count: 1,\n },\n },\n];\n\nconst granularityForTimeSpan: Record<TimeSpanSubset, Granularity> = {\n [TimeSpan.Day_1]: Granularity.H1,\n [TimeSpan.Week_1]: Granularity.H4,\n [TimeSpan.Month_1]: Granularity.D1,\n [TimeSpan.Month_6]: Granularity.D1,\n [TimeSpan.Year_1]: Granularity.D1,\n};\n\nexport { granularityForTimeSpan, timeUnitConfig };\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,sBAAsB;AAG5D,MAAMC,cAAc,GAAG,CACrB;EACEC,KAAK,EAAEF,QAAQ,CAACG,KAAK;EACrBC,KAAK,EAAE,IAAI;EACXC,YAAY,EAAE;IACZC,cAAc,EAAE,KAAK;IACrBC,KAAK,EAAE;EACT;AACF,CAAC,EACD;EACEL,KAAK,EAAEF,QAAQ,CAACQ,MAAM;EACtBJ,KAAK,EAAE,IAAI;EACXC,YAAY,EAAE;IACZC,cAAc,EAAE,MAAM;IACtBC,KAAK,EAAE;EACT;AACF,CAAC,EACD;EACEL,KAAK,EAAEF,QAAQ,CAACS,OAAO;EACvBL,KAAK,EAAE,IAAI;EACXC,YAAY,EAAE;IACZC,cAAc,EAAE,OAAO;IACvBC,KAAK,EAAE;EACT;AACF,CAAC,EAED;EACEL,KAAK,EAAEF,QAAQ,CAACU,OAAO;EACvBN,KAAK,EAAE,IAAI;EACXC,YAAY,EAAE;IACZC,cAAc,EAAE,OAAO;IACvBC,KAAK,EAAE;EACT;AACF,CAAC,EACD;EACEL,KAAK,EAAEF,QAAQ,CAACW,MAAM;EACtBP,KAAK,EAAE,IAAI;EACXC,YAAY,EAAE;IACZC,cAAc,EAAE,MAAM;IACtBC,KAAK,EAAE;EACT;AACF,CAAC,CACF;AAED,MAAMK,sBAA2D,GAAG;EAClE,CAACZ,QAAQ,CAACG,KAAK,GAAGJ,WAAW,CAACc,EAAE;EAChC,CAACb,QAAQ,CAACQ,MAAM,GAAGT,WAAW,CAACe,EAAE;EACjC,CAACd,QAAQ,CAACS,OAAO,GAAGV,WAAW,CAACgB,EAAE;EAClC,CAACf,QAAQ,CAACU,OAAO,GAAGX,WAAW,CAACgB,EAAE;EAClC,CAACf,QAAQ,CAACW,MAAM,GAAGZ,WAAW,CAACgB;AACjC,CAAC;AAED,SAASH,sBAAsB,EAAEX,cAAc","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validateLocale, validateToolParams } from '@oanda/labs-widget-common';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
|
-
import { Division } from '../gql/types/graphql';
|
|
4
|
+
import { Division, InstrumentDataSource } from '../gql/types/graphql';
|
|
5
5
|
import { InstrumentsPriceChartWidget } from './InstrumentsPriceChartWidget';
|
|
6
6
|
const {
|
|
7
7
|
graphqlUrl
|
|
@@ -13,12 +13,15 @@ dataInstrumentsPriceChartParamsElements.forEach(element => {
|
|
|
13
13
|
const mode = element.getAttribute('data-mode');
|
|
14
14
|
const {
|
|
15
15
|
division,
|
|
16
|
-
locale
|
|
16
|
+
locale,
|
|
17
|
+
instrument,
|
|
18
|
+
dataSource
|
|
17
19
|
} = JSON.parse(params);
|
|
18
20
|
const isParamError = validateToolParams({
|
|
19
21
|
division,
|
|
20
22
|
locale,
|
|
21
|
-
graphqlUrl
|
|
23
|
+
graphqlUrl,
|
|
24
|
+
dataSource
|
|
22
25
|
}, [{
|
|
23
26
|
name: 'locale',
|
|
24
27
|
valueCheck: value => validateLocale(value)
|
|
@@ -27,10 +30,15 @@ dataInstrumentsPriceChartParamsElements.forEach(element => {
|
|
|
27
30
|
valueCheck: value => Object.values(Division).includes(value)
|
|
28
31
|
}, {
|
|
29
32
|
name: 'graphqlUrl'
|
|
33
|
+
}, {
|
|
34
|
+
name: 'dataSource',
|
|
35
|
+
valueCheck: value => Object.values(InstrumentDataSource).includes(value)
|
|
30
36
|
}]);
|
|
31
37
|
root.render(React.createElement(InstrumentsPriceChartWidget, {
|
|
38
|
+
dataSource: dataSource,
|
|
32
39
|
division: division,
|
|
33
40
|
graphqlUrl: graphqlUrl,
|
|
41
|
+
instrument: instrument,
|
|
34
42
|
isParamError: isParamError,
|
|
35
43
|
locale: locale,
|
|
36
44
|
theme: mode
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["validateLocale","validateToolParams","React","createRoot","Division","InstrumentsPriceChartWidget","graphqlUrl","window","widgetsConfig","dataInstrumentsPriceChartParamsElements","document","querySelectorAll","forEach","element","root","params","getAttribute","mode","division","locale","JSON","parse","isParamError","name","valueCheck","value","Object","values","includes","render","createElement","theme"],"sources":["../../../src/InstrumentsPriceChartWidget/render.tsx"],"sourcesContent":["import type { Theme } from '@oanda/labs-widget-common';\nimport { validateLocale, validateToolParams } from '@oanda/labs-widget-common';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { Division } from '../gql/types/graphql';\nimport { InstrumentsPriceChartWidget } from './InstrumentsPriceChartWidget';\n\nconst { graphqlUrl } = window.widgetsConfig || {};\n\nconst dataInstrumentsPriceChartParamsElements = document.querySelectorAll(\n 'div[data-instruments-price-chart-params]'\n);\n\ndataInstrumentsPriceChartParamsElements.forEach((element) => {\n const root = createRoot(element);\n const params = element.getAttribute('data-instruments-price-chart-params');\n const mode = element.getAttribute('data-mode');\n const { division, locale } = JSON.parse(params as string);\n\n const isParamError = validateToolParams(\n {\n division,\n locale,\n graphqlUrl,\n },\n [\n {\n name: 'locale',\n valueCheck: (value: string | undefined) => validateLocale(value),\n },\n {\n name: 'division',\n valueCheck: (value: Division) =>\n Object.values(Division).includes(value),\n },\n {\n name: 'graphqlUrl',\n },\n ]\n );\n\n root.render(\n <InstrumentsPriceChartWidget\n division={division}\n graphqlUrl={graphqlUrl}\n isParamError={isParamError}\n locale={locale}\n theme={mode as Theme}\n />\n );\n});\n"],"mappings":"AACA,SAASA,cAAc,EAAEC,kBAAkB,QAAQ,2BAA2B;AAC9E,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,SAASC,QAAQ,QAAQ,sBAAsB;
|
|
1
|
+
{"version":3,"file":"render.js","names":["validateLocale","validateToolParams","React","createRoot","Division","InstrumentDataSource","InstrumentsPriceChartWidget","graphqlUrl","window","widgetsConfig","dataInstrumentsPriceChartParamsElements","document","querySelectorAll","forEach","element","root","params","getAttribute","mode","division","locale","instrument","dataSource","JSON","parse","isParamError","name","valueCheck","value","Object","values","includes","render","createElement","theme"],"sources":["../../../src/InstrumentsPriceChartWidget/render.tsx"],"sourcesContent":["import type { Theme } from '@oanda/labs-widget-common';\nimport { validateLocale, validateToolParams } from '@oanda/labs-widget-common';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { Division, InstrumentDataSource } from '../gql/types/graphql';\nimport { InstrumentsPriceChartWidget } from './InstrumentsPriceChartWidget';\n\nconst { graphqlUrl } = window.widgetsConfig || {};\n\nconst dataInstrumentsPriceChartParamsElements = document.querySelectorAll(\n 'div[data-instruments-price-chart-params]'\n);\n\ndataInstrumentsPriceChartParamsElements.forEach((element) => {\n const root = createRoot(element);\n const params = element.getAttribute('data-instruments-price-chart-params');\n const mode = element.getAttribute('data-mode');\n const { division, locale, instrument, dataSource } = JSON.parse(\n params as string\n );\n\n const isParamError = validateToolParams(\n {\n division,\n locale,\n graphqlUrl,\n dataSource,\n },\n [\n {\n name: 'locale',\n valueCheck: (value: string | undefined) => validateLocale(value),\n },\n {\n name: 'division',\n valueCheck: (value: Division) =>\n Object.values(Division).includes(value),\n },\n {\n name: 'graphqlUrl',\n },\n {\n name: 'dataSource',\n valueCheck: (value: InstrumentDataSource) =>\n Object.values(InstrumentDataSource).includes(value),\n },\n ]\n );\n\n root.render(\n <InstrumentsPriceChartWidget\n dataSource={dataSource}\n division={division}\n graphqlUrl={graphqlUrl}\n instrument={instrument}\n isParamError={isParamError}\n locale={locale}\n theme={mode as Theme}\n />\n );\n});\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AAC;EAEDb,IAAI,CAACiB,MAAM,CACT9B,KAAA,CAAA+B,aAAA,CAAC3B,2BAA2B;IAC1BgB,UAAU,EAAEA,UAAW;IACvBH,QAAQ,EAAEA,QAAS;IACnBZ,UAAU,EAAEA,UAAW;IACvBc,UAAU,EAAEA,UAAW;IACvBI,YAAY,EAAEA,YAAa;IAC3BL,MAAM,EAAEA,MAAO;IACfc,KAAK,EAAEhB;EAAc,CACtB,CACH,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["TimeSpan","TimeSpanSubset","Day_1","Week_1","Month_1","Month_6","Year_1"],"sources":["../../../src/InstrumentsPriceChartWidget/types.ts"],"sourcesContent":["import type { WidgetConfig } from '@oanda/labs-widget-common';\n\nimport type { Division } from '../gql/types/graphql';\nimport { TimeSpan } from '../gql/types/graphql';\n\nexport interface InstrumentsPriceChartConfig extends WidgetConfig {\n division: Division;\n}\n\nexport interface MainProps {\n division: Division;\n}\n\nexport enum TimeSpanSubset {\n Day_1 = TimeSpan.Day_1,\n Week_1 = TimeSpan.Week_1,\n Month_1 = TimeSpan.Month_1,\n Month_6 = TimeSpan.Month_6,\n Year_1 = TimeSpan.Year_1,\n}\n"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,sBAAsB;
|
|
1
|
+
{"version":3,"file":"types.js","names":["TimeSpan","TimeSpanSubset","Day_1","Week_1","Month_1","Month_6","Year_1"],"sources":["../../../src/InstrumentsPriceChartWidget/types.ts"],"sourcesContent":["import type { WidgetConfig } from '@oanda/labs-widget-common';\n\nimport type { Division, InstrumentDataSource } from '../gql/types/graphql';\nimport { TimeSpan } from '../gql/types/graphql';\n\nexport interface InstrumentsPriceChartConfig extends WidgetConfig {\n division: Division;\n instrument: string;\n dataSource: InstrumentDataSource;\n}\n\nexport interface MainProps {\n division: Division;\n instrument: string;\n dataSource: InstrumentDataSource;\n}\n\nexport enum TimeSpanSubset {\n Day_1 = TimeSpan.Day_1,\n Week_1 = TimeSpan.Week_1,\n Month_1 = TimeSpan.Month_1,\n Month_6 = TimeSpan.Month_6,\n Year_1 = TimeSpan.Year_1,\n}\n"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,sBAAsB;AAc/C,WAAYC,cAAc,aAAdA,cAAc;EAAdA,cAAc,CAAdA,cAAc,YAChBD,QAAQ,CAACE,KAAK;EADZD,cAAc,CAAdA,cAAc,aAEfD,QAAQ,CAACG,MAAM;EAFdF,cAAc,CAAdA,cAAc,cAGdD,QAAQ,CAACI,OAAO;EAHhBH,cAAc,CAAdA,cAAc,cAIdD,QAAQ,CAACK,OAAO;EAJhBJ,cAAc,CAAdA,cAAc,aAKfD,QAAQ,CAACM,MAAM;EAAA,OALdL,cAAc;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["granularityForTimeSpan","getGranularityForTimeSpan","timeSpan","getCandles","data","priceCandles","candle","filter","c"],"sources":["../../../src/InstrumentsPriceChartWidget/utils.ts"],"sourcesContent":["import type {\n Candle,\n Granularity,\n PriceCandlesQuery,\n TimeSpan,\n} from '../gql/types/graphql';\nimport { granularityForTimeSpan } from './config';\nimport type { TimeSpanSubset } from './types';\n\nexport const getGranularityForTimeSpan = (timeSpan: TimeSpan): Granularity =>\n granularityForTimeSpan[timeSpan as unknown as TimeSpanSubset];\n\nexport const getCandles = (\n data: PriceCandlesQuery | undefined\n): Candle[] | undefined =>\n data?.priceCandles.candle.filter((c): c is Candle => c !== null);\n"],"mappings":"AAMA,SAASA,sBAAsB,QAAQ,UAAU;AAGjD,OAAO,MAAMC,yBAAyB,GAAIC,QAAkB,IAC1DF,sBAAsB,CAACE,QAAQ,CAA8B;AAE/D,OAAO,MAAMC,UAAU,GACrBC,IAAmC,IAEnCA,IAAI,EAAEC,YAAY,CAACC,MAAM,CAACC,MAAM,CAAEC,CAAC,IAAkBA,CAAC,KAAK,IAAI,CAAC","ignoreList":[]}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
-
const
|
|
3
|
-
query
|
|
4
|
-
$division: Division
|
|
2
|
+
const priceCandles = gql`
|
|
3
|
+
query PriceCandles(
|
|
4
|
+
$division: Division!
|
|
5
|
+
$dataSource: InstrumentDataSource!
|
|
5
6
|
$instrument: String!
|
|
6
7
|
$granularity: Granularity!
|
|
7
8
|
$timeSpan: TimeSpan!
|
|
8
9
|
) {
|
|
9
|
-
|
|
10
|
+
priceCandles(
|
|
10
11
|
division: $division
|
|
12
|
+
dataSource: $dataSource
|
|
11
13
|
instrument: $instrument
|
|
12
14
|
granularity: $granularity
|
|
13
15
|
timeSpan: $timeSpan
|
|
14
16
|
) {
|
|
15
|
-
time
|
|
16
|
-
unixTime
|
|
17
17
|
candle {
|
|
18
|
+
point
|
|
18
19
|
high
|
|
19
20
|
low
|
|
20
21
|
open
|
|
@@ -24,5 +25,5 @@ const getPriceCandles = gql`
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
`;
|
|
27
|
-
export {
|
|
28
|
-
//# sourceMappingURL=
|
|
28
|
+
export { priceCandles };
|
|
29
|
+
//# sourceMappingURL=priceCandles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceCandles.js","names":["gql","priceCandles"],"sources":["../../../src/gql/priceCandles.ts"],"sourcesContent":["import { gql } from '@apollo/client';\n\nconst priceCandles = gql`\n query PriceCandles(\n $division: Division!\n $dataSource: InstrumentDataSource!\n $instrument: String!\n $granularity: Granularity!\n $timeSpan: TimeSpan!\n ) {\n priceCandles(\n division: $division\n dataSource: $dataSource\n instrument: $instrument\n granularity: $granularity\n timeSpan: $timeSpan\n ) {\n candle {\n point\n high\n low\n open\n close\n }\n timeSpan\n }\n }\n`;\n\nexport { priceCandles };\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,gBAAgB;AAEpC,MAAMC,YAAY,GAAGD,GAAG;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,SAASC,YAAY","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as types from './graphql';
|
|
2
2
|
const documents = {
|
|
3
|
-
'\n query
|
|
3
|
+
'\n query PriceCandles(\n $division: Division!\n $dataSource: InstrumentDataSource!\n $instrument: String!\n $granularity: Granularity!\n $timeSpan: TimeSpan!\n ) {\n priceCandles(\n division: $division\n dataSource: $dataSource\n instrument: $instrument\n granularity: $granularity\n timeSpan: $timeSpan\n ) {\n candle {\n point\n high\n low\n open\n close\n }\n timeSpan\n }\n }\n': types.PriceCandlesDocument,
|
|
4
4
|
'\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n': types.ValidateInstrumentsDocument
|
|
5
5
|
};
|
|
6
6
|
export function graphql(source) {
|