Skip to content

Commit 82fa27f

Browse files
author
DanielSteger
committed
Reformat
1 parent 0e875c8 commit 82fa27f

File tree

1 file changed

+55
-43
lines changed

1 file changed

+55
-43
lines changed

frontend/src/app/modules/time-series/services/line-chart.service.ts

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ export class LineChartService {
124124

125125
private bringMouseMarkerToTheFront(xScale: D3ScaleTime<number, number>, yScale: D3ScaleLinear<number, number>) {
126126
const markerGroup = d3Select('#marker-group').remove();
127-
d3Select('#time-series-chart-drawing-area').append(() => { return markerGroup.node(); });
127+
d3Select('#time-series-chart-drawing-area').append(() => {
128+
return markerGroup.node();
129+
});
128130
this._mouseEventCatcher.on('mousemove', (_, index, nodes: D3ContainerElement[]) => this.moveMarker(nodes[index], xScale, yScale, this._height));
129131
}
130132

@@ -260,7 +262,7 @@ export class LineChartService {
260262
// Add the X-Axis to the chart
261263
chart.append('g') // new group for the X-Axis (see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g)
262264
.attr('class', 'axis x-axis') // a css class to style it later
263-
.attr('transform', 'translate(0, ' + this._height + ')') // even if the D3 method called `axisBottom` we have to move it to the bottom by ourselfs
265+
.attr('transform', 'translate(0, ' + this._height + ')') // even if the D3 method called `axisBottom` we have to move it to the bottom by ourselves
264266
.call(xAxis);
265267
}
266268

@@ -337,7 +339,7 @@ export class LineChartService {
337339
// Include line breaks
338340
transition.on('end.linebreak', insertLinebreakToLabels);
339341

340-
// Show the ticks again as now all manipulation should have been happend
342+
// Show the ticks again as now all manipulation should have been happened
341343
transition.on('end.showTicks', function show() {
342344
d3Select(this).selectAll('g.tick text')
343345
.transition()
@@ -372,7 +374,7 @@ export class LineChartService {
372374
.y((point: TimeSeriesPoint) => {
373375
return yScale(point.value);
374376
}) // ... and for the Y-Coordinate
375-
// .curve(d3CurveMonotoneX); // smooth the line
377+
// .curve(d3CurveMonotoneX); // smooth the line
376378

377379
}
378380

@@ -383,7 +385,7 @@ export class LineChartService {
383385
xScale: D3ScaleTime<number, number>,
384386
yScale: D3ScaleLinear<number, number>,
385387
data: TimeSeries[]): void {
386-
//Remove after resize
388+
// Remove after resize
387389
chart.selectAll('.line').remove();
388390
// Create one group per line / data entry
389391
chart.selectAll('.line') // Get all lines already drawn
@@ -393,7 +395,9 @@ export class LineChartService {
393395
this.addDataPointsToXAxisCluster(enter);
394396
const lineSelection: any = this.drawLine(enter, xScale, yScale);
395397

396-
const lineGroup = lineSelection.select(function() { return (<SVGPathElement>this).parentNode; });
398+
const lineGroup = lineSelection.select(function () {
399+
return (<SVGPathElement>this).parentNode;
400+
});
397401
this.addDataPointMarkersToChart(lineGroup, xScale, yScale);
398402

399403
return lineSelection;
@@ -409,7 +413,7 @@ export class LineChartService {
409413
private addDataPointsToXAxisCluster(enter: D3Selection<D3BaseType, TimeSeries, D3BaseType, {}>) {
410414
enter.each((timeSeries: TimeSeries) => {
411415
timeSeries.values.forEach((timeSeriesPoint: TimeSeriesPoint) => {
412-
if(!this._xAxisCluster[timeSeriesPoint.date.getTime()]) this._xAxisCluster[timeSeriesPoint.date.getTime()] = [];
416+
if (!this._xAxisCluster[timeSeriesPoint.date.getTime()]) this._xAxisCluster[timeSeriesPoint.date.getTime()] = [];
413417
this._xAxisCluster[timeSeriesPoint.date.getTime()].push(timeSeriesPoint);
414418
});
415419
});
@@ -484,49 +488,55 @@ export class LineChartService {
484488

485489
const resultingSelection = selection
486490
.append('g') // Group each line so we can add dots to this group latter
487-
.attr('class', (timeSeries: TimeSeries) => 'line line-'+timeSeries.key)
491+
.attr('class', (timeSeries: TimeSeries) => 'line line-' + timeSeries.key)
488492
.style('opacity', '0')
489-
.append('path') // Draw one path for every item in the data set
490-
.attr('fill', 'none')
491-
.attr('stroke-width', 1.5)
492-
.attr('d', (dataItem: TimeSeries) => {
493-
return this.getLineGenerator(xScale, yScale)(dataItem.values);
494-
});
493+
.append('path') // Draw one path for every item in the data set
494+
.attr('fill', 'none')
495+
.attr('stroke-width', 1.5)
496+
.attr('d', (dataItem: TimeSeries) => {
497+
return this.getLineGenerator(xScale, yScale)(dataItem.values);
498+
});
495499

496500
d3SelectAll('.line')
497-
// colorize (in reverse order as d3 adds new line before the existing ones ...
498-
.attr('stroke', (_, index: number, nodes: []) => { return getColorScheme()[nodes.length - index - 1]; })
501+
// colorize (in reverse order as d3 adds new line before the existing ones ...
502+
.attr('stroke', (_, index: number, nodes: []) => {
503+
return getColorScheme()[nodes.length - index - 1];
504+
})
499505
// fade in
500506
.transition().duration(500).style('opacity', (timeSeries: TimeSeries) => {
501-
return (this.legendDataMap[timeSeries.key].show) ? '1' : '0.2';
502-
});
507+
return (this.legendDataMap[timeSeries.key].show) ? '1' : '0.2';
508+
});
503509

504510
return resultingSelection;
505511
}
506512

507-
private addDataPointMarkersToChart(lineGroups: D3Selection<any, TimeSeries, D3BaseType, {}>, xScale: D3ScaleTime<number, number>, yScale: D3ScaleLinear<number, number>) : void {
513+
private addDataPointMarkersToChart(lineGroups: D3Selection<any, TimeSeries, D3BaseType, {}>, xScale: D3ScaleTime<number, number>, yScale: D3ScaleLinear<number, number>): void {
508514
lineGroups.each((timeSeries: TimeSeries, index: number, nodes: D3BaseType[]) => {
509515
const lineGroup = d3Select(nodes[index]);
510516

511517
// TODO: Some dots are group into the wrong parent line group (and in turn do have the wrong color!) and I fucking don't know why!
512518
lineGroup
513519
.append('g')
514-
.selectAll('.dot-'+timeSeries.key)
520+
.selectAll('.dot-' + timeSeries.key)
515521
.data((timeSeries: TimeSeries) => timeSeries.values)
516522
.enter()
517-
.append('circle')
518-
.attr('class', (dot: TimeSeriesPoint) => 'dot dot-'+timeSeries.key+' dot-x-'+xScale(dot.date).toString().replace('.', '_'))
519-
.style('opacity', '0')
520-
.attr('r', this.DOT_RADIUS)
521-
.attr('cx', (dot: TimeSeriesPoint) => { return xScale(dot.date); })
522-
.attr('cy', (dot: TimeSeriesPoint) => { return yScale(dot.value); })
523+
.append('circle')
524+
.attr('class', (dot: TimeSeriesPoint) => 'dot dot-' + timeSeries.key + ' dot-x-' + xScale(dot.date).toString().replace('.', '_'))
525+
.style('opacity', '0')
526+
.attr('r', this.DOT_RADIUS)
527+
.attr('cx', (dot: TimeSeriesPoint) => {
528+
return xScale(dot.date);
529+
})
530+
.attr('cy', (dot: TimeSeriesPoint) => {
531+
return yScale(dot.value);
532+
})
523533
});
524534
}
525535

526-
private addMouseMarkerToChart(chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}>, xScale: D3ScaleTime<number, number>, data: TimeSeries[]) : void {
536+
private addMouseMarkerToChart(chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}>, xScale: D3ScaleTime<number, number>, data: TimeSeries[]): void {
527537
let markerGroup = chart.append('g').attr('id', 'marker-group');
528538

529-
// Append the marker line, initialy hidden
539+
// Append the marker line, initially hidden
530540
markerGroup.append('path')
531541
.attr('class', 'marker-line')
532542
.style('opacity', '0');
@@ -545,7 +555,9 @@ export class LineChartService {
545555
}
546556

547557
private addTooltipBoxToChart() {
548-
this._markerTooltip = d3Select('#time-series-chart').select(function() { return (<SVGElement>this).parentNode; }).append('div')
558+
this._markerTooltip = d3Select('#time-series-chart').select(function () {
559+
return (<SVGElement>this).parentNode;
560+
}).append('div')
549561
.attr('id', 'marker-tooltip')
550562
.style('opacity', '0.9');
551563
}
@@ -569,7 +581,7 @@ export class LineChartService {
569581
if (clusterKeys.length < 2) return;
570582
clusterKeys.sort();
571583

572-
var clusterIndex = bisect(clusterKeys, mouseXDatum.getTime().toString());
584+
let clusterIndex = bisect(clusterKeys, mouseXDatum.getTime().toString());
573585

574586
if (clusterIndex == 0) clusterIndex = 1;
575587
if (clusterIndex >= clusterKeys.length) clusterIndex = clusterKeys.length - 1;
@@ -579,8 +591,8 @@ export class LineChartService {
579591
const pointXBefore = xScale(firstPointFromClusterBefore.date);
580592
const pointXAfter = xScale(firstPointFromClusterAfter.date);
581593

582-
var pointX: number;
583-
var point: TimeSeriesPoint;
594+
let pointX: number;
595+
let point: TimeSeriesPoint;
584596
if (pointXAfter - mouseX < mouseX - pointXBefore) {
585597
pointX = pointXAfter;
586598
point = firstPointFromClusterAfter;
@@ -589,7 +601,7 @@ export class LineChartService {
589601
point = firstPointFromClusterBefore;
590602
}
591603
d3Select('.marker-line')
592-
.attr('d', function() {
604+
.attr('d', function () {
593605
let d = "M" + pointX + "," + containerHeight;
594606
d += " " + pointX + "," + 0;
595607
return d;
@@ -607,12 +619,12 @@ export class LineChartService {
607619
d3SelectAll('.dot').attr('r', this.DOT_RADIUS).style('opacity', '0');
608620

609621
const cx = pointX.toString().replace('.', '_');
610-
return d3SelectAll('.dot-x-'+cx).style('opacity', '1');
622+
return d3SelectAll('.dot-x-' + cx).style('opacity', '1');
611623
}
612624

613625
private highlightNearestDot(visibleDots: D3Selection<D3BaseType, {}, HTMLElement, any>, mouseY: number, yScale: D3ScaleLinear<number, number>) {
614-
var nearestDot;
615-
var minDistance;
626+
let nearestDot;
627+
let minDistance;
616628
visibleDots.each((_, index: number, nodes: []) => {
617629
const cy = parseFloat(d3Select(nodes[index]).attr('cy'));
618630
const distance = Math.abs(mouseY - cy);
@@ -636,10 +648,10 @@ export class LineChartService {
636648
const nearestDotXPosition: number = parseFloat(nearestDot.attr('cx'));
637649

638650
const top = parseFloat(nearestDot.attr('cy')) + this._margin.top;
639-
const left = ( tooltipWidth + nearestDotXPosition > this._width ) ?
651+
const left = (tooltipWidth + nearestDotXPosition > this._width) ?
640652
(nearestDotXPosition - tooltipWidth + this._margin.right + 10) : nearestDotXPosition + this._margin.left + 50;
641-
tooltip.style('top', top+'px');
642-
tooltip.style('left', left+ 'px');
653+
tooltip.style('top', top + 'px');
654+
tooltip.style('left', left + 'px');
643655

644656
}
645657

@@ -653,13 +665,13 @@ export class LineChartService {
653665
visibleDots
654666
.sort((a: TimeSeriesPoint, b: TimeSeriesPoint) => {
655667
// console.log(a,b);
656-
if (a.value > b.value) return -1
657-
else if (a.value < b.value) return 1
668+
if (a.value > b.value) return -1;
669+
else if (a.value < b.value) return 1;
658670
else return 0;
659671
})
660672
.each((timeSeriesPoint: TimeSeriesPoint, index: number, nodes: D3BaseType[]) => {
661673
// console.log(timeSeriesPoint, index, nodes[index]);
662-
tableBody.append(this.generateTooltipDatapointRow(timeSeriesPoint, nodes[index], nearestDot));
674+
tableBody.append(this.generateTooltipDataPointRow(timeSeriesPoint, nodes[index], nearestDot));
663675
});
664676

665677
return table;
@@ -678,7 +690,7 @@ export class LineChartService {
678690
return row;
679691
}
680692

681-
private generateTooltipDatapointRow(timeSeriesPoint: TimeSeriesPoint, node: D3BaseType, nearestDot: D3Selection<any, unknown, null, undefined>): string | Node {
693+
private generateTooltipDataPointRow(timeSeriesPoint: TimeSeriesPoint, node: D3BaseType, nearestDot: D3Selection<any, unknown, null, undefined>): string | Node {
682694
const nodeSelection = d3Select(node);
683695

684696
const label: HTMLTableCellElement = document.createElement('td');

0 commit comments

Comments
 (0)