|
12 | 12 | * limitations under the License. |
13 | 13 | */ |
14 | 14 |
|
15 | | -import { OverlayTemplate, Coordinate } from 'klinecharts' |
16 | | - |
17 | | -const abcd: OverlayTemplate = { |
18 | | - name: 'abcd', |
19 | | - totalStep: 5, |
20 | | - needDefaultPointFigure: true, |
21 | | - needDefaultXAxisFigure: true, |
22 | | - needDefaultYAxisFigure: true, |
23 | | - createPointFigures: ({ coordinates }) => { |
24 | | - let acLineCoordinates: Coordinate[] = [] |
25 | | - let bdLineCoordinates: Coordinate[] = [] |
26 | | - |
27 | | - const tags = ['A', 'B', 'C', 'D'] |
28 | | - const texts = coordinates.map((coordinate, i) => ({ |
29 | | - ...coordinate, |
30 | | - baseline: 'bottom', |
31 | | - text: `(${tags[i]})` |
32 | | - })) |
33 | | - if (coordinates.length > 2) { |
34 | | - acLineCoordinates = [coordinates[0], coordinates[2]] |
35 | | - if (coordinates.length > 3) { |
36 | | - bdLineCoordinates = [coordinates[1], coordinates[3]] |
37 | | - } |
| 15 | +import { Coordinate, LineStyle, DeepPartial, TextStyle } from 'klinecharts' |
| 16 | +import { OverlayProperties, ProOverlayTemplate } from '../types' |
| 17 | +import loadash from "lodash" |
| 18 | + |
| 19 | +const abcd = (): ProOverlayTemplate => { |
| 20 | + let properties: DeepPartial<OverlayProperties> = {} |
| 21 | + |
| 22 | + const line1Style = (): DeepPartial<LineStyle> => { |
| 23 | + return { |
| 24 | + style: properties.lineStyle, |
| 25 | + size: properties.lineWidth, |
| 26 | + color: properties.lineColor ?? properties.borderColor, |
| 27 | + dashedValue: properties.lineDashedValue |
38 | 28 | } |
39 | | - return [ |
40 | | - { |
41 | | - type: 'line', |
42 | | - attrs: { coordinates } |
43 | | - }, |
44 | | - { |
45 | | - type: 'line', |
46 | | - attrs: [{ coordinates: acLineCoordinates }, { coordinates: bdLineCoordinates }], |
47 | | - styles: { style: 'dashed' } |
48 | | - }, |
49 | | - { |
50 | | - type: 'text', |
51 | | - ignoreEvent: true, |
52 | | - attrs: texts |
53 | | - } |
54 | | - ] |
55 | 29 | } |
| 30 | + const line2Style = (): DeepPartial<LineStyle> => { |
| 31 | + return { |
| 32 | + ...line1Style(), |
| 33 | + style: 'dashed' |
| 34 | + } |
| 35 | + } |
| 36 | + const textStyle = (): DeepPartial<TextStyle> => { |
| 37 | + return { |
| 38 | + color: properties.textColor, |
| 39 | + family: properties.textFont, |
| 40 | + size: properties.textFontSize, |
| 41 | + weight: properties.textFontWeight, |
| 42 | + backgroundColor: properties.textBackgroundColor, |
| 43 | + paddingLeft: properties.textPaddingLeft, |
| 44 | + paddingRight: properties.textPaddingRight, |
| 45 | + paddingTop: properties.textPaddingTop, |
| 46 | + paddingBottom: properties.textPaddingBottom |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + return { |
| 51 | + name: 'abcd', |
| 52 | + totalStep: 5, |
| 53 | + needDefaultPointFigure: true, |
| 54 | + needDefaultXAxisFigure: true, |
| 55 | + needDefaultYAxisFigure: true, |
| 56 | + createPointFigures: ({ coordinates }) => { |
| 57 | + let acLineCoordinates: Coordinate[] = [] |
| 58 | + let bdLineCoordinates: Coordinate[] = [] |
| 59 | + |
| 60 | + const tags = ['A', 'B', 'C', 'D'] |
| 61 | + const texts = coordinates.map((coordinate, i) => ({ |
| 62 | + ...coordinate, |
| 63 | + baseline: 'bottom', |
| 64 | + text: `(${tags[i]})` |
| 65 | + })) |
| 66 | + if (coordinates.length > 2) { |
| 67 | + acLineCoordinates = [coordinates[0], coordinates[2]] |
| 68 | + if (coordinates.length > 3) { |
| 69 | + bdLineCoordinates = [coordinates[1], coordinates[3]] |
| 70 | + } |
| 71 | + } |
| 72 | + return [ |
| 73 | + { |
| 74 | + type: 'line', |
| 75 | + attrs: { coordinates }, |
| 76 | + styles: line1Style() |
| 77 | + }, |
| 78 | + { |
| 79 | + type: 'line', |
| 80 | + attrs: [{ coordinates: acLineCoordinates }, { coordinates: bdLineCoordinates }], |
| 81 | + styles: line2Style() |
| 82 | + }, |
| 83 | + { |
| 84 | + type: 'text', |
| 85 | + ignoreEvent: true, |
| 86 | + attrs: texts, |
| 87 | + styles: textStyle() |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + setProperties: (_properties: DeepPartial<OverlayProperties>) => { |
| 92 | + properties = loadash.merge({}, properties, _properties) as OverlayProperties |
| 93 | + }, |
| 94 | + getProperties: (): DeepPartial<OverlayProperties> => { |
| 95 | + return properties |
| 96 | + } |
| 97 | +} |
56 | 98 | } |
57 | 99 |
|
58 | 100 | export default abcd |
0 commit comments