Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/ServicePulse.Host/app/css/particular.css
Original file line number Diff line number Diff line change
Expand Up @@ -3526,4 +3526,58 @@ g.error .node-text .lead.saga {

g.error .node-text a:hover {
text-decoration: underline;
}

:root {
--avg-tooltip-background-color: #000;
}

div.avg-tooltip {
position: absolute;
text-align: left;
padding: .5rem;
line-height: 1;
background: var(--avg-tooltip-background-color);
color: #ffffff;
border-radius: 8px 1px 1px 8px;
pointer-events: none;
font-size: 11px;
white-space: nowrap;
}

div.avg-tooltip.left {
border-radius: 1px 8px 8px 1px;
}

div.avg-tooltip:before {
content: '';
display: block;
z-index: -1;
right: 0;
position: absolute;
top: 50%;
background-color: var(--avg-tooltip-background-color);
width: 24px;
height: 24px;
margin-top: -12px;
margin-right: -12px;

transform: rotate(45deg);
}

div.avg-tooltip.left:before {
right: inherit;
margin-right: inherit;
margin-left: -12px;
left:0;
}

div.avg-tooltip .value {
font-size: 14px;
font-weight: bold;
}

div.avg-tooltip .value span {
font-size: 11px;
font-weight: normal;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default function ArrowLabel({ pointToTheLeft = false, caption = '' }) {

var div = document.createElement('div');
div.style.position = 'absolute';
div.style.zIndex = 10;
div.style.visibility = 'hidden';
div.classList = `avg-tooltip${pointToTheLeft && ' left' || ''}`;
div.innerHTML = `<div>
${caption}
</div>
<div class="value">
0 <span></span>
</div>`;
document.body.appendChild(div);

return {
displayAt: function ({ x, y, color}) {
var lableDimensions = getComputedStyle(div);
//align the label vertically.
div.style.top = `${Math.trunc(y - lableDimensions.height.replace('px', '') / 2)}px`;

//align the label horizontally.
//get the label tip dimensions. The label tip is composed by a roated square of the ::before pseudo-element.
var labelTipWidth = getComputedStyle(div, ':before').width.replace('px', '');
var labelTipHeight = getComputedStyle(div, ':before').height.replace('px', '');
var lalbeTipHypotenuse = Math.trunc(Math.hypot(labelTipWidth, labelTipHeight));

if (pointToTheLeft == false) {
div.style.left = 'inherit';
div.style.right = `calc(100% - ${x}px + ${lalbeTipHypotenuse / 2}px)`;
} else {
div.style.right = 'inherit';
div.style.left = `${x + (lalbeTipHypotenuse / 2)}px`;
}

div.style.visibility = 'visible';
div.style.setProperty('--avg-tooltip-background-color', color); //by using properties the color of the 'before' content pseudo element can be updated.
},

hide: function () {
div.style.visibility = 'hidden';
},

value: function (value, unit) {
div.querySelector('.value').innerHTML = `${value} <span>${unit}</span>`;
},

pointingToTheLeft: pointToTheLeft
};
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
(function(window, angular, d3) {
import ArrowLabel from './ui.particular.arrowLabel';

(function(window, angular, d3) {
'use strict';

const averageDecimalsDefault = 2;
const avgLabelColorDefault = '#2700CB';
const avgLabelSuffixDefault = '';

var averageLabelToTheRight = ArrowLabel({pointToTheLeft: false, caption: 'AVG'});


angular.module('ui.particular.graph', [])
.directive('graph',
function() {
function(formatter) {
return {
restrict: 'E',
scope: {
plotData: '=',
formatter: '&',
minimumYaxis: '@'
minimumYaxis: '@',
isDurationGraph: '=isDurationGraph',
avgDecimals: '@'
},
template: '<svg></svg>',
link: function link(scope, element, attrs) {
attrs.avgLabelColor = attrs.avgLabelColor || avgLabelColorDefault;
attrs.metricSuffix = attrs.metricSuffix || avgLabelSuffixDefault;
scope.avgDecimals = scope.avgDecimals || averageDecimalsDefault;

scope.plotData = scope.plotData || { points: [], average: 0 };

scope.$watch('plotData',
Expand Down Expand Up @@ -92,13 +107,39 @@
.attr('class', 'graph-data-line');
}

chart.append('path')
var averageLine = chart.append('path')
.datum(Array(numberOfPoints).fill(average))
.attr('d', line)
.attr('class', 'graph-avg-line');

var displayAverageLabel = function(averageLine, label, value, color, unit) {
var {x, y, width} = averageLine.node().getBoundingClientRect();
label.value(value, unit);

if (label.pointingToTheLeft) {
label.displayAt({x:x + width + window.pageXOffset, y:y + window.pageYOffset, color});
} else {
label.displayAt({x:x + window.pageXOffset, y:y + window.pageYOffset, color});
}
}

chart.on("mouseover", function() {
var value = `${formatter.formatLargeNumber(average,scope.avgDecimals)}`;
var suffix = attrs.metricSuffix;

if (scope.isDurationGraph) {
value = `${formatter.formatTime(average).value}`;
suffix = formatter.formatTime(average).unit.toUpperCase();
}

displayAverageLabel(averageLine, averageLabelToTheRight, value, attrs.avgLabelColor, suffix);
})
.on("mouseout", function(){
averageLabelToTheRight.hide();
});
});
}
};
});
});

}(window, window.angular, window.d3));
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
(function(window, angular, d3) {
import ArrowLabel from './ui.particular.arrowLabel';

(function(window, angular, d3) {
'use strict';

const averageDecimalsDefault = 2;
const avgLabelSuffixDefault = '';

var averageLabelToTheRight = ArrowLabel({pointToTheLeft: false, caption: 'AVG'});
var averageLabelToTheLeft = ArrowLabel({pointToTheLeft: true, caption: 'AVG'});

function drawDataSeries(chart, data, color, fillColor, scaleX, scaleY) {

var area = d3.area()
Expand Down Expand Up @@ -40,13 +48,15 @@

var group = chart.append('g').attr('class', 'dataAverage');

group.append('path')
var avgLine = group.append('path')
.datum(Array(data.points.length).fill(data.average))
.attr('d', line)
.attr('stroke', color)
.attr('stroke-width', 1.5)
.attr('opacity', 0.5)
.attr('stroke-dasharray', '10,10');

return avgLine;
}

function padToWholeValue(value) {
Expand Down Expand Up @@ -78,10 +88,14 @@
isDurationGraph: '=isDurationGraph',
minimumYaxis: '@',
width: '=plotWidth',
height: '=plotHeight'
height: '=plotHeight',
avgDecimals: '@'
},
template: '<svg></svg>',
link: function link(scope, element, attrs) {
link: function link(scope, element, attrs) {
scope.avgDecimals = scope.avgDecimals || averageDecimalsDefault;
attrs.metricSuffix = attrs.metricSuffix || avgLabelSuffixDefault;

scope.$watch('firstDataSeries', function () {

var svg = element.find('svg')[0];
Expand Down Expand Up @@ -163,7 +177,18 @@
}

var drawAverage = function(data, lineColor, fillColor) {
drawAverageLine(chart, data, lineColor, fillColor, scaleX, scaleY);
return drawAverageLine(chart, data, lineColor, fillColor, scaleX, scaleY);
}

var displayAverageLabel = function(averageLine, label, value, color, unit) {
var {x, y, width} = averageLine.node().getBoundingClientRect();
label.value(value, unit);

if (label.pointingToTheLeft) {
label.displayAt({x:x + width + window.pageXOffset, y:y + window.pageYOffset, color});
} else {
label.displayAt({x:x + window.pageXOffset, y:y + window.pageYOffset, color});
}
}

drawSeries(firstSeries, attrs.firstSeriesColor, attrs.firstSeriesFillColor);
Expand All @@ -172,14 +197,43 @@
drawSeries(secondSeries, attrs.secondSeriesColor,attrs.secondSeriesFillColor);
}

drawAverage(firstSeries, attrs.firstSeriesColor, attrs.firstSeriesFillColor );
var firstAverageLine = drawAverage(firstSeries, attrs.firstSeriesColor, attrs.firstSeriesFillColor );

var secondAverageLine = null;

if (secondSeries) {
drawAverage(secondSeries, attrs.secondSeriesColor, attrs.secondSeriesFillColor);
secondAverageLine = drawAverage(secondSeries, attrs.secondSeriesColor, attrs.secondSeriesFillColor);
}

chart.on("mouseover", function() {
var value = `${formatter.formatLargeNumber(firstSeries.average, scope.avgDecimals)}`;
var suffix = attrs.metricSuffix;

if (scope.isDurationGraph) {
value = `${formatter.formatTime(firstSeries.average).value}`;
suffix = formatter.formatTime(firstSeries.average).unit.toUpperCase();
}

displayAverageLabel(firstAverageLine, averageLabelToTheRight, value, attrs.firstSeriesColor, suffix);

if (secondAverageLine && secondSeries.points.length > 0) {
value = `${formatter.formatLargeNumber(secondSeries.average, scope.avgDecimals)}`;

if (scope.isDurationGraph) {
value = `${formatter.formatTime(secondSeries.average).value}`;
suffix = formatter.formatTime(secondSeries.average).unit.toUpperCase();
}

displayAverageLabel(secondAverageLine, averageLabelToTheLeft, value, attrs.secondSeriesColor, suffix);
}
})
.on("mouseout", function() {
averageLabelToTheRight.hide();
averageLabelToTheLeft.hide();
});
});
}
};
});

}(window, window.angular, window.d3));
}(window, window.angular, window.d3));
Loading