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

Method constructor

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

renderMethod · 0.95
addFontFunction · 0.85
addFilterFunction · 0.85

Tested by

no test coverage detected