-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Chart and DataGrid examples to use FDC3 standard
- Loading branch information
Showing
10 changed files
with
328 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,66 @@ | ||
import Chart from 'highcharts/es-modules/Core/Chart/Chart.js'; | ||
import ColumnSeries from 'highcharts/es-modules/Series/Column/ColumnSeries.js'; | ||
import { createMessageRouter } from "@morgan-stanley/composeui-messaging-client"; | ||
import * as Highcharts from 'highcharts'; | ||
|
||
let chart; | ||
let client; | ||
let currentChannel; | ||
|
||
window.addEventListener('load', function () { | ||
chart = new Chart({ | ||
chart: { | ||
renderTo: 'container', | ||
defaultSeriesType: 'column', | ||
events: { | ||
load: requestData | ||
} | ||
}, | ||
title: { | ||
text: 'Monthly Sales Data' | ||
}, | ||
xAxis: { | ||
categories: [ | ||
'Jan', | ||
'Feb', | ||
'March', | ||
'Apr', | ||
'May', | ||
'Jun', | ||
'Jul', | ||
'Aug', | ||
'Sep', | ||
'Oct', | ||
'Nov', | ||
'Dec' | ||
], | ||
}, | ||
yAxis: { | ||
minPadding: 0.2, | ||
maxPadding: 0.2, | ||
window.addEventListener('load', function() { | ||
chart = Highcharts.chart('container', { | ||
chart: { | ||
type: 'column', | ||
events: { | ||
load: requestData | ||
} | ||
}, | ||
title: { | ||
text: 'Value', | ||
margin: 80 | ||
} | ||
}, | ||
series: [{ | ||
name: 'Buy' | ||
}, { | ||
name: 'Sell' | ||
} | ||
] | ||
text: 'Monthly Sales Data' | ||
}, | ||
yAxis: { | ||
minPadding: 0.2, | ||
maxPadding: 0.2, | ||
title: { | ||
text: 'Value', | ||
margin: 80, | ||
} | ||
}, | ||
xAxis: { | ||
categories: ['Jan','Feb','March','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], | ||
}, | ||
series: [{ | ||
name: 'Buy', | ||
data: [] | ||
}, { | ||
name: 'Sell', | ||
data: [] | ||
}] | ||
}); | ||
|
||
window.document.getElementById("close-button").onclick = | ||
async ev => { | ||
if (!client) return; | ||
const tmpClient = client; | ||
client = undefined; | ||
tmpClient.close(); | ||
}; | ||
|
||
}); | ||
|
||
async function requestData() { | ||
|
||
(async () => { | ||
client = createMessageRouter(); | ||
|
||
window.client = client; | ||
|
||
await client.connect(); | ||
|
||
client.subscribe('proto_select_monthlySales', (message) => { | ||
|
||
const payload = JSON.parse(message.payload); | ||
const symbol = payload.symbol; | ||
const buyData = payload.buy; | ||
const sellData = payload.sell; | ||
|
||
chart.setTitle({ text: "Monthly sales for " + symbol }); | ||
chart.series[0].setData([]); | ||
chart.series[1].setData([]); | ||
currentChannel = await window.fdc3.getCurrentChannel(); | ||
|
||
if(!currentChannel) { | ||
await window.fdc3.joinUserChannel("default"); | ||
} | ||
|
||
buyData.forEach(function (p) { | ||
chart.series[0].addPoint(p, false); | ||
}); | ||
await window.fdc3.addContextListener('fdc3.instrument', (context, metadata) => { | ||
if(context.id) { | ||
chart.setTitle({ text: "Monthly sales for " + context.id.ticker }); | ||
chart.series[0].setData([]); | ||
chart.series[1].setData([]); | ||
|
||
sellData.forEach(function (p) { | ||
chart.series[1].addPoint(p, false); | ||
}); | ||
context.id.buyData.forEach(function (p) { | ||
chart.series[0].addPoint(p, false); | ||
}); | ||
|
||
context.id.sellData.forEach(function (p) { | ||
chart.series[1].addPoint(p, false); | ||
}); | ||
|
||
chart.redraw(); | ||
chart.redraw(); | ||
} | ||
}); | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 29 additions & 32 deletions
61
examples/js-datagrid/src/app/main-view/services/mock-data.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
/* Morgan Stanley makes this available to you under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { MESSAGE_ROUTER } from 'src/app/app.module'; | ||
import { DesktopAgent } from '@finos/fdc3'; | ||
import { MockDataService } from './mock-data.service'; | ||
import { MessageRouter } from '@morgan-stanley/composeui-messaging-client'; | ||
|
||
const dummyDesktopAgent = jasmine.createSpyObj<DesktopAgent>( | ||
'DesktopAgent', | ||
[ | ||
'joinChannel', | ||
'getSystemChannels', | ||
'getAppMetadata', | ||
'getInfo', | ||
'leaveCurrentChannel', | ||
'getCurrentChannel', | ||
'createPrivateChannel', | ||
'getOrCreateChannel', | ||
'joinUserChannel', | ||
'getUserChannels', | ||
'addContextListener', | ||
'addIntentListener', | ||
'raiseIntentForContext', | ||
'raiseIntent', | ||
'broadcast', | ||
'findInstances', | ||
'findIntentsByContext', | ||
'findIntent', | ||
'open', | ||
] | ||
) | ||
|
||
describe('MockDataService', () => { | ||
let service: MockDataService; | ||
|
||
beforeEach(() => { | ||
|
||
const messageRouterMock = jasmine.createSpyObj<MessageRouter>( | ||
"MessageRouter", | ||
[ | ||
"connect", | ||
"subscribe", | ||
"publish", | ||
"invoke", | ||
"registerService", | ||
"unregisterService", | ||
"registerEndpoint", | ||
"unregisterEndpoint" | ||
] | ||
); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
MockDataService, | ||
{ | ||
provide: MESSAGE_ROUTER, | ||
useValue: messageRouterMock | ||
} | ||
] | ||
}); | ||
|
||
service = TestBed.inject(MockDataService); | ||
window.fdc3 = dummyDesktopAgent; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
const mockDataService = new MockDataService(); | ||
expect(mockDataService).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.