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

Method constructor

src/Line.js:22–76  ·  view source on GitHub ↗
(svg, {
    title, xLabel, yLabel, data: { labels, datasets }, options,
  })

Source from the content-addressed store, hash-verified

20
21class Line {
22 constructor(svg, {
23 title, xLabel, yLabel, data: { labels, datasets }, options,
24 }) {
25 this.options = {
26 unxkcdify: false,
27 yTickCount: 3,
28 legendPosition: config.positionType.upLeft,
29 dataColors: colors,
30 fontFamily: 'xkcd',
31 strokeColor: 'black',
32 backgroundColor: 'white',
33 showLegend: true,
34 ...options,
35 };
36 if (title) {
37 this.title = title;
38 margin.top = 60;
39 }
40 if (xLabel) {
41 this.xLabel = xLabel;
42 margin.bottom = 50;
43 }
44 if (yLabel) {
45 this.yLabel = yLabel;
46 margin.left = 70;
47 }
48 this.data = {
49 labels,
50 datasets,
51 };
52 this.filter = 'url(#xkcdify)';
53 this.fontFamily = this.options.fontFamily || 'xkcd';
54 if (this.options.unxkcdify) {
55 this.filter = null;
56 this.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
57 }
58
59 this.svgEl = select(svg)
60 .style('stroke-width', '3')
61 .style('font-family', this.fontFamily)
62 .style('background', this.options.backgroundColor)
63 .attr('width', svg.parentElement.clientWidth)
64 .attr('height', Math.min((svg.parentElement.clientWidth * 2) / 3, window.innerHeight));
65 this.svgEl.selectAll('*').remove();
66
67 this.chart = this.svgEl.append('g')
68 .attr('transform',
69 `translate(${margin.left},${margin.top})`);
70 this.width = this.svgEl.attr('width') - margin.left - margin.right;
71 this.height = this.svgEl.attr('height') - margin.top - margin.bottom;
72
73 addFont(this.svgEl);
74 addFilter(this.svgEl);
75 this.render();
76 }
77
78 render() {
79 if (this.title) addLabels.title(this.svgEl, this.title, this.options.strokeColor);

Callers

nothing calls this directly

Calls 3

renderMethod · 0.95
addFontFunction · 0.85
addFilterFunction · 0.85

Tested by

no test coverage detected