-
Notifications
You must be signed in to change notification settings - Fork 37
/
factory.ts
39 lines (35 loc) · 1.01 KB
/
factory.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
/*!
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/
import { SGItem, MarkType } from '@chart-parts/interfaces'
import { MarkBuilder } from './MarkBuilder'
import * as Elements from './elements'
import { createItemType } from './registry'
/**
*
* @param markType The type of mark item to create
* @param item The mark items to add
*/
export function createMark(markType: MarkType, items: SGItem[]) {
items.forEach((item, index) => {
if (item.itemtype !== markType) {
throw new Error(
`Mark type must match the type of it's child items. Mark ${markType}, child ${item.itemtype}@${index}`,
)
}
})
const result = new Elements.Mark()
result.marktype = markType
result.items = items as Elements.Item[]
return result
}
export function createItem(
itemType: MarkType,
props: { [key: string]: any } = {},
): SGItem {
return createItemType(itemType, props)
}
export function buildMark(markType: MarkType) {
return new MarkBuilder(markType)
}