-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.ts
81 lines (68 loc) · 2.29 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*!
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/
import {
SGItem,
SGAreaItem,
SGLineItem,
SGSymbolItem,
SGArcItem,
SGRectItem,
SGGroupItem,
} from '@chart-parts/interfaces'
import {
arc as d3Arc,
symbol as d3Symbol,
area as d3Area,
line as d3Lines,
} from 'd3-shape'
import { Rectangle } from './Rectangle'
import { symbols } from './symbols'
const x = (item: SGItem) => item.x || 0
const x2 = (item: SGItem) => item.x2 || 0
const y = (item: SGItem) => item.y || 0
const y2 = (item: SGItem) => item.y2 || 0
const w = (item: SGItem) => item.width || 0
const h = (item: SGItem) => item.height || 0
const sa = (item: SGArcItem) => item.startAngle || 0
const ea = (item: SGArcItem) => item.endAngle || 0
const pa = (item: SGArcItem) => item.padAngle || 0
const ir = (item: SGArcItem) => item.innerRadius || 0
const or = (item: SGArcItem) => item.outerRadius || 0
const cr = (item: SGArcItem | SGRectItem | SGGroupItem) =>
item.cornerRadius || 0
const def = (item: SGAreaItem | SGLineItem) =>
item.defined == null ? true : item.defined
/**
* Extracts the symbol "size" from a scenegraph item - this is expressed as an area
* @param item The scenegraph item to inspect
*/
const symbolSize = (item: SGSymbolItem) => (item.size == null ? 64 : item.size)
/**
* Extracts the symbol "width" from a scenegraph item.
* @param item The scenegraph item to inspect
*/
const symbolWidth = (item: SGSymbolItem) =>
item.width == null ? 8 : item.width
const rendererByArea = (item: SGSymbolItem) =>
symbols(item.shape || 'circle').byArea
const rendererByWidth = (item: SGSymbolItem) =>
symbols(item.shape || 'circle').byWidth
export const rectShape = new Rectangle(x, y, w, h, cr)
export const arcShape = d3Arc<SGArcItem>()
.startAngle(sa)
.endAngle(ea)
.padAngle(pa)
.innerRadius(ir)
.outerRadius(or)
.cornerRadius(cr)
export const areahShape = d3Area<SGAreaItem>().x1(x).x0(x2).y(y).defined(def)
export const areavShape = d3Area<SGAreaItem>().y1(y).y0(y2).x(x).defined(def)
export const lineShape = d3Lines<SGLineItem>().x(x).y(y).defined(def)
export const symbolWithArea = d3Symbol<SGSymbolItem>()
.type(rendererByArea)
.size(symbolSize)
export const symbolWithWidth = d3Symbol<SGSymbolItem>()
.type(rendererByWidth)
.size(symbolWidth)