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

Method render

src/XY.js:83–248  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81 }
82
83 render() {
84 if (this.title) addLabels.title(this.svgEl, this.title, this.options.strokeColor);
85 if (this.xLabel) addLabels.xLabel(this.svgEl, this.xLabel, this.options.strokeColor);
86 if (this.yLabel) addLabels.yLabel(this.svgEl, this.yLabel, this.options.strokeColor);
87
88 const tooltip = new Tooltip({
89 parent: this.svgEl,
90 title: '',
91 items: [{ color: 'red', text: 'weweyang' }, { color: 'blue', text: 'timqian' }],
92 position: { x: 60, y: 60, type: config.positionType.dowfnRight },
93 unxkcdify: this.options.unxkcdify,
94 strokeColor: this.options.strokeColor,
95 backgroundColor: this.options.backgroundColor,
96 });
97
98 if (this.options.timeFormat) {
99 this.data.datasets.forEach((dataset) => {
100 dataset.data.forEach((d) => {
101 // eslint-disable-next-line no-param-reassign
102 d.x = dayjs(d.x);
103 });
104 });
105 }
106
107 const allData = this.data.datasets
108 .reduce((pre, cur) => pre.concat(cur.data), []);
109
110 const allDataX = allData.map((d) => d.x);
111 const allDataY = allData.map((d) => d.y);
112
113 let xScale = scaleLinear()
114 .domain([Math.min(...allDataX), Math.max(...allDataX)])
115 .range([0, this.width]);
116
117 if (this.options.timeFormat) {
118 xScale = scaleTime()
119 .domain([Math.min(...allDataX), Math.max(...allDataX)])
120 .range([0, this.width]);
121 }
122
123 const yScale = scaleLinear()
124 .domain([Math.min(...allDataY), Math.max(...allDataY)])
125 .range([this.height, 0]);
126
127 const graphPart = this.chart.append('g')
128 .attr('pointer-events', 'all');
129
130 // axis
131 addAxis.xAxis(graphPart, {
132 xScale,
133 tickCount: this.options.xTickCount === undefined ? 3 : this.options.xTickCount,
134 moveDown: this.height,
135 fontFamily: this.fontFamily,
136 unxkcdify: this.options.unxkcdify,
137 stroke: this.options.strokeColor,
138 });
139 addAxis.yAxis(graphPart, {
140 yScale,

Callers 1

constructorMethod · 0.95

Calls 4

updateMethod · 0.95
showMethod · 0.95
hideMethod · 0.95
addLegendFunction · 0.85

Tested by

no test coverage detected