(protected configuration: TimeseriesGraphConfiguration, private datasource: GraphDataSource)
| 62 | private start: number; |
| 63 | |
| 64 | constructor(protected configuration: TimeseriesGraphConfiguration, private datasource: GraphDataSource) { |
| 65 | this.start = new Date().getTime(); |
| 66 | |
| 67 | const now = this.start; |
| 68 | |
| 69 | this.span = configuration.timespan * 1000; |
| 70 | |
| 71 | this.x = d3.scaleTime().range([0, this.width]).domain([now - this.span, now]); |
| 72 | this.y = d3.scaleLinear().range([this.height, 0]).domain([configuration.minimum, configuration.maximum]); |
| 73 | |
| 74 | this.line = d3.line<GraphPoint>().x((d) => this.x(d.timestamp)).y((d) => this.y(d.value)); |
| 75 | |
| 76 | const wrapper = d3.select('.graph-container').append('div').attr('class', 'graph-wrapper'); |
| 77 | wrapper.append('h3').text(configuration.label); |
| 78 | |
| 79 | // Setup Main Graph |
| 80 | const twidth = this.width + this.margins.left + this.margins.right; |
| 81 | const theight = this.height + this.margins.top + this.margins.bottom + this.sheight + 50; |
| 82 | this.svg = wrapper.append('svg') |
| 83 | .attr('viewBox', `0 0 ${twidth} ${theight}`) |
| 84 | .attr('preserveAspectRatio', 'xMidYMid meet'); |
| 85 | this.g = this.svg.append('g') |
| 86 | .attr('transform', `translate(${this.margins.left}, ${this.margins.top})`); |
| 87 | this.ag = this.g.append('g'); |
| 88 | |
| 89 | this.xAxis = this.g.append('g').attr('class', 'axis x-axis') |
| 90 | .attr('transform', `translate(0,${this.height})`) |
| 91 | .call(d3.axisBottom(this.x)); |
| 92 | this.yAxis = this.g.append('g').attr('class', 'axis y-axis') |
| 93 | .call(d3.axisLeft(this.y)); |
| 94 | |
| 95 | // Setup Legend |
| 96 | const legend = this.svg.append('g') |
| 97 | .attr('class', 'legend') |
| 98 | .attr('transform', `translate(${this.margins.left + 10}, ${this.margins.top + this.height + 30})`) |
| 99 | .attr('stroke-width', 1) |
| 100 | .attr('stroke', 'black') |
| 101 | .attr('fill', 'none'); |
| 102 | |
| 103 | let offset = 10; |
| 104 | |
| 105 | // Setup Summary Graph |
| 106 | this.sx = d3.scaleTime().range([0, this.width]).domain([now, now + 1000]); |
| 107 | this.sy = d3.scaleLinear().range([this.sheight, 0]).domain([configuration.minimum, configuration.maximum]); |
| 108 | this.sg = this.svg.append('g') |
| 109 | .attr('transform', `translate(${this.margins.left}, ${this.margins.top + this.height + this.margins.bottom + 25})`); |
| 110 | this.sxAxis = this.sg.append('g').attr('class', 'axis x-axis') |
| 111 | .attr('transform', `translate(0,${this.sheight})`) |
| 112 | .call(d3.axisBottom(this.sx)); |
| 113 | this.syAxis = this.sg.append('g').attr('class', 'axis x-axis') |
| 114 | .call(d3.axisLeft(this.sy).ticks(4)); |
| 115 | this.sline = d3.line<GraphPoint>().x((d) => this.sx(d.timestamp)).y((d) => this.sy(d.value)); |
| 116 | this.hrect = this.sg.append('rect') |
| 117 | .attr('class', 'highlight-area') |
| 118 | .attr('x', 0) |
| 119 | .attr('y', 0) |
| 120 | .attr('height', this.sheight) |
| 121 | .attr('width', this.width); |
nothing calls this directly
no test coverage detected