Skip to content

updating definition of otherConfig in fdc3.chart to use an array of context objects #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

* Updated definition of the `ChatInitSettings` context type to use the new `Message` type. ([#779](https://github.com/finos/FDC3/pull/779))
* Updated the `StartChat` intent to return a reference to the room. ([#794](https://github.com/finos/FDC3/pull/794))
* Updated definition of the `Instrument` context type to include optional market identifiers ([#819](https://github.com/finos/FDC3/pull/819))
* Corrected API functions and object types to always use `string` instead of `String` ([#924](https://github.com/finos/FDC3/pull/924))
* Updated the `StartChat` intent to return a reference to the room. ([#794](https://github.com/finos/FDC3/pull/794))
* Updated definition of the `otherConfig` element of the `Chart` context type from an Object to an array of Contexts as this allows the `type` of each additional item of config to be examined before it is used ([#985](https://github.com/finos/FDC3/pull/985))

### Deprecated

Expand Down
36 changes: 20 additions & 16 deletions docs/context/ref/Chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In addition to handling requests to plot charts, a charting application may use

## Schema

https://fdc3.finos.org/schemas/next/chart.schema.json
[https://fdc3.finos.org/schemas/next/chart.schema.json](https://fdc3.finos.org/schemas/next/chart.schema.json)

## Details

Expand All @@ -31,9 +31,9 @@ https://fdc3.finos.org/schemas/next/chart.schema.json
| `instruments` | Instrument[] | Yes | <pre>[<br/>&emsp;&emsp;{<br/>&emsp;&emsp;&emsp;&emsp;"type": "fdc3.instrument",<br/>&emsp;&emsp;&emsp;&emsp;"id": {<br/>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;"ticker": "AAPL"<br/>&emsp;&emsp;&emsp;&emsp;}<br/>&emsp;&emsp;},<br/>&emsp;&emsp;{<br/>&emsp;&emsp;&emsp;&emsp;"type": "fdc3.instrument",<br/>&emsp;&emsp;&emsp;&emsp;"id": {<br/>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;"ticker": "MSFT"<br/>&emsp;&emsp;&emsp;&emsp;}<br/>&emsp;&emsp;}<br/>]</pre> |
| `range` | TimeRange | No | <pre>{<br/>&emsp;&emsp;"type": "fdc3.timerange",<br/>&emsp;&emsp;"startTime": "2022-03-30T15:44:44+00:00",<br/>&emsp;&emsp;"endTime": "2022-04-30T23:59:59+00:00"<br/>}</pre> |
| `style` | string | No | one of: `'line'`, `'bar'`, `'stacked-bar'`, `'mountain'`, `'candle'`, `'pie'`, `'scatter'`, `'histogram'`, `'heatmap'`, `'custom'` |
| `otherConfig`* | object | No | `{ /* unstandardized additional config */}` |
| `otherConfig`* | array | No | `[ {/* additional config context objects */} ]` |

\* It is common for charts to support other configuration, such as indicators, annotations etc., which do not have standarized formats, but may be included in the `otherConfig` element.
\* It is common for charts to support other configuration, such as indicators, annotations etc., which do not have standardized formats, but may be included in the `otherConfig` array as context objects.

## Example

Expand All @@ -60,20 +60,24 @@ const chart = {
endTime: "2020-10-31T08:00:00.000Z"
},
style: "line",
otherConfig: {
indicators: [
{
name: "ma",
parameters: {
period: 14,
type: "ema"
}
},
{
name: "volume"
otherConfig: [
{
type: "somevendor.someproduct.indicator",
name: "stddev",
parameters: {
period: 10,
matype: "exponential"
}
]
}
},
{
type: "someothervendor.someotherproduct.formula",
formula: "standard-deviation",
fields: {
lookback: 10,
type: "ema"
}
}
]
};

fdc3.raiseIntent("ViewChart", chart);
Expand Down
19 changes: 17 additions & 2 deletions src/context/ContextTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

export interface Chart {
instruments: InstrumentElement[];
otherConfig?: { [key: string]: any };
otherConfig?: OtherConfigElement[];
range?: TimeRangeObject;
style?: Style;
type: string;
Expand Down Expand Up @@ -62,6 +62,13 @@ export interface PurpleMarket {
[property: string]: any;
}

export interface OtherConfigElement {
id?: { [key: string]: any };
name?: string;
type: string;
[property: string]: any;
}

export interface TimeRangeObject {
endTime?: Date;
startTime?: Date;
Expand Down Expand Up @@ -623,7 +630,7 @@ const typeMap: any = {
Chart: o(
[
{ json: 'instruments', js: 'instruments', typ: a(r('InstrumentElement')) },
{ json: 'otherConfig', js: 'otherConfig', typ: u(undefined, m('any')) },
{ json: 'otherConfig', js: 'otherConfig', typ: u(undefined, a(r('OtherConfigElement'))) },
{ json: 'range', js: 'range', typ: u(undefined, r('TimeRangeObject')) },
{ json: 'style', js: 'style', typ: u(undefined, r('Style')) },
{ json: 'type', js: 'type', typ: '' },
Expand Down Expand Up @@ -664,6 +671,14 @@ const typeMap: any = {
],
'any'
),
OtherConfigElement: o(
[
{ json: 'id', js: 'id', typ: u(undefined, m('any')) },
{ json: 'name', js: 'name', typ: u(undefined, '') },
{ json: 'type', js: 'type', typ: '' },
],
'any'
),
TimeRangeObject: o(
[
{ json: 'endTime', js: 'endTime', typ: u(undefined, Date) },
Expand Down
5 changes: 4 additions & 1 deletion src/context/schemas/chart.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"enum": [ "line", "bar", "stacked-bar", "mountain", "candle", "pie", "scatter", "histogram", "heatmap", "custom"]
},
"otherConfig": {
"type": "object"
"type": "array",
"items": {
"$ref": "context.schema.json#"
}
}
},
"required": ["instruments"]
Expand Down