mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Merge pull request #418 from peitschie/benchmark-units
Improve benchmark appearance slightly and add km/h & pages/h units
This commit is contained in:
@@ -11,15 +11,18 @@
|
||||
<h1>Loading required files. This may take a while.</h1>
|
||||
</div>
|
||||
<div id="benchmarkView">
|
||||
<h1>Benchmark results</h1>
|
||||
<h1>Benchmark [<span id="version" class="value">unknown</span>]</h1>
|
||||
<table id="benchmarkResults">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="action">Action</td>
|
||||
<td class="status">Status</td>
|
||||
<td class="elapsed">Elapsed time (ms)</td>
|
||||
<td class="elapsed">Time taken<br/> (ms)</td>
|
||||
<td class="speed">km/h</td>
|
||||
<td class="pages">pages/h</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="documentView">
|
||||
|
||||
@@ -51,12 +51,14 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
context.recordDistanceFromCurrentSelection(state);
|
||||
action.start();
|
||||
sharedState.sessionController.getDirectFormattingController().alignParagraphJustified();
|
||||
context.sessionController.getDirectFormattingController().alignParagraphJustified();
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,35 +36,19 @@
|
||||
* @source: https://github.com/kogmbh/WebODF/
|
||||
*/
|
||||
|
||||
define([], function() {
|
||||
define(["OdfBenchmarkContext"], function(OdfBenchmarkContext) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @struct
|
||||
*/
|
||||
function SharedState() {
|
||||
/**
|
||||
* @type {!odf.OdfCanvas}
|
||||
*/
|
||||
this.odfCanvas = null;
|
||||
|
||||
/**
|
||||
* @type {!gui.SessionController}
|
||||
*/
|
||||
this.sessionController = null;
|
||||
}
|
||||
|
||||
runtime.loadClass("core.EventNotifier");
|
||||
runtime.loadClass("odf.OdfCanvas");
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!HTMLElement} canvasElement
|
||||
*/
|
||||
function Benchmark() {
|
||||
function Benchmark(canvasElement) {
|
||||
var self = this,
|
||||
canvasElement = document.getElementById("canvas"),
|
||||
sharedState = new SharedState(),
|
||||
context = new OdfBenchmarkContext(),
|
||||
events = new core.EventNotifier(["start", "complete"]),
|
||||
currentActionIndex,
|
||||
lastProfileAction;
|
||||
@@ -79,7 +63,7 @@ define([], function() {
|
||||
if (currentAction) {
|
||||
lastProfileAction = currentAction.state.description;
|
||||
console.profile(lastProfileAction);
|
||||
currentAction.start(sharedState);
|
||||
currentAction.start(context);
|
||||
} else {
|
||||
events.emit("complete", {});
|
||||
}
|
||||
@@ -96,10 +80,20 @@ define([], function() {
|
||||
});
|
||||
|
||||
events.emit("start", {});
|
||||
sharedState.odfCanvas = new odf.OdfCanvas(canvasElement);
|
||||
context.odfCanvas = new odf.OdfCanvas(canvasElement);
|
||||
currentActionIndex = -1;
|
||||
executeNextAction();
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {!string}
|
||||
*/
|
||||
this.getWebODFVersion = function() {
|
||||
return (typeof webodf_version !== "undefined"
|
||||
? String(webodf_version)
|
||||
: "uncompiled"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
return Benchmark;
|
||||
|
||||
@@ -57,11 +57,14 @@ define(function() {
|
||||
startedAt = new Date().getTime();
|
||||
};
|
||||
|
||||
this.stop = function() {
|
||||
state.elapsedTime = new Date().getTime() - startedAt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {!boolean} result
|
||||
*/
|
||||
this.complete = function(result) {
|
||||
state.elapsedTime = new Date().getTime() - startedAt;
|
||||
state.status = result;
|
||||
events.emit("complete", state);
|
||||
};
|
||||
|
||||
@@ -51,13 +51,15 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
context.recordDistanceFromCurrentSelection(state);
|
||||
action.start();
|
||||
sharedState.sessionController.getDirectFormattingController().setBold(true);
|
||||
context.sessionController.getDirectFormattingController().setBold(true);
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return BoldCurrentSelection;
|
||||
|
||||
@@ -71,9 +71,9 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
var session,
|
||||
sessionController,
|
||||
shadowCursor,
|
||||
@@ -83,7 +83,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
|
||||
action.start();
|
||||
|
||||
session = new ops.Session(sharedState.odfCanvas);
|
||||
session = new ops.Session(context.odfCanvas);
|
||||
shadowCursor = new gui.ShadowCursor(session.getOdtDocument());
|
||||
sessionController = new gui.SessionController(session, localMemberId, shadowCursor, sessionControllerOptions);
|
||||
sessionController.setUndoManager(undoManager);
|
||||
@@ -104,8 +104,11 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
|
||||
sessionController.insertLocalCursor();
|
||||
sessionController.startEditing();
|
||||
sharedState.sessionController = sessionController;
|
||||
|
||||
context.session = session;
|
||||
context.sessionController = sessionController;
|
||||
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (C) 2010-2014 KO GmbH <copyright@kogmbh.com>
|
||||
*
|
||||
* @licstart
|
||||
* This file is part of WebODF.
|
||||
*
|
||||
* WebODF is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License (GNU AGPL)
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* WebODF is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
|
||||
* @licend
|
||||
*
|
||||
* @source: http://www.webodf.org/
|
||||
* @source: https://github.com/kogmbh/WebODF/
|
||||
*/
|
||||
|
||||
|
||||
define(function() {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Object} action
|
||||
* @param {!number} index
|
||||
* @param {!HTMLTableElement} outputTable
|
||||
* @param {!number} pxPerCm
|
||||
*/
|
||||
function HTMLActionResult(action, index, outputTable, pxPerCm) {
|
||||
var descriptionCell = document.createElement('td'),
|
||||
statusCell = document.createElement('td'),
|
||||
elapsedMsCell = document.createElement('td'),
|
||||
speedCell = document.createElement('td'),
|
||||
pagesPerHr = document.createElement('td');
|
||||
|
||||
function formatNumber(number) {
|
||||
if (number > 1000000) {
|
||||
return (number / 1000000).toFixed(2) + " mill";
|
||||
}
|
||||
return number.toFixed(2);
|
||||
}
|
||||
|
||||
function pxPerMsToKmPerHr(pxPerMs) {
|
||||
// Google knows!
|
||||
// https://www.google.com.au/search?q=centimeters%20per%20millisecond%20to%20kilometers%20per%20hour
|
||||
var cmPerSecond = (pxPerMs / pxPerCm),
|
||||
kmsPerHr = (cmPerSecond * 36);
|
||||
return formatNumber(kmsPerHr);
|
||||
}
|
||||
|
||||
function toPagesPerMin(stepsPerMs) {
|
||||
// http://anycount.com/WordCountBlog/how-many-words-in-one-page/
|
||||
var pagesPerHr = (stepsPerMs / 3838) * 1000 * 60 * 60;
|
||||
return formatNumber(pagesPerHr);
|
||||
}
|
||||
|
||||
function start() {
|
||||
statusCell.textContent = "running";
|
||||
elapsedMsCell.textContent = "";
|
||||
speedCell.textContent = "";
|
||||
}
|
||||
|
||||
function complete(state) {
|
||||
statusCell.textContent = state.status ? "done" : "failed";
|
||||
elapsedMsCell.textContent = state.elapsedTime;
|
||||
if (state.horizontalTravelPx !== undefined) {
|
||||
speedCell.classList.add("active");
|
||||
speedCell.textContent = pxPerMsToKmPerHr(state.horizontalTravelPx / state.elapsedTime);
|
||||
}
|
||||
if (state.travelledSteps !== undefined) {
|
||||
pagesPerHr.classList.add("active");
|
||||
pagesPerHr.textContent = toPagesPerMin(state.travelledSteps / state.elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
var tr = document.createElement('tr');
|
||||
|
||||
descriptionCell.className = "action";
|
||||
statusCell.className = "status";
|
||||
elapsedMsCell.className = "elapsed";
|
||||
speedCell.className = "speed";
|
||||
pagesPerHr.className = "pages";
|
||||
|
||||
[descriptionCell, statusCell, elapsedMsCell, speedCell, pagesPerHr].forEach(function(cell) {
|
||||
tr.appendChild(cell);
|
||||
});
|
||||
|
||||
outputTable.appendChild(tr);
|
||||
descriptionCell.textContent = (index + 1) + ". " + action.state.description;
|
||||
|
||||
action.subscribe("start", start);
|
||||
action.subscribe("complete", complete);
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
return HTMLActionResult;
|
||||
}
|
||||
);
|
||||
@@ -99,14 +99,18 @@ define([
|
||||
* @constructor
|
||||
*/
|
||||
function HTMLBenchmark() {
|
||||
var loadingScreen = document.getElementById('loadingScreen'),
|
||||
var loadingScreenElement = document.getElementById('loadingScreen'),
|
||||
canvasElement = document.getElementById("canvas"),
|
||||
benchmarkResultsElement = document.getElementById("benchmarkResults").getElementsByTagName("tbody")[0],
|
||||
versionElement = document.getElementById("version"),
|
||||
config = getConfiguration(),
|
||||
benchmark = new Benchmark(),
|
||||
renderer = new HTMLResultsRenderer(benchmark);
|
||||
benchmark = new Benchmark(canvasElement),
|
||||
renderer = new HTMLResultsRenderer(benchmark, benchmarkResultsElement);
|
||||
|
||||
versionElement.textContent = benchmark.getWebODFVersion();
|
||||
renderer.setBackgroundColour(config.colour);
|
||||
|
||||
loadingScreen.style.display = "none";
|
||||
loadingScreenElement.style.display = "none";
|
||||
|
||||
benchmark.actions.push(new PreloadDocument(config.fileUrl));
|
||||
benchmark.actions.push(new OpenDocument(config.fileUrl));
|
||||
|
||||
@@ -36,48 +36,21 @@
|
||||
* @source: https://github.com/kogmbh/WebODF/
|
||||
*/
|
||||
|
||||
define(function() {
|
||||
define(["HTMLActionResult"], function(HTMLActionResult) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @param {!Benchmark} benchmark
|
||||
* @constructor
|
||||
* @param {!Benchmark} benchmark
|
||||
* @param {!HTMLTableElement} outputTable
|
||||
*/
|
||||
function HTMLResultsRenderer(benchmark) {
|
||||
var outputTable = document.getElementById("benchmarkResults");
|
||||
|
||||
/**
|
||||
* @param {!Text} node
|
||||
* @param {!string} newValue
|
||||
*/
|
||||
function setText(node, newValue) {
|
||||
node.replaceData(0, node.length, newValue);
|
||||
}
|
||||
function HTMLResultsRenderer(benchmark, outputTable) {
|
||||
var results = [],
|
||||
pxPerCm;
|
||||
|
||||
function onStart() {
|
||||
benchmark.actions.forEach(function(action, index) {
|
||||
var tr = document.createElement('tr'),
|
||||
cells = ["action", "status", "elapsed"].map(function(clazz) {
|
||||
var td = document.createElement('td'),
|
||||
text = document.createTextNode("");
|
||||
td.className = clazz;
|
||||
td.appendChild(text);
|
||||
tr.appendChild(td);
|
||||
return text;
|
||||
});
|
||||
|
||||
outputTable.appendChild(tr);
|
||||
setText(cells[0], (index + 1) + ". " + action.state.description);
|
||||
|
||||
action.subscribe("start", function() {
|
||||
setText(cells[1], "running");
|
||||
setText(cells[2], "");
|
||||
});
|
||||
|
||||
action.subscribe("complete", function(state) {
|
||||
setText(cells[1], state.status ? "done" : "failed");
|
||||
setText(cells[2], state.elapsedTime);
|
||||
});
|
||||
results.push(new HTMLActionResult(action, index, outputTable, pxPerCm));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -96,6 +69,18 @@ define(function() {
|
||||
};
|
||||
|
||||
function init() {
|
||||
var parent,
|
||||
testChild;
|
||||
|
||||
// Determine how many px per cm on the current screen
|
||||
parent = outputTable.parentNode;
|
||||
testChild = document.createElement("div");
|
||||
testChild.style.width = "1cm";
|
||||
testChild.style.height = "1cm";
|
||||
parent.appendChild(testChild);
|
||||
pxPerCm = testChild.getBoundingClientRect().width;
|
||||
parent.removeChild(testChild);
|
||||
|
||||
benchmark.subscribe("start", onStart);
|
||||
benchmark.subscribe("complete", onComplete);
|
||||
}
|
||||
|
||||
@@ -52,14 +52,17 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
var count;
|
||||
context.storeCurrentPosition(state);
|
||||
action.start();
|
||||
for (count = 0; count < times; count += 1) {
|
||||
sharedState.sessionController.getTextController().insertText('A');
|
||||
context.sessionController.getTextController().insertText('A');
|
||||
}
|
||||
action.stop();
|
||||
context.recordDistanceFromPreviousPosition(state);
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +52,17 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
var count;
|
||||
context.storeCurrentPosition(state);
|
||||
action.start();
|
||||
for (count = 0; count < steps; count += 1) {
|
||||
sharedState.sessionController.getSelectionController().moveCursorToLeft();
|
||||
context.sessionController.getSelectionController().moveCursorToLeft();
|
||||
}
|
||||
action.stop();
|
||||
context.recordDistanceFromPreviousPosition(state);
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,13 +51,16 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
context.storeCurrentPosition(state);
|
||||
action.start();
|
||||
sharedState.sessionController.getSelectionController().moveCursorToDocumentEnd();
|
||||
context.sessionController.getSelectionController().moveCursorToDocumentEnd();
|
||||
action.stop();
|
||||
context.recordDistanceFromPreviousPosition(state);
|
||||
action.complete(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return MoveCursorToEnd;
|
||||
|
||||
@@ -51,18 +51,22 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
var canvasElement,
|
||||
range;
|
||||
|
||||
context.storeCurrentPosition(state);
|
||||
action.start();
|
||||
|
||||
canvasElement = sharedState.odfCanvas.getElement();
|
||||
canvasElement = context.odfCanvas.getElement();
|
||||
range = canvasElement.ownerDocument.createRange();
|
||||
range.setStart(canvasElement, canvasElement.childNodes.length);
|
||||
sharedState.sessionController.getSelectionController().selectRange(range, true, 1);
|
||||
context.sessionController.getSelectionController().selectRange(range, true, 1);
|
||||
|
||||
action.stop();
|
||||
context.recordDistanceFromPreviousPosition(state);
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,14 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
context.storeCurrentPosition(state);
|
||||
action.start();
|
||||
sharedState.sessionController.getSelectionController().moveCursorToDocumentStart();
|
||||
context.sessionController.getSelectionController().moveCursorToDocumentStart();
|
||||
action.stop();
|
||||
context.recordDistanceFromPreviousPosition(state);
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (C) 2010-2014 KO GmbH <copyright@kogmbh.com>
|
||||
*
|
||||
* @licstart
|
||||
* This file is part of WebODF.
|
||||
*
|
||||
* WebODF is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License (GNU AGPL)
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* WebODF is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
|
||||
* @licend
|
||||
*
|
||||
* @source: http://www.webodf.org/
|
||||
* @source: https://github.com/kogmbh/WebODF/
|
||||
*/
|
||||
|
||||
define(["RangeCalculator"], function(RangeCalculator) {
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function OdfBenchmarkContext() {
|
||||
var self = this,
|
||||
rangeCalculator = new RangeCalculator();
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
function initialized() {
|
||||
return Boolean(self.session && self.sessionController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!number} length
|
||||
* @return {!number}
|
||||
*/
|
||||
function measureSelectionLength(length) {
|
||||
var odtDocument = self.session.getOdtDocument(),
|
||||
position = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
|
||||
|
||||
return rangeCalculator.measureTraversedDistance(odtDocument.convertCursorToDomRange(position, length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!number}
|
||||
*/
|
||||
function measureCurrentSelection() {
|
||||
var range = self.session.getOdtDocument().getCursor(self.sessionController.getInputMemberId()).getSelectedRange();
|
||||
return rangeCalculator.measureTraversedDistance(range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {?odf.OdfCanvas}
|
||||
*/
|
||||
this.odfCanvas = null;
|
||||
|
||||
/**
|
||||
* @type {?ops.Session}
|
||||
*/
|
||||
this.session = null;
|
||||
|
||||
/**
|
||||
* @type {?gui.SessionController}
|
||||
*/
|
||||
this.sessionController = null;
|
||||
|
||||
/**
|
||||
* Calculate the traveled distance from the supplied length in cursor steps
|
||||
* @param {!Object} state
|
||||
* @param {!number} length
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.recordDistanceFromLength = function(state, length) {
|
||||
if (initialized()) {
|
||||
state.travelledSteps = Math.abs(length);
|
||||
state.horizontalTravelPx = measureSelectionLength(length);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Store the current cursor position onto the provided state
|
||||
* @param {!Object} state
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.storeCurrentPosition = function(state) {
|
||||
var odtDocument;
|
||||
|
||||
if (initialized()) {
|
||||
odtDocument = self.session.getOdtDocument();
|
||||
state.initialCursorPosition = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the traveled distance from the previously recorded position
|
||||
* @param {!Object} state
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.recordDistanceFromPreviousPosition = function(state) {
|
||||
var odtDocument,
|
||||
finalCursorPosition;
|
||||
|
||||
if (initialized()) {
|
||||
odtDocument = self.session.getOdtDocument();
|
||||
runtime.assert(state.initialCursorPosition !== undefined, "Initial cursor position should first be saved with context.storeCurrentPosition");
|
||||
finalCursorPosition = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
|
||||
state.travelledSteps = Math.abs(state.initialCursorPosition - finalCursorPosition);
|
||||
state.horizontalTravelPx = measureSelectionLength(state.initialCursorPosition - finalCursorPosition)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the traveled distance from the current selection
|
||||
* @param {!Object} state
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.recordDistanceFromCurrentSelection = function(state) {
|
||||
var odtDocument,
|
||||
selection;
|
||||
|
||||
if (initialized()) {
|
||||
odtDocument = self.session.getOdtDocument();
|
||||
selection = odtDocument.getCursorSelection(self.sessionController.getInputMemberId());
|
||||
state.travelledSteps = Math.abs(selection.length);
|
||||
state.horizontalTravelPx = measureCurrentSelection();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return OdfBenchmarkContext;
|
||||
});
|
||||
@@ -49,6 +49,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
action = new BenchmarkAction(state);
|
||||
|
||||
function onDocumentLoaded() {
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
|
||||
@@ -56,12 +57,12 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
action.start();
|
||||
sharedState.odfCanvas.addListener("statereadychange", onDocumentLoaded);
|
||||
sharedState.odfCanvas.load(docUrl);
|
||||
context.odfCanvas.addListener("statereadychange", onDocumentLoaded);
|
||||
context.odfCanvas.load(docUrl);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
action = new BenchmarkAction(state);
|
||||
|
||||
function onDocumentDownloaded() {
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
|
||||
@@ -56,9 +57,9 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
action.start();
|
||||
runtime.readFile(docUrl, 'binary', onDocumentDownloaded);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (C) 2010-2014 KO GmbH <copyright@kogmbh.com>
|
||||
*
|
||||
* @licstart
|
||||
* This file is part of WebODF.
|
||||
*
|
||||
* WebODF is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License (GNU AGPL)
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* WebODF is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
|
||||
* @licend
|
||||
*
|
||||
* @source: http://www.webodf.org/
|
||||
* @source: https://github.com/kogmbh/WebODF/
|
||||
*/
|
||||
|
||||
define([], function() {
|
||||
|
||||
runtime.loadClass("odf.OdfUtils");
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function RangeCalculator() {
|
||||
var odfUtils = new odf.OdfUtils(),
|
||||
textRange = document.createRange(),
|
||||
TEXT_NODE = Node.TEXT_NODE;
|
||||
|
||||
/**
|
||||
* Calculate the amount of horizontal movement experienced while traversing
|
||||
* the supplied range.
|
||||
* @param {!Range} range
|
||||
* @return {!number}
|
||||
*/
|
||||
this.measureTraversedDistance = function (range) {
|
||||
var textElements = odfUtils.getTextElements(range, true, false),
|
||||
horizontalDistance = 0;
|
||||
|
||||
textElements.forEach(function(node) {
|
||||
var clientRects,
|
||||
i,
|
||||
rect;
|
||||
|
||||
if (node.nodeType === TEXT_NODE) {
|
||||
textRange.selectNodeContents(node);
|
||||
if (range.startContainer === node) {
|
||||
textRange.setStart(range.startContainer, range.startOffset);
|
||||
}
|
||||
if (range.endContainer === node) {
|
||||
range.setEnd(range.endContainer, range.endOffset);
|
||||
}
|
||||
clientRects = textRange.getClientRects();
|
||||
} else {
|
||||
clientRects = node.getClientRects();
|
||||
}
|
||||
for (i = 0; i < clientRects.length; i += 1) {
|
||||
rect = clientRects[i];
|
||||
horizontalDistance += rect.width;
|
||||
}
|
||||
});
|
||||
|
||||
return horizontalDistance;
|
||||
};
|
||||
}
|
||||
|
||||
return RangeCalculator;
|
||||
|
||||
});
|
||||
@@ -51,11 +51,13 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
context.recordDistanceFromCurrentSelection(state);
|
||||
action.start();
|
||||
sharedState.sessionController.getTextController().removeCurrentSelection();
|
||||
context.sessionController.getTextController().removeCurrentSelection();
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,18 +53,20 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
var count;
|
||||
context.recordDistanceFromLength(state, useBackspace ? -times : times);
|
||||
action.start();
|
||||
for (count = 0; count < times; count += 1) {
|
||||
if (useBackspace) {
|
||||
sharedState.sessionController.getTextController().removeTextByBackspaceKey();
|
||||
context.sessionController.getTextController().removeTextByBackspaceKey();
|
||||
} else {
|
||||
sharedState.sessionController.getTextController().removeTextByDeleteKey();
|
||||
context.sessionController.getTextController().removeTextByDeleteKey();
|
||||
}
|
||||
}
|
||||
action.stop();
|
||||
action.complete(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,13 +51,15 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @param {!SharedState} sharedState
|
||||
* @param {!OdfBenchmarkContext} context
|
||||
*/
|
||||
this.start = function(sharedState) {
|
||||
this.start = function(context) {
|
||||
action.start();
|
||||
sharedState.sessionController.getSelectionController().extendSelectionToEntireDocument();
|
||||
context.sessionController.getSelectionController().extendSelectionToEntireDocument();
|
||||
action.stop();
|
||||
context.recordDistanceFromCurrentSelection(state);
|
||||
action.complete(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SelectEntireDocument;
|
||||
|
||||
@@ -12,20 +12,75 @@ body {
|
||||
max-width: 100%;
|
||||
/*width: 400px;*/
|
||||
float: left;
|
||||
background-color: #70a186;
|
||||
background-color: #49A34B;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
#benchmarkView h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#documentView {
|
||||
min-height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#benchmarkResults {
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#benchmarkResults td {
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
#benchmarkResults thead {
|
||||
font-weight: bold;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
#benchmarkResults thead td {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#benchmarkResults thead td:not(:last-of-type) {
|
||||
border-right: 1px solid white;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody td {
|
||||
border-right: 1px solid white;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody td:first-of-type {
|
||||
border-left: 1px solid white;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody tr {
|
||||
border-top: 1px solid white;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody tr:hover td {
|
||||
background-color: #5AB953;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody tr:nth-child(2n+0) {
|
||||
background-color: #E6FFBF;
|
||||
}
|
||||
|
||||
#benchmarkResults tbody tr:nth-child(2n+1) {
|
||||
background-color: #BEEE9E;
|
||||
}
|
||||
|
||||
#benchmarkResults .status {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#benchmarkResults .elapsed {
|
||||
#benchmarkResults tbody .elapsed,
|
||||
#benchmarkResults tbody .speed,
|
||||
#benchmarkResults tbody .pages
|
||||
{
|
||||
padding-left: 1em;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,18 @@
|
||||
<h1>Loading required files. This may take a while.</h1>
|
||||
</div>
|
||||
<div id="benchmarkView">
|
||||
<h1>Benchmark results</h1>
|
||||
<h1>Benchmark [<span id="version" class="value">unknown</span>]</h1>
|
||||
<table id="benchmarkResults">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="action">Action</td>
|
||||
<td class="status">Status</td>
|
||||
<td class="elapsed">Elapsed time (ms)</td>
|
||||
<td class="elapsed">Time taken<br/> (ms)</td>
|
||||
<td class="speed">km/h</td>
|
||||
<td class="pages">pages/h</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="documentView">
|
||||
|
||||
Reference in New Issue
Block a user