• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

naver / billboard.js / 11884196428

18 Nov 2024 01:38AM UTC coverage: 94.256%. Remained the same
11884196428

push

github

web-flow
test(point): update test for point.sensitivity (#3916)

Co-authored-by: netil <netil@AD02298065.local>

6270 of 6909 branches covered (90.75%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

7810 of 8029 relevant lines covered (97.27%)

26301.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.08
/src/ChartInternal/shape/point.common.ts
1
/**
2
 * Copyright (c) 2017 ~ present NAVER Corp.
3
 * billboard.js project is licensed under the MIT license
4
 */
5
import {namespaces as d3Namespaces, select as d3Select} from "d3-selection";
6
import {document} from "../../module/browser";
7
import {isFunction, isObjectType, notEmpty, toArray} from "../../module/util";
8

9
/**
10
 * Check if point draw methods are valid
11
 * @param {string} point point type
12
 * @returns {boolean}
13
 * @private
14
 */
15
function hasValidPointDrawMethods(point: string): boolean {
16
        return isObjectType(point) &&
984!
17
                isFunction(point.create) && isFunction(point.update);
18
}
19

20
/**
21
 * Insert point info defs element
22
 * @param {string} point Point element
23
 * @param {string} id Point id
24
 * @private
25
 */
26
function insertPointInfoDefs(point: string, id: string): void {
27
        const $$ = this;
114✔
28
        const copyAttr = (from, target) => {
114✔
29
                const attribs = from.attributes;
114✔
30

31
                for (let i = 0, name; (name = attribs[i]); i++) {
114✔
32
                        name = name.name;
147✔
33
                        target.setAttribute(name, from.getAttribute(name));
147✔
34
                }
35
        };
36

37
        const doc = new DOMParser().parseFromString(point, "image/svg+xml");
114✔
38
        const node = doc.documentElement;
114✔
39
        const clone = document.createElementNS(d3Namespaces.svg, node.nodeName.toLowerCase());
114✔
40

41
        clone.id = id;
114✔
42
        clone.style.fill = "inherit";
114✔
43
        clone.style.stroke = "inherit";
114✔
44

45
        copyAttr(node, clone);
114✔
46

47
        if (node.childNodes?.length) {
114✔
48
                const parent = d3Select(clone);
33✔
49

50
                if ("innerHTML" in clone) {
33!
51
                        parent.html(node.innerHTML);
33✔
52
                } else {
53
                        toArray(node.childNodes).forEach(v => {
×
54
                                copyAttr(v, parent.append(v.tagName).node());
×
55
                        });
56
                }
57
        }
58

59
        $$.$el.defs.node().appendChild(clone);
114✔
60
}
61

62
export default {
63
        /**
64
         * Check if point type option is valid
65
         * @param {string} type point type
66
         * @returns {boolean}
67
         * @private
68
         */
69
        hasValidPointType(type?: string): boolean {
70
                return /^(circle|rect(angle)?|polygon|ellipse|use)$/i.test(type || this.config.point_type);
83,277!
71
        },
72

73
        /**
74
         * Check if pattern point is set to be used on legend
75
         * @returns {boolean}
76
         * @private
77
         */
78
        hasLegendDefsPoint(): boolean {
79
                const {config} = this;
7,212✔
80

81
                return config.legend_show && config.point_pattern?.length && config.legend_usePoint;
7,212✔
82
        },
83

84
        getDefsPointId(id: string): string {
85
                const {state: {datetimeId}} = this;
987✔
86

87
                return `${datetimeId}-point${id}`;
987✔
88
        },
89

90
        /**
91
         * Get generate point function
92
         * @returns {Function}
93
         * @private
94
         */
95
        generatePoint(): Function {
96
                const $$ = this;
3,540✔
97
                const {$el, config} = $$;
3,540✔
98
                const ids: string[] = [];
3,540✔
99
                const pattern = notEmpty(config.point_pattern) ? config.point_pattern : [config.point_type];
3,540✔
100

101
                return function(method, context, ...args) {
3,540✔
102
                        return function(d) {
8,943✔
103
                                const id: string = $$.getTargetSelectorSuffix(d.id || d.data?.id || d);
82,572!
104
                                const element = d3Select(this);
82,572✔
105

106
                                ids.indexOf(id) < 0 && ids.push(id);
82,572✔
107

108
                                let point = pattern[ids.indexOf(id) % pattern.length];
82,572✔
109

110
                                if ($$.hasValidPointType(point)) {
82,572✔
111
                                        point = $$[point];
81,588✔
112
                                } else if (!hasValidPointDrawMethods(point || config.point_type)) {
984!
113
                                        const pointId = $$.getDefsPointId(id);
984✔
114
                                        const defsPoint = $el.defs.select(`#${pointId}`);
984✔
115

116
                                        if (defsPoint.size() < 1) {
984✔
117
                                                insertPointInfoDefs.bind($$)(point, pointId);
114✔
118
                                        }
119

120
                                        if (method === "create") {
984✔
121
                                                return $$.custom?.create.bind(context)(element, pointId, ...args);
474✔
122
                                        } else if (method === "update") {
510!
123
                                                return $$.custom?.update.bind(context)(element, ...args);
510✔
124
                                        }
125
                                }
126

127
                                return point[method]?.bind(context)(element, ...args);
81,588✔
128
                        };
129
                };
130
        }
131
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc