MCPcopy
hub / github.com/timqian/chart.xkcd / update

Method update

src/components/Tooltip.js:77–108  ·  view source on GitHub ↗
({ title, items, position })

Source from the content-addressed store, hash-verified

75
76 // update tooltip position / content
77 update({ title, items, position }) {
78 if (title && title !== this.title) {
79 this.title = title;
80 this.tipTitle.text(title);
81 }
82
83 if (items && JSON.stringify(items) !== JSON.stringify(this.items)) {
84 this.items = items;
85
86 this.tipItems.forEach((g) => g.svg.remove());
87
88 this.tipItems = this.items.map((item, i) => {
89 const g = this._generateTipItem(item, i);
90 return g;
91 });
92
93 const maxWidth = Math.max(
94 ...this.tipItems.map((item) => item.width),
95 this.tipTitle.node().getBBox().width,
96 );
97
98 this.tipBackground
99 .attr('width', maxWidth + 15)
100 .attr('height', this._getBackgroundHeight());
101 }
102
103 if (position) {
104 this.position = position;
105 this.svg.attr('x', this._getUpLeftX());
106 this.svg.attr('y', this._getUpLeftY());
107 }
108 }
109
110 _generateTipItem(item, i) {
111 const svg = this.svg.append('svg');

Callers 7

renderMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95

Calls 4

_generateTipItemMethod · 0.95
_getBackgroundHeightMethod · 0.95
_getUpLeftXMethod · 0.95
_getUpLeftYMethod · 0.95

Tested by

no test coverage detected