@oanda/labs-order-book-widget 1.0.61 → 1.0.63
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 +476 -0
- package/dist/main/OrderBookWidget/OrderBookWidget.js +6 -3
- package/dist/main/OrderBookWidget/OrderBookWidget.js.map +1 -1
- package/dist/main/OrderBookWidget/Widget.js +12 -14
- package/dist/main/OrderBookWidget/Widget.js.map +1 -1
- package/dist/main/OrderBookWidget/components/Chart/Chart.js +49 -13
- package/dist/main/OrderBookWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/OrderBookWidget/components/Chart/constants.js +7 -3
- package/dist/main/OrderBookWidget/components/Chart/constants.js.map +1 -1
- package/dist/main/OrderBookWidget/components/Chart/formatters.js +14 -0
- package/dist/main/OrderBookWidget/components/Chart/formatters.js.map +1 -0
- package/dist/main/OrderBookWidget/components/Chart/getOption.js +274 -0
- package/dist/main/OrderBookWidget/components/Chart/getOption.js.map +1 -0
- package/dist/main/OrderBookWidget/components/Chart/types.js +6 -0
- package/dist/main/OrderBookWidget/components/Chart/types.js.map +1 -0
- package/dist/main/OrderBookWidget/config.js +15 -0
- package/dist/main/OrderBookWidget/config.js.map +1 -0
- package/dist/main/OrderBookWidget/render.js +31 -10
- package/dist/main/OrderBookWidget/render.js.map +1 -1
- package/dist/main/OrderBookWidget/types.js.map +1 -1
- package/dist/main/gql/getOrderPositionBooks.js +3 -17
- package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js +3 -2
- package/dist/main/gql/types/fragment-masking.js.map +1 -1
- package/dist/main/gql/types/gql.js +2 -1
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/module/OrderBookWidget/OrderBookWidget.js +7 -4
- package/dist/module/OrderBookWidget/OrderBookWidget.js.map +1 -1
- package/dist/module/OrderBookWidget/Widget.js +13 -15
- package/dist/module/OrderBookWidget/Widget.js.map +1 -1
- package/dist/module/OrderBookWidget/components/Chart/Chart.js +47 -13
- package/dist/module/OrderBookWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/OrderBookWidget/components/Chart/constants.js +6 -2
- package/dist/module/OrderBookWidget/components/Chart/constants.js.map +1 -1
- package/dist/module/OrderBookWidget/components/Chart/formatters.js +8 -0
- package/dist/module/OrderBookWidget/components/Chart/formatters.js.map +1 -0
- package/dist/module/OrderBookWidget/components/Chart/getOption.js +266 -0
- package/dist/module/OrderBookWidget/components/Chart/getOption.js.map +1 -0
- package/dist/module/OrderBookWidget/components/Chart/types.js +2 -0
- package/dist/module/OrderBookWidget/components/Chart/types.js.map +1 -0
- package/dist/module/OrderBookWidget/config.js +10 -0
- package/dist/module/OrderBookWidget/config.js.map +1 -0
- package/dist/module/OrderBookWidget/render.js +31 -10
- package/dist/module/OrderBookWidget/render.js.map +1 -1
- package/dist/module/OrderBookWidget/types.js.map +1 -1
- package/dist/module/gql/getOrderPositionBooks.js +3 -17
- package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js +3 -2
- package/dist/module/gql/types/fragment-masking.js.map +1 -1
- package/dist/module/gql/types/gql.js +2 -1
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/types/OrderBookWidget/OrderBookWidget.d.ts +1 -1
- package/dist/types/OrderBookWidget/components/Chart/Chart.d.ts +2 -6
- package/dist/types/OrderBookWidget/components/Chart/constants.d.ts +6 -2
- package/dist/types/OrderBookWidget/components/Chart/formatters.d.ts +3 -0
- package/dist/types/OrderBookWidget/components/Chart/getOption.d.ts +174 -0
- package/dist/types/OrderBookWidget/components/Chart/types.d.ts +18 -0
- package/dist/types/OrderBookWidget/config.d.ts +6 -0
- package/dist/types/OrderBookWidget/render.d.ts +1 -6
- package/dist/types/OrderBookWidget/types.d.ts +2 -0
- package/package.json +3 -3
- package/src/OrderBookWidget/OrderBookWidget.tsx +9 -6
- package/src/OrderBookWidget/Widget.tsx +12 -21
- package/src/OrderBookWidget/components/Chart/Chart.tsx +56 -18
- package/src/OrderBookWidget/components/Chart/constants.ts +7 -2
- package/src/OrderBookWidget/components/Chart/formatters.ts +11 -0
- package/src/OrderBookWidget/components/Chart/getOption.ts +296 -0
- package/src/OrderBookWidget/components/Chart/types.ts +29 -0
- package/src/OrderBookWidget/config.ts +11 -0
- package/src/OrderBookWidget/render.tsx +36 -18
- package/src/OrderBookWidget/types.ts +2 -0
- package/dist/main/OrderBookWidget/components/Chart/getOptions.js +0 -322
- package/dist/main/OrderBookWidget/components/Chart/getOptions.js.map +0 -1
- package/dist/module/OrderBookWidget/components/Chart/getOptions.js +0 -315
- package/dist/module/OrderBookWidget/components/Chart/getOptions.js.map +0 -1
- package/dist/types/OrderBookWidget/components/Chart/getOptions.d.ts +0 -6
- package/src/OrderBookWidget/components/Chart/getOptions.ts +0 -361
|
@@ -2,14 +2,35 @@ import React from 'react';
|
|
|
2
2
|
import { render } from 'react-dom';
|
|
3
3
|
import { OrderBookWidget } from './OrderBookWidget';
|
|
4
4
|
const {
|
|
5
|
-
graphqlUrl,
|
|
6
|
-
instrument,
|
|
7
|
-
renderElementId,
|
|
8
|
-
locale
|
|
9
|
-
} = window.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
graphqlUrl: configGraphQl,
|
|
6
|
+
instrument: configInstrument,
|
|
7
|
+
renderElementId: configRenderElementId,
|
|
8
|
+
locale: configLocale
|
|
9
|
+
} = window.volatilityChartWidgetConfig || {};
|
|
10
|
+
const {
|
|
11
|
+
graphqlUrl
|
|
12
|
+
} = window.widgetsConfig || {};
|
|
13
|
+
const orderBookElements = document.querySelectorAll('div[data-order-book-params]');
|
|
14
|
+
if (orderBookElements.length > 0) {
|
|
15
|
+
orderBookElements.forEach(element => {
|
|
16
|
+
const params = element.getAttribute('data-order-book-params');
|
|
17
|
+
const mode = element.getAttribute('data-mode');
|
|
18
|
+
const {
|
|
19
|
+
instrument,
|
|
20
|
+
locale
|
|
21
|
+
} = JSON.parse(params);
|
|
22
|
+
render(React.createElement(OrderBookWidget, {
|
|
23
|
+
locale: locale,
|
|
24
|
+
graphqlUrl: graphqlUrl,
|
|
25
|
+
instrument: instrument,
|
|
26
|
+
theme: mode
|
|
27
|
+
}), element);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
render(React.createElement(OrderBookWidget, {
|
|
31
|
+
locale: configLocale,
|
|
32
|
+
graphqlUrl: configGraphQl,
|
|
33
|
+
instrument: configInstrument
|
|
34
|
+
}), document.getElementById(configRenderElementId));
|
|
35
|
+
}
|
|
15
36
|
//# sourceMappingURL=render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["React","render","OrderBookWidget","graphqlUrl","instrument","renderElementId","locale","window","
|
|
1
|
+
{"version":3,"file":"render.js","names":["React","render","OrderBookWidget","graphqlUrl","configGraphQl","instrument","configInstrument","renderElementId","configRenderElementId","locale","configLocale","window","volatilityChartWidgetConfig","widgetsConfig","orderBookElements","document","querySelectorAll","length","forEach","element","params","getAttribute","mode","JSON","parse","createElement","theme","getElementById"],"sources":["../../../src/OrderBookWidget/render.tsx"],"sourcesContent":["import React from 'react';\nimport { render } from 'react-dom';\nimport { Theme } from '@oanda/labs-widget-common';\nimport { OrderBookWidget } from './OrderBookWidget';\n\nconst {\n graphqlUrl: configGraphQl,\n instrument: configInstrument,\n renderElementId: configRenderElementId,\n locale: configLocale,\n} = window.volatilityChartWidgetConfig || {};\n\nconst {\n graphqlUrl,\n} = window.widgetsConfig || {};\n\nconst orderBookElements = document.querySelectorAll('div[data-order-book-params]');\n\nif (orderBookElements.length > 0) {\n orderBookElements.forEach((element) => {\n const params = element.getAttribute('data-order-book-params');\n const mode = element.getAttribute('data-mode');\n const { instrument, locale } = JSON.parse(params as string);\n\n render(\n <OrderBookWidget\n locale={locale}\n graphqlUrl={graphqlUrl}\n instrument={instrument}\n theme={mode as Theme}\n />,\n element,\n );\n });\n} else {\n render(\n <OrderBookWidget\n locale={configLocale}\n graphqlUrl={configGraphQl}\n instrument={configInstrument}\n />,\n document.getElementById(configRenderElementId),\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,MAAM;EACJC,UAAU,EAAEC,aAAa;EACzBC,UAAU,EAAEC,gBAAgB;EAC5BC,eAAe,EAAEC,qBAAqB;EACtCC,MAAM,EAAEC;AACV,CAAC,GAAGC,MAAM,CAACC,2BAA2B,IAAI,CAAC,CAAC;AAE5C,MAAM;EACJT;AACF,CAAC,GAAGQ,MAAM,CAACE,aAAa,IAAI,CAAC,CAAC;AAE9B,MAAMC,iBAAiB,GAAGC,QAAQ,CAACC,gBAAgB,CAAC,6BAA6B,CAAC;AAElF,IAAIF,iBAAiB,CAACG,MAAM,GAAG,CAAC,EAAE;EAChCH,iBAAiB,CAACI,OAAO,CAAEC,OAAO,IAAK;IACrC,MAAMC,MAAM,GAAGD,OAAO,CAACE,YAAY,CAAC,wBAAwB,CAAC;IAC7D,MAAMC,IAAI,GAAGH,OAAO,CAACE,YAAY,CAAC,WAAW,CAAC;IAC9C,MAAM;MAAEhB,UAAU;MAAEI;IAAO,CAAC,GAAGc,IAAI,CAACC,KAAK,CAACJ,MAAgB,CAAC;IAE3DnB,MAAM,CACJD,KAAA,CAAAyB,aAAA,CAACvB,eAAe;MACdO,MAAM,EAAEA,MAAO;MACfN,UAAU,EAAEA,UAAW;MACvBE,UAAU,EAAEA,UAAW;MACvBqB,KAAK,EAAEJ;IAAc,CACtB,CAAC,EACFH,OACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,MAAM;EACLlB,MAAM,CACJD,KAAA,CAAAyB,aAAA,CAACvB,eAAe;IACdO,MAAM,EAAEC,YAAa;IACrBP,UAAU,EAAEC,aAAc;IAC1BC,UAAU,EAAEC;EAAiB,CAC9B,CAAC,EACFS,QAAQ,CAACY,cAAc,CAACnB,qBAAqB,CAC/C,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/OrderBookWidget/types.ts"],"sourcesContent":["import { Locale } from '@oanda/mono-i18n';\n\nexport interface OrderBookWidgetConfig {\n graphqlUrl: string;\n instrument: string;\n locale: Locale;\n}\n\nexport interface OrderBookWrapperConfig extends OrderBookWidgetConfig {\n renderElementId: string;\n}\n\nexport interface WidgetProps {\n instrument: string;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/OrderBookWidget/types.ts"],"sourcesContent":["import { Theme } from '@oanda/labs-widget-common';\nimport { Locale } from '@oanda/mono-i18n';\n\nexport interface OrderBookWidgetConfig {\n graphqlUrl: string;\n instrument: string;\n locale: Locale;\n theme?: Theme;\n}\n\nexport interface OrderBookWrapperConfig extends OrderBookWidgetConfig {\n renderElementId: string;\n}\n\nexport interface WidgetProps {\n instrument: string;\n}\n"],"mappings":""}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
1
3
|
import { gql } from '@apollo/client';
|
|
2
|
-
const getOrderPositionBooks = gql
|
|
3
|
-
query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {
|
|
4
|
-
orderPositionBooks(
|
|
5
|
-
instrument: $instrument
|
|
6
|
-
bookType: $bookType
|
|
7
|
-
recentHours: $recentHours
|
|
8
|
-
) {
|
|
9
|
-
bucketWidth
|
|
10
|
-
price
|
|
11
|
-
buckets {
|
|
12
|
-
price
|
|
13
|
-
longCountPercent
|
|
14
|
-
shortCountPercent
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`;
|
|
4
|
+
const getOrderPositionBooks = gql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n"])));
|
|
19
5
|
export { getOrderPositionBooks };
|
|
20
6
|
//# sourceMappingURL=getOrderPositionBooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOrderPositionBooks.js","names":["gql","getOrderPositionBooks"],"sources":["../../../src/gql/getOrderPositionBooks.ts"],"sourcesContent":["import { gql } from '@apollo/client';\n\nconst getOrderPositionBooks = gql`\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n`;\n\nexport { getOrderPositionBooks };\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,gBAAgB;AAEpC,MAAMC,qBAAqB,GAAGD,
|
|
1
|
+
{"version":3,"file":"getOrderPositionBooks.js","names":["gql","getOrderPositionBooks","_templateObject","_taggedTemplateLiteral"],"sources":["../../../src/gql/getOrderPositionBooks.ts"],"sourcesContent":["import { gql } from '@apollo/client';\n\nconst getOrderPositionBooks = gql`\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n`;\n\nexport { getOrderPositionBooks };\n"],"mappings":";;AAAA,SAASA,GAAG,QAAQ,gBAAgB;AAEpC,MAAMC,qBAAqB,GAAGD,GAAG,CAAAE,eAAA,KAAAA,eAAA,GAAAC,sBAAA,iXAgBhC;AAED,SAASF,qBAAqB"}
|
|
@@ -5,10 +5,11 @@ export function makeFragmentData(data, _fragment) {
|
|
|
5
5
|
return data;
|
|
6
6
|
}
|
|
7
7
|
export function isFragmentReady(queryNode, fragmentNode, data) {
|
|
8
|
-
|
|
8
|
+
var _meta__, _fragDef$name;
|
|
9
|
+
const deferredFields = (_meta__ = queryNode.__meta__) === null || _meta__ === void 0 ? void 0 : _meta__.deferredFields;
|
|
9
10
|
if (!deferredFields) return true;
|
|
10
11
|
const fragDef = fragmentNode.definitions[0];
|
|
11
|
-
const fragName = fragDef
|
|
12
|
+
const fragName = fragDef === null || fragDef === void 0 || (_fragDef$name = fragDef.name) === null || _fragDef$name === void 0 ? void 0 : _fragDef$name.value;
|
|
12
13
|
const fields = fragName && deferredFields[fragName] || [];
|
|
13
14
|
return fields.length > 0 && fields.every(field => data && field in data);
|
|
14
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragment-masking.js","names":["useFragment","_documentNode","fragmentType","makeFragmentData","data","_fragment","isFragmentReady","queryNode","fragmentNode","deferredFields","__meta__","fragDef","definitions","fragName","name","value","fields","length","every","field"],"sources":["../../../../src/gql/types/fragment-masking.ts"],"sourcesContent":["import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { FragmentDefinitionNode } from 'graphql';\nimport { Incremental } from './graphql';\n\n\nexport type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<\n infer TType,\n any\n>\n ? [TType] extends [{ ' $fragmentName'?: infer TKey }]\n ? TKey extends string\n ? { ' $fragmentRefs'?: { [key in TKey]: TType } }\n : never\n : never\n : never;\n\n// return non-nullable if `fragmentType` is non-nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>\n): TType;\n// return nullable if `fragmentType` is nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined\n): TType | null | undefined;\n// return array of non-nullable if `fragmentType` is array of non-nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>\n): ReadonlyArray<TType>;\n// return array of nullable if `fragmentType` is array of nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): ReadonlyArray<TType> | null | undefined;\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): TType | ReadonlyArray<TType> | null | undefined {\n return fragmentType as any;\n}\n\n\nexport function makeFragmentData<\n F extends DocumentTypeDecoration<any, any>,\n FT extends ResultOf<F>\n>(data: FT, _fragment: F): FragmentType<F> {\n return data as FragmentType<F>;\n}\nexport function isFragmentReady<TQuery, TFrag>(\n queryNode: DocumentTypeDecoration<TQuery, any>,\n fragmentNode: TypedDocumentNode<TFrag>,\n data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined\n): data is FragmentType<typeof fragmentNode> {\n const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__\n ?.deferredFields;\n\n if (!deferredFields) return true;\n\n const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;\n const fragName = fragDef?.name?.value;\n\n const fields = (fragName && deferredFields[fragName]) || [];\n return fields.length > 0 && fields.every(field => data && field in data);\n}\n"],"mappings":"AAoCA,OAAO,SAASA,WAAWA,CACzBC,aAAiD,EACjDC,YAAmJ,EAClG;EACjD,OAAOA,YAAY;AACrB;AAGA,OAAO,SAASC,gBAAgBA,CAG9BC,IAAQ,EAAEC,SAAY,EAAmB;EACzC,OAAOD,IAAI;AACb;AACA,OAAO,SAASE,eAAeA,CAC7BC,SAA8C,EAC9CC,YAAsC,EACtCJ,IAAiF,EACtC;EAC3C,
|
|
1
|
+
{"version":3,"file":"fragment-masking.js","names":["useFragment","_documentNode","fragmentType","makeFragmentData","data","_fragment","isFragmentReady","queryNode","fragmentNode","_meta__","_fragDef$name","deferredFields","__meta__","fragDef","definitions","fragName","name","value","fields","length","every","field"],"sources":["../../../../src/gql/types/fragment-masking.ts"],"sourcesContent":["import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { FragmentDefinitionNode } from 'graphql';\nimport { Incremental } from './graphql';\n\n\nexport type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<\n infer TType,\n any\n>\n ? [TType] extends [{ ' $fragmentName'?: infer TKey }]\n ? TKey extends string\n ? { ' $fragmentRefs'?: { [key in TKey]: TType } }\n : never\n : never\n : never;\n\n// return non-nullable if `fragmentType` is non-nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>\n): TType;\n// return nullable if `fragmentType` is nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined\n): TType | null | undefined;\n// return array of non-nullable if `fragmentType` is array of non-nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>\n): ReadonlyArray<TType>;\n// return array of nullable if `fragmentType` is array of nullable\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): ReadonlyArray<TType> | null | undefined;\nexport function useFragment<TType>(\n _documentNode: DocumentTypeDecoration<TType, any>,\n fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined\n): TType | ReadonlyArray<TType> | null | undefined {\n return fragmentType as any;\n}\n\n\nexport function makeFragmentData<\n F extends DocumentTypeDecoration<any, any>,\n FT extends ResultOf<F>\n>(data: FT, _fragment: F): FragmentType<F> {\n return data as FragmentType<F>;\n}\nexport function isFragmentReady<TQuery, TFrag>(\n queryNode: DocumentTypeDecoration<TQuery, any>,\n fragmentNode: TypedDocumentNode<TFrag>,\n data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined\n): data is FragmentType<typeof fragmentNode> {\n const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__\n ?.deferredFields;\n\n if (!deferredFields) return true;\n\n const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;\n const fragName = fragDef?.name?.value;\n\n const fields = (fragName && deferredFields[fragName]) || [];\n return fields.length > 0 && fields.every(field => data && field in data);\n}\n"],"mappings":"AAoCA,OAAO,SAASA,WAAWA,CACzBC,aAAiD,EACjDC,YAAmJ,EAClG;EACjD,OAAOA,YAAY;AACrB;AAGA,OAAO,SAASC,gBAAgBA,CAG9BC,IAAQ,EAAEC,SAAY,EAAmB;EACzC,OAAOD,IAAI;AACb;AACA,OAAO,SAASE,eAAeA,CAC7BC,SAA8C,EAC9CC,YAAsC,EACtCJ,IAAiF,EACtC;EAAA,IAAAK,OAAA,EAAAC,aAAA;EAC3C,MAAMC,cAAc,IAAAF,OAAA,GAAIF,SAAS,CAAwEK,QAAQ,cAAAH,OAAA,uBAA1FA,OAAA,CACnBE,cAAc;EAElB,IAAI,CAACA,cAAc,EAAE,OAAO,IAAI;EAEhC,MAAME,OAAO,GAAGL,YAAY,CAACM,WAAW,CAAC,CAAC,CAAuC;EACjF,MAAMC,QAAQ,GAAGF,OAAO,aAAPA,OAAO,gBAAAH,aAAA,GAAPG,OAAO,CAAEG,IAAI,cAAAN,aAAA,uBAAbA,aAAA,CAAeO,KAAK;EAErC,MAAMC,MAAM,GAAIH,QAAQ,IAAIJ,cAAc,CAACI,QAAQ,CAAC,IAAK,EAAE;EAC3D,OAAOG,MAAM,CAACC,MAAM,GAAG,CAAC,IAAID,MAAM,CAACE,KAAK,CAACC,KAAK,IAAIjB,IAAI,IAAIiB,KAAK,IAAIjB,IAAI,CAAC;AAC1E"}
|
|
@@ -3,6 +3,7 @@ const documents = {
|
|
|
3
3
|
"\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n": types.GetOrderPositionBooksDocument
|
|
4
4
|
};
|
|
5
5
|
export function graphql(source) {
|
|
6
|
-
|
|
6
|
+
var _source;
|
|
7
|
+
return (_source = documents[source]) !== null && _source !== void 0 ? _source : {};
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=gql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gql.js","names":["types","documents","GetOrderPositionBooksDocument","graphql","source"],"sources":["../../../../src/gql/types/gql.ts"],"sourcesContent":["/* eslint-disable */\nimport * as types from './graphql';\nimport { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n\n/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n * 1. It is not tree-shakeable, so it will include all operations in the project.\n * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n * 3. It does not support dead code elimination, so it will add unused operations.\n *\n * Therefore it is highly recommended to use the babel or swc plugin for production.\n */\nconst documents = {\n \"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\": types.GetOrderPositionBooksDocument,\n};\n\n/**\n * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n *\n *\n * @example\n * ```ts\n * const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);\n * ```\n *\n * The query argument is unknown!\n * Please regenerate the types.\n */\nexport function graphql(source: string): unknown;\n\n/**\n * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n */\nexport function graphql(source: \"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\"): (typeof documents)[\"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\"];\n\nexport function graphql(source: string) {\n return (documents as any)[source] ?? {};\n}\n\nexport type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,WAAW;AAalC,MAAMC,SAAS,GAAG;EACd,2WAA2W,EAAED,KAAK,CAACE;AACvX,CAAC;AAqBD,OAAO,SAASC,OAAOA,CAACC,MAAc,EAAE;EACtC,
|
|
1
|
+
{"version":3,"file":"gql.js","names":["types","documents","GetOrderPositionBooksDocument","graphql","source","_source"],"sources":["../../../../src/gql/types/gql.ts"],"sourcesContent":["/* eslint-disable */\nimport * as types from './graphql';\nimport { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n\n/**\n * Map of all GraphQL operations in the project.\n *\n * This map has several performance disadvantages:\n * 1. It is not tree-shakeable, so it will include all operations in the project.\n * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n * 3. It does not support dead code elimination, so it will add unused operations.\n *\n * Therefore it is highly recommended to use the babel or swc plugin for production.\n */\nconst documents = {\n \"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\": types.GetOrderPositionBooksDocument,\n};\n\n/**\n * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n *\n *\n * @example\n * ```ts\n * const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);\n * ```\n *\n * The query argument is unknown!\n * Please regenerate the types.\n */\nexport function graphql(source: string): unknown;\n\n/**\n * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n */\nexport function graphql(source: \"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\"): (typeof documents)[\"\\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\\n orderPositionBooks(\\n instrument: $instrument\\n bookType: $bookType\\n recentHours: $recentHours\\n ) {\\n bucketWidth\\n price\\n buckets {\\n price\\n longCountPercent\\n shortCountPercent\\n }\\n }\\n }\\n\"];\n\nexport function graphql(source: string) {\n return (documents as any)[source] ?? {};\n}\n\nexport type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,WAAW;AAalC,MAAMC,SAAS,GAAG;EACd,2WAA2W,EAAED,KAAK,CAACE;AACvX,CAAC;AAqBD,OAAO,SAASC,OAAOA,CAACC,MAAc,EAAE;EAAA,IAAAC,OAAA;EACtC,QAAAA,OAAA,GAAQJ,SAAS,CAASG,MAAM,CAAC,cAAAC,OAAA,cAAAA,OAAA,GAAI,CAAC,CAAC;AACzC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { OrderBookWidgetConfig } from './types';
|
|
3
|
-
declare const OrderBookWidget: ({ graphqlUrl, instrument, locale, }: OrderBookWidgetConfig) => JSX.Element;
|
|
3
|
+
declare const OrderBookWidget: ({ graphqlUrl, instrument, locale, theme, }: OrderBookWidgetConfig) => JSX.Element;
|
|
4
4
|
export { OrderBookWidget };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
data: GetOrderPositionBooksQuery;
|
|
5
|
-
}
|
|
6
|
-
export declare const Chart: ({ data }: ChartProps) => JSX.Element;
|
|
7
|
-
export {};
|
|
2
|
+
import { ChartProps } from './types';
|
|
3
|
+
export declare const Chart: ({ data, isOrderBook }: ChartProps) => JSX.Element;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export declare const INITIAL_BARS =
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const INITIAL_BARS = 80;
|
|
2
|
+
export declare const X_LABEL_SIZE = 40;
|
|
3
|
+
export declare const Y_LABEL_SIZE_MOBILE = 35;
|
|
4
|
+
export declare const Y_LABEL_SIZE_DESKTOP = 120;
|
|
5
|
+
export declare const CHART_WIDTH = 9999;
|
|
6
|
+
export declare const CHART_HEIGHT = 450;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { GetOptionType, GetResponsiveOptionsProps } from './types';
|
|
2
|
+
export declare const getDesktopOption: ({ isDark, isOrderBook }: GetResponsiveOptionsProps) => {
|
|
3
|
+
grid: {
|
|
4
|
+
name: string;
|
|
5
|
+
top: string;
|
|
6
|
+
left: string;
|
|
7
|
+
right: string;
|
|
8
|
+
bottom: string;
|
|
9
|
+
}[];
|
|
10
|
+
graphic: ({
|
|
11
|
+
top: number | undefined;
|
|
12
|
+
bottom: number | undefined;
|
|
13
|
+
left: number | undefined;
|
|
14
|
+
right: number | undefined;
|
|
15
|
+
shape: {
|
|
16
|
+
x1: number;
|
|
17
|
+
y1: number;
|
|
18
|
+
x2: number;
|
|
19
|
+
y2: number;
|
|
20
|
+
};
|
|
21
|
+
type: string;
|
|
22
|
+
silent: boolean;
|
|
23
|
+
z: number;
|
|
24
|
+
style: {
|
|
25
|
+
stroke: string;
|
|
26
|
+
lineWidth: number;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
top: number;
|
|
30
|
+
shape: {
|
|
31
|
+
x1: number;
|
|
32
|
+
y1: number;
|
|
33
|
+
x2: number;
|
|
34
|
+
y2: number;
|
|
35
|
+
};
|
|
36
|
+
type: string;
|
|
37
|
+
silent: boolean;
|
|
38
|
+
z: number;
|
|
39
|
+
style: {
|
|
40
|
+
stroke: string;
|
|
41
|
+
lineWidth: number;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
right: number;
|
|
45
|
+
shape: {
|
|
46
|
+
x1: number;
|
|
47
|
+
y1: number;
|
|
48
|
+
x2: number;
|
|
49
|
+
y2: number;
|
|
50
|
+
};
|
|
51
|
+
type: string;
|
|
52
|
+
silent: boolean;
|
|
53
|
+
z: number;
|
|
54
|
+
style: {
|
|
55
|
+
stroke: string;
|
|
56
|
+
lineWidth: number;
|
|
57
|
+
};
|
|
58
|
+
} | {
|
|
59
|
+
bottom: number;
|
|
60
|
+
shape: {
|
|
61
|
+
x1: number;
|
|
62
|
+
y1: number;
|
|
63
|
+
x2: number;
|
|
64
|
+
y2: number;
|
|
65
|
+
};
|
|
66
|
+
type: string;
|
|
67
|
+
silent: boolean;
|
|
68
|
+
z: number;
|
|
69
|
+
style: {
|
|
70
|
+
stroke: string;
|
|
71
|
+
lineWidth: number;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
left: number;
|
|
75
|
+
shape: {
|
|
76
|
+
x1: number;
|
|
77
|
+
y1: number;
|
|
78
|
+
x2: number;
|
|
79
|
+
y2: number;
|
|
80
|
+
};
|
|
81
|
+
type: string;
|
|
82
|
+
silent: boolean;
|
|
83
|
+
z: number;
|
|
84
|
+
style: {
|
|
85
|
+
stroke: string;
|
|
86
|
+
lineWidth: number;
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
type: string;
|
|
90
|
+
left: string;
|
|
91
|
+
top: string;
|
|
92
|
+
silent: boolean;
|
|
93
|
+
children: ({
|
|
94
|
+
type: string;
|
|
95
|
+
z: number;
|
|
96
|
+
left: string;
|
|
97
|
+
top: string;
|
|
98
|
+
shape: {
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
};
|
|
102
|
+
style: {
|
|
103
|
+
fill: string;
|
|
104
|
+
shadowBlur: number;
|
|
105
|
+
shadowOffsetX: number;
|
|
106
|
+
shadowOffsetY: number;
|
|
107
|
+
shadowColor: string;
|
|
108
|
+
width?: undefined;
|
|
109
|
+
height?: undefined;
|
|
110
|
+
text?: undefined;
|
|
111
|
+
};
|
|
112
|
+
} | {
|
|
113
|
+
type: string;
|
|
114
|
+
z: number;
|
|
115
|
+
left: string;
|
|
116
|
+
top: string;
|
|
117
|
+
style: {
|
|
118
|
+
fill: string;
|
|
119
|
+
width: number;
|
|
120
|
+
height: number;
|
|
121
|
+
text: string;
|
|
122
|
+
shadowBlur?: undefined;
|
|
123
|
+
shadowOffsetX?: undefined;
|
|
124
|
+
shadowOffsetY?: undefined;
|
|
125
|
+
shadowColor?: undefined;
|
|
126
|
+
};
|
|
127
|
+
shape?: undefined;
|
|
128
|
+
})[];
|
|
129
|
+
right?: undefined;
|
|
130
|
+
} | {
|
|
131
|
+
type: string;
|
|
132
|
+
right: string;
|
|
133
|
+
top: string;
|
|
134
|
+
silent: boolean;
|
|
135
|
+
children: ({
|
|
136
|
+
type: string;
|
|
137
|
+
z: number;
|
|
138
|
+
right: string;
|
|
139
|
+
top: string;
|
|
140
|
+
shape: {
|
|
141
|
+
width: number;
|
|
142
|
+
height: number;
|
|
143
|
+
};
|
|
144
|
+
style: {
|
|
145
|
+
fill: string;
|
|
146
|
+
shadowBlur: number;
|
|
147
|
+
shadowOffsetX: number;
|
|
148
|
+
shadowOffsetY: number;
|
|
149
|
+
shadowColor: string;
|
|
150
|
+
width?: undefined;
|
|
151
|
+
height?: undefined;
|
|
152
|
+
text?: undefined;
|
|
153
|
+
};
|
|
154
|
+
} | {
|
|
155
|
+
type: string;
|
|
156
|
+
z: number;
|
|
157
|
+
right: string;
|
|
158
|
+
top: string;
|
|
159
|
+
style: {
|
|
160
|
+
fill: string;
|
|
161
|
+
width: number;
|
|
162
|
+
height: number;
|
|
163
|
+
text: string;
|
|
164
|
+
shadowBlur?: undefined;
|
|
165
|
+
shadowOffsetX?: undefined;
|
|
166
|
+
shadowOffsetY?: undefined;
|
|
167
|
+
shadowColor?: undefined;
|
|
168
|
+
};
|
|
169
|
+
shape?: undefined;
|
|
170
|
+
})[];
|
|
171
|
+
left?: undefined;
|
|
172
|
+
})[];
|
|
173
|
+
};
|
|
174
|
+
export declare const getOption: GetOptionType;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { GetOrderPositionBooksQuery } from '../../../gql/types/graphql';
|
|
3
|
+
export interface ChartProps {
|
|
4
|
+
data: GetOrderPositionBooksQuery;
|
|
5
|
+
isOrderBook: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface GetResponsiveOptionsProps {
|
|
8
|
+
isDark: boolean;
|
|
9
|
+
isOrderBook: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface GetOptionProps {
|
|
12
|
+
data: GetOrderPositionBooksQuery;
|
|
13
|
+
precision: number;
|
|
14
|
+
isDark: boolean;
|
|
15
|
+
isOrderBook: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type GetOptionType = (props: GetOptionProps) => EChartsOption;
|
|
18
|
+
export type TooltipFormatterType = (data: number[], precision: number, isOrderBook: boolean) => string;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Theme } from '@oanda/labs-widget-common';
|
|
1
2
|
import { Locale } from '@oanda/mono-i18n';
|
|
2
3
|
export interface OrderBookWidgetConfig {
|
|
3
4
|
graphqlUrl: string;
|
|
4
5
|
instrument: string;
|
|
5
6
|
locale: Locale;
|
|
7
|
+
theme?: Theme;
|
|
6
8
|
}
|
|
7
9
|
export interface OrderBookWrapperConfig extends OrderBookWidgetConfig {
|
|
8
10
|
renderElementId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oanda/labs-order-book-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "Labs Order Book Widget",
|
|
5
5
|
"main": "dist/main/index.js",
|
|
6
6
|
"module": "dist/module/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "UNLICENSED",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@apollo/client": "3.7.17",
|
|
16
|
-
"@oanda/labs-widget-common": "^1.0.
|
|
16
|
+
"@oanda/labs-widget-common": "^1.0.63",
|
|
17
17
|
"@oanda/mono-i18n": "9.0.0",
|
|
18
18
|
"classnames": "2.3.2",
|
|
19
19
|
"echarts": "5.4.3",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"@graphql-codegen/client-preset": "4.1.0",
|
|
26
26
|
"@graphql-codegen/typescript": "4.0.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f09946395428aaec61ae575a8c762be67e3f05d5"
|
|
29
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
|
3
3
|
import { LocaleProvider } from '@oanda/mono-i18n';
|
|
4
|
-
import { getLocale } from '@oanda/labs-widget-common';
|
|
4
|
+
import { ThemeProvider, getLocale } from '@oanda/labs-widget-common';
|
|
5
5
|
import { Widget } from './Widget';
|
|
6
6
|
import { OrderBookWidgetConfig } from './types';
|
|
7
7
|
import { translations } from '../translations';
|
|
@@ -10,6 +10,7 @@ const OrderBookWidget = ({
|
|
|
10
10
|
graphqlUrl,
|
|
11
11
|
instrument,
|
|
12
12
|
locale,
|
|
13
|
+
theme,
|
|
13
14
|
}: OrderBookWidgetConfig) => {
|
|
14
15
|
const client = new ApolloClient({
|
|
15
16
|
uri: graphqlUrl,
|
|
@@ -17,11 +18,13 @@ const OrderBookWidget = ({
|
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
return (
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
<ThemeProvider theme={theme}>
|
|
22
|
+
<LocaleProvider locale={getLocale(locale)} translations={translations}>
|
|
23
|
+
<ApolloProvider client={client}>
|
|
24
|
+
<Widget instrument={instrument} />
|
|
25
|
+
</ApolloProvider>
|
|
26
|
+
</LocaleProvider>
|
|
27
|
+
</ThemeProvider>
|
|
25
28
|
);
|
|
26
29
|
};
|
|
27
30
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { useQuery } from '@apollo/client';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
ChartError, Spinner, SpinnerSize, Tabs,
|
|
5
5
|
} from '@oanda/labs-widget-common';
|
|
6
6
|
import { useLocale } from '@oanda/mono-i18n';
|
|
7
7
|
import { WidgetProps } from './types';
|
|
8
8
|
import { getOrderPositionBooks } from '../gql/getOrderPositionBooks';
|
|
9
9
|
import { GetOrderPositionBooksQuery, GetOrderPositionBooksQueryVariables, BookType } from '../gql/types/graphql';
|
|
10
10
|
import { Chart } from './components/Chart/Chart';
|
|
11
|
+
import { navigationConfig } from './config';
|
|
11
12
|
|
|
12
13
|
const Widget = ({
|
|
13
14
|
instrument,
|
|
@@ -28,39 +29,29 @@ const Widget = ({
|
|
|
28
29
|
|
|
29
30
|
const isError = (!loading && !data) || !!error;
|
|
30
31
|
|
|
31
|
-
const isTypeOrder = bookType === BookType.Order;
|
|
32
|
-
|
|
33
32
|
return (
|
|
34
33
|
<div data-testid="order-book-widget" className="lw-p-4 lw-text-sm lw-tracking-normal lw-text-black">
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</Button>
|
|
42
|
-
<Button
|
|
43
|
-
variant={isTypeOrder ? ButtonVariant.secondary : ButtonVariant.primary}
|
|
44
|
-
onClick={() => setBookType(BookType.Position)}
|
|
45
|
-
>
|
|
46
|
-
{lang('position_book')}
|
|
47
|
-
</Button>
|
|
48
|
-
</div>
|
|
34
|
+
<Tabs
|
|
35
|
+
activeTab={bookType}
|
|
36
|
+
handleClick={(e) => setBookType(e.currentTarget.value as BookType)}
|
|
37
|
+
labelCallback={lang}
|
|
38
|
+
items={navigationConfig}
|
|
39
|
+
/>
|
|
49
40
|
{/* @todo: chart height */}
|
|
50
|
-
<div className="lw-relative lw-h-[
|
|
41
|
+
<div className="lw-relative lw-h-[450px] lw-w-full">
|
|
51
42
|
{isError && (
|
|
52
|
-
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full lw-items-center lw-justify-center lw-
|
|
43
|
+
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary">
|
|
53
44
|
<ChartError />
|
|
54
45
|
</div>
|
|
55
46
|
)}
|
|
56
47
|
{loading && (
|
|
57
|
-
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full lw-items-center lw-justify-center lw-
|
|
48
|
+
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary">
|
|
58
49
|
<Spinner size={SpinnerSize.lg} />
|
|
59
50
|
</div>
|
|
60
51
|
)}
|
|
61
52
|
{data && (
|
|
62
53
|
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full">
|
|
63
|
-
<Chart data={data} />
|
|
54
|
+
<Chart data={data} isOrderBook={bookType === BookType.Order} />
|
|
64
55
|
</div>
|
|
65
56
|
)}
|
|
66
57
|
</div>
|
|
@@ -1,33 +1,71 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef, useEffect, useContext } from 'react';
|
|
2
2
|
import ReactEcharts from 'echarts-for-react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { registerTheme, EChartsType, Color } from 'echarts';
|
|
4
|
+
import {
|
|
5
|
+
Theme, ThemeContext, colorPalette, getChartTheme,
|
|
6
|
+
} from '@oanda/labs-widget-common';
|
|
7
|
+
import { useMediaQuery } from 'usehooks-ts';
|
|
8
|
+
import { getDesktopOption, getOption } from './getOption';
|
|
9
|
+
import { ChartProps } from './types';
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
11
|
+
registerTheme('dark_theme', getChartTheme(Theme.Dark));
|
|
12
|
+
registerTheme('light_theme', getChartTheme(Theme.Light));
|
|
9
13
|
|
|
10
|
-
export const Chart = ({ data }: ChartProps) => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
+
export const Chart = ({ data, isOrderBook }: ChartProps) => {
|
|
15
|
+
const isDark = useContext(ThemeContext) === Theme.Dark;
|
|
16
|
+
const echartRef = useRef(null);
|
|
17
|
+
const isDesktop = useMediaQuery('(min-width: 768px)');
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (echartRef.current) {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const echartInstance = echartRef.current.getEchartsInstance() as EChartsType;
|
|
23
|
+
|
|
24
|
+
echartInstance.on('highlight', () => {
|
|
25
|
+
if ((echartInstance.getOption().color as Color[])[0] === colorPalette.bottleGreenLight) {
|
|
26
|
+
echartInstance.setOption({
|
|
27
|
+
color: [
|
|
28
|
+
colorPalette.bottleGreenLight70,
|
|
29
|
+
isDark ? colorPalette.orange70 : colorPalette.raspberryDark70,
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
echartInstance.on('globalout', () => {
|
|
36
|
+
echartInstance.setOption({
|
|
37
|
+
color: [
|
|
38
|
+
colorPalette.bottleGreenLight,
|
|
39
|
+
isDark ? colorPalette.orange : colorPalette.raspberryDark,
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}, [echartRef, isDark]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (echartRef.current) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const echartInstance = echartRef.current.getEchartsInstance() as EChartsType;
|
|
50
|
+
|
|
51
|
+
echartInstance.setOption(getDesktopOption({ isDark, isOrderBook }));
|
|
52
|
+
}
|
|
53
|
+
}, [echartRef, isDesktop, isDark, isOrderBook]);
|
|
20
54
|
|
|
21
55
|
return (
|
|
22
56
|
<div className="lw-relative lw-w-full">
|
|
23
57
|
<div>
|
|
24
|
-
{
|
|
58
|
+
{data && (
|
|
25
59
|
<ReactEcharts
|
|
60
|
+
ref={echartRef}
|
|
61
|
+
theme={isDark ? 'dark_theme' : 'light_theme'}
|
|
26
62
|
style={{
|
|
27
|
-
height: '
|
|
63
|
+
height: '450px',
|
|
28
64
|
width: '100%',
|
|
29
65
|
}}
|
|
30
|
-
option={
|
|
66
|
+
option={getOption({
|
|
67
|
+
data, precision: 4, isDark, isOrderBook,
|
|
68
|
+
})}
|
|
31
69
|
/>
|
|
32
70
|
)}
|
|
33
71
|
</div>
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export const INITIAL_BARS =
|
|
2
|
-
|
|
1
|
+
export const INITIAL_BARS = 80;
|
|
2
|
+
|
|
3
|
+
export const X_LABEL_SIZE = 40;
|
|
4
|
+
export const Y_LABEL_SIZE_MOBILE = 35;
|
|
5
|
+
export const Y_LABEL_SIZE_DESKTOP = 120;
|
|
6
|
+
export const CHART_WIDTH = 9999;
|
|
7
|
+
export const CHART_HEIGHT = 450;
|