-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plots: make measure script more flexible (CLI args) (#2183)
- Loading branch information
1 parent
b866ec4
commit 3f7e5a1
Showing
11 changed files
with
454 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- | ||
Copyright 2017 Google Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<script src="https://cdn.plot.ly/plotly-1.25.2.min.js"></script> | ||
<style> | ||
nav { display: flex; justify-content: center; font-size: 17px; font-family: "Open Sans", verdana, arial, sans-serif; padding: 5px 0 23px; border-bottom: 1px solid black; } | ||
nav a { padding: 0 5px; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
View results: | ||
<a href="./index.html">grouped by metric</a> | ||
<a href="./metrics-per-site.html">grouped by site</a> | ||
<a>bar charts per site</a> | ||
</nav> | ||
<script src="./out/generatedResults.js"></script> | ||
<script src="./bars-per-site.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* global Plotly, generatedResults */ | ||
/* eslint-env browser */ | ||
|
||
const IGNORED_METRICS = new Set(['Navigation Start']); | ||
|
||
const metrics = Object.keys(generatedResults).filter(metric => !IGNORED_METRICS.has(metric)); | ||
|
||
let elementId = 1; | ||
|
||
/** | ||
* Incrementally renders the plot, otherwise it hangs the browser | ||
* because it's generating so many charts. | ||
*/ | ||
const queuedPlots = []; | ||
|
||
function enqueuePlot(fn) { | ||
const isFirst = queuedPlots.length == 0; | ||
queuedPlots.push(fn); | ||
if (isFirst) { | ||
renderPlots(); | ||
} | ||
} | ||
|
||
function renderPlots() { | ||
window.requestAnimationFrame(_ => { | ||
const plotFn = queuedPlots.shift(); | ||
if (plotFn) { | ||
plotFn(); | ||
renderPlots(); | ||
} | ||
}); | ||
} | ||
|
||
function createChartElement(height = 800) { | ||
const div = document.createElement('div'); | ||
div.style = `width: 100%; height: ${height}px`; | ||
div.id = 'chart' + elementId++; | ||
document.body.appendChild(div); | ||
return div.id; | ||
} | ||
|
||
function generateGroupedBarChart() { | ||
const sitesCount = metrics.reduce( | ||
(acc, metric) => Math.max(acc, generatedResults[metric].length), | ||
0 | ||
); | ||
for (let i = 0; i < sitesCount; i++) { | ||
const data = metrics.map(metric => ({ | ||
y: generatedResults[metric][i].metrics.map(m => m ? m.timing : null), | ||
name: metric, | ||
type: 'bar' | ||
})); | ||
|
||
const layout = { | ||
yaxis: { | ||
rangemode: 'tozero' | ||
}, | ||
hovermode: 'closest', | ||
barmode: 'group', | ||
title: generatedResults[metrics[0]][i].site | ||
}; | ||
enqueuePlot(_ => { | ||
Plotly.newPlot(createChartElement(), data, layout); | ||
}); | ||
} | ||
} | ||
|
||
generateGroupedBarChart(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.