mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1123306 - Remove minSquaredDistanceBetweenPoints from the LineGraph, r=jsantell
This commit is contained in:
parent
8b92678a58
commit
c4a9090f20
@ -49,7 +49,6 @@ const GRAPH_STRIPE_PATTERN_LINE_SPACING = 4; // px
|
||||
// Line graph constants.
|
||||
|
||||
const LINE_GRAPH_DAMPEN_VALUES = 0.85;
|
||||
const LINE_GRAPH_MIN_SQUARED_DISTANCE_BETWEEN_POINTS = 1; // px
|
||||
const LINE_GRAPH_TOOLTIP_SAFE_BOUNDS = 8; // px
|
||||
const LINE_GRAPH_MIN_MAX_TOOLTIP_DISTANCE = 14; // px
|
||||
|
||||
@ -1232,12 +1231,6 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
|
||||
*/
|
||||
dampenValuesFactor: LINE_GRAPH_DAMPEN_VALUES,
|
||||
|
||||
/**
|
||||
* Points that are too close too each other in the graph will not be rendered.
|
||||
* This scalar specifies the required minimum squared distance between points.
|
||||
*/
|
||||
minSquaredDistanceBetweenPoints: LINE_GRAPH_MIN_SQUARED_DISTANCE_BETWEEN_POINTS,
|
||||
|
||||
/**
|
||||
* Specifies if min/max/avg tooltips have arrow handlers on their sides.
|
||||
*/
|
||||
@ -1266,11 +1259,6 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
|
||||
plottedData,
|
||||
plottedMinMaxSum
|
||||
} = yield CanvasGraphUtils._performTaskInWorker("plotTimestampsGraph", {
|
||||
width: this._width,
|
||||
height: this._height,
|
||||
dataOffsetX: this.dataOffsetX,
|
||||
dampenValuesFactor: this.dampenValuesFactor,
|
||||
minSquaredDistanceBetweenPoints: this.minSquaredDistanceBetweenPoints,
|
||||
timestamps: timestamps,
|
||||
interval: interval
|
||||
});
|
||||
@ -1294,16 +1282,11 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
|
||||
let maxValue = Number.MIN_SAFE_INTEGER;
|
||||
let minValue = Number.MAX_SAFE_INTEGER;
|
||||
let avgValue = 0;
|
||||
let forceDrawAllPoints = false;
|
||||
|
||||
if (this._tempMinMaxSum) {
|
||||
maxValue = this._tempMinMaxSum.maxValue;
|
||||
minValue = this._tempMinMaxSum.minValue;
|
||||
avgValue = this._tempMinMaxSum.avgValue;
|
||||
// If we use cached `minValue`, `maxValue`, `avgValue` then we can assume
|
||||
// that we've already removed points that did not meet the
|
||||
// `minSquaredDistanceBetweenPoints` requirement.
|
||||
forceDrawAllPoints = true;
|
||||
} else {
|
||||
let sumValues = 0;
|
||||
for (let { delta, value } of this._data) {
|
||||
@ -1332,10 +1315,6 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
|
||||
ctx.lineWidth = this.strokeWidth * this._pixelRatio;
|
||||
ctx.beginPath();
|
||||
|
||||
let prevX = 0;
|
||||
let prevY = 0;
|
||||
let minSqDist = this.minSquaredDistanceBetweenPoints;
|
||||
|
||||
for (let { delta, value } of this._data) {
|
||||
let currX = (delta - this.dataOffsetX) * dataScaleX;
|
||||
let currY = height - value * dataScaleY;
|
||||
@ -1345,11 +1324,7 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
|
||||
ctx.lineTo(-LINE_GRAPH_STROKE_WIDTH, currY);
|
||||
}
|
||||
|
||||
if (forceDrawAllPoints || distSquared(prevX, prevY, currX, currY) >= minSqDist) {
|
||||
ctx.lineTo(currX, currY);
|
||||
prevX = currX;
|
||||
prevY = currY;
|
||||
}
|
||||
ctx.lineTo(currX, currY);
|
||||
|
||||
if (delta == lastTick) {
|
||||
ctx.lineTo(width + LINE_GRAPH_STROKE_WIDTH, currY);
|
||||
|
@ -19,17 +19,14 @@ self.onmessage = e => {
|
||||
/**
|
||||
* @see LineGraphWidget.prototype.setDataFromTimestamps in Graphs.jsm
|
||||
* @param number id
|
||||
* @param number width
|
||||
* @param number height
|
||||
* @param array timestamps
|
||||
* @param number interval
|
||||
*/
|
||||
function plotTimestampsGraph(id, args) {
|
||||
let plottedData = plotTimestamps(args.timestamps, args.interval);
|
||||
let plottedMinMaxSum = getMinMaxSum(plottedData);
|
||||
let sparsifiedData = sparsifyLineData(plottedData, plottedMinMaxSum, args);
|
||||
|
||||
let response = { id, plottedData: sparsifiedData, plottedMinMaxSum };
|
||||
let response = { id, plottedData, plottedMinMaxSum };
|
||||
self.postMessage(response);
|
||||
}
|
||||
|
||||
@ -55,48 +52,6 @@ function getMinMaxSum(source) {
|
||||
return { minValue, maxValue, avgValue };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce a data source for a line graph, based off of a minimum distance
|
||||
* between the points to render.
|
||||
*/
|
||||
function sparsifyLineData(plottedData, plottedMinMaxSum, options) {
|
||||
let { width: graphWidth, height: graphHeight } = options;
|
||||
let { dataOffsetX, dampenValuesFactor } = options;
|
||||
let { minSquaredDistanceBetweenPoints } = options;
|
||||
|
||||
let result = [];
|
||||
|
||||
let totalTicks = plottedData.length;
|
||||
let maxValue = plottedMinMaxSum.maxValue;
|
||||
|
||||
let firstTick = totalTicks ? plottedData[0].delta : 0;
|
||||
let lastTick = totalTicks ? plottedData[totalTicks - 1].delta : 0;
|
||||
let dataScaleX = graphWidth / (lastTick - dataOffsetX);
|
||||
let dataScaleY = graphHeight / maxValue * dampenValuesFactor;
|
||||
|
||||
let prevX = 0;
|
||||
let prevY = 0;
|
||||
|
||||
for (let { delta, value } of plottedData) {
|
||||
let currX = (delta - dataOffsetX) * dataScaleX;
|
||||
let currY = graphHeight - value * dataScaleY;
|
||||
|
||||
if (delta == firstTick || delta == lastTick) {
|
||||
result.push({ delta, value });
|
||||
continue;
|
||||
}
|
||||
|
||||
let dist = distSquared(prevX, prevY, currX, currY);
|
||||
if (dist >= minSquaredDistanceBetweenPoints) {
|
||||
result.push({ delta, value });
|
||||
prevX = currX;
|
||||
prevY = currY;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a list of numbers and plots them on a line graph representing
|
||||
* the rate of occurences in a specified interval.
|
||||
@ -150,12 +105,3 @@ function plotTimestamps(timestamps, interval = 100, clamp = 60) {
|
||||
|
||||
return timeline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the squared distance between two 2D points.
|
||||
*/
|
||||
function distSquared(x0, y0, x1, y1) {
|
||||
let xs = x1 - x0;
|
||||
let ys = y1 - y0;
|
||||
return xs * xs + ys * ys;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user