-
Notifications
You must be signed in to change notification settings - Fork 37
/
Orchestrator.ts
60 lines (56 loc) · 1.63 KB
/
Orchestrator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*!
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/
/* eslint-disable no-console */
import { createScenegraph } from '@chart-parts/builder'
import {
ChartOptions,
SceneNode,
DataFrame,
VDomRenderer,
ScenegraphConverter,
} from '@chart-parts/interfaces'
import { parseScene } from '@chart-parts/scenegraph'
import { VirtualSvgConverter } from '@chart-parts/vsvg'
export class Orchestrator<T> {
public constructor(
private renderer: VDomRenderer<T>,
private prerenderer: ScenegraphConverter<any> = new VirtualSvgConverter(),
) {}
/**
* Renders a raw scenegraph object into view. This is mostly useful for internal debugging
* @param rawScene The raw scenegraph object to render
* @param options Charting options
*/
public renderScenegraph(rawScene: any, options: ChartOptions = {}): T {
try {
const scenegraph = parseScene(rawScene)
const intermediate = this.prerenderer.render(scenegraph, options)
return this.renderer.render(intermediate, {})
} catch (err) {
console.log('error rendering scenegraph', err)
throw err
}
}
/**
* Binds data to a scene and renders it into view.
* @param scene The scene to rendre
* @param options The chart options
* @param tables The charting data
*/
public renderScene(
scene: SceneNode,
options: ChartOptions = {},
tables: DataFrame,
) {
try {
const sg = createScenegraph(scene, tables, options)
const vdom = this.prerenderer.render(sg.root, options)
return this.renderer.render(vdom, sg.channelHandlers)
} catch (err) {
console.log('error rendering scene', err)
throw err
}
}
}