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

Method constructor

src/components/Tooltip.js:26–66  ·  view source on GitHub ↗

* * @param {String} parent * @param {String} title * @param {Array} items * @param {Object} position * @example * { * parent: {}, // a d3 selection component * title: 'tooltip title', * items:[{ * color: 'red', * text: 'tim: 13' * }], *

({
    parent, title, items, position, unxkcdify, backgroundColor, strokeColor,
  })

Source from the content-addressed store, hash-verified

24 * }
25 */
26 constructor({
27 parent, title, items, position, unxkcdify, backgroundColor, strokeColor,
28 }) {
29 this.title = title;
30 this.items = items;
31 this.position = position;
32 this.filter = !unxkcdify ? 'url(#xkcdify)' : null;
33 this.backgroundColor = backgroundColor;
34 this.strokeColor = strokeColor;
35
36 this.svg = parent.append('svg')
37 .attr('x', this._getUpLeftX())
38 .attr('y', this._getUpLeftY())
39 .style('visibility', 'hidden');
40
41 this.tipBackground = this.svg.append('rect')
42 .style('fill', this.backgroundColor)
43 .attr('fill-opacity', 0.9)
44 .attr('stroke', strokeColor) // FIXME: find a good way to calculate boder color form this.strokeColor
45 .attr('stroke-width', 2)
46 .attr('rx', 5)
47 .attr('ry', 5)
48 .attr('filter', this.filter)
49 .attr('width', this._getBackgroundWidth())
50 .attr('height', this._getBackgroundHeight())
51 .attr('x', 5)
52 .attr('y', 5);
53
54 this.tipTitle = this.svg.append('text')
55 .style('font-size', 15)
56 .style('font-weight', 'bold')
57 .style('fill', this.strokeColor)
58 .attr('x', 15)
59 .attr('y', 25)
60 .text(title);
61
62 this.tipItems = items.map((item, i) => {
63 const g = this._generateTipItem(item, i);
64 return g;
65 });
66 }
67
68 show() {
69 this.svg.style('visibility', 'visible');

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected