-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed row height optimization #221
base: fixed-height-optimization
Are you sure you want to change the base?
Changes from 4 commits
61cb0cc
bedd378
71c2f33
8f4bece
551bff3
43561dd
d183273
62c8bc6
fdcca3d
b1be940
45a8387
95a6d4a
359d905
b174ffc
0b62060
bbc1a74
dd3bdfc
3cff84e
07e7047
9c26d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Fixed Row Height</title> | ||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script> | ||
<script src="../../dist/ui-scroll.js"></script> | ||
<script src="fixedRowHeight.js"></script> | ||
<link rel="stylesheet" href="../css/style.css" type="text/css" /> | ||
</head> | ||
|
||
<body ng-app="application"> | ||
|
||
<div class="cont cont-global" ng-controller="MainCtrl"> | ||
|
||
<a class="back" href="../index.html">browse other examples</a> | ||
|
||
<h1 class="page-header page-header-exapmle">Fixed Row Height</h1> | ||
|
||
<div class="description"> | ||
<p> | ||
If the height of all the viewport rows is known and not going to be changed, | ||
it might be passed as "row-height" attribute. | ||
This reduces inner calculations and browser reflows, | ||
which leads to a performance increase. | ||
</p> | ||
</div> | ||
|
||
<div class="actions"> | ||
<input ng-model="perfSlowCount" size="4" /> performance decrease coefficient (0 - fastest) | ||
</div> | ||
|
||
<div class="viewport" ui-scroll-viewport> | ||
<div ui-scroll="item in datasource" buffer-size="10" row-height="25" adapter="adapter"> | ||
<div class="item" ng-style="{'height': '25px'}"> | ||
|
||
{{item.text}} | ||
<span ng-repeat="(key, value) in item.input track by $index"> | ||
<input ng-model="value.value" size="2" /> | ||
</span> | ||
{{getSum(item)}} | ||
{{getMul(item)}} | ||
{{getText(item)}} | ||
|
||
<span ng-repeat="(key, value) in perfSlowCountList track by $index"> | ||
<div style="height: 1px; width: 1px; overflow: hidden;"> | ||
{{item.text}} | ||
<span ng-repeat="(key, value) in item.input track by $index"> | ||
<input ng-model="value.value" size="2" /> | ||
</span> | ||
{{getSum(item)}} | ||
{{getMul(item)}} | ||
{{getText(item)}} | ||
</div> | ||
</span> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
angular.module('application', ['ui.scroll']) | ||
|
||
.controller('MainCtrl', ($scope) => { | ||
$scope.hello = 'Hello Main Controller!'; | ||
|
||
let min = -150, max = 200, delay = 0, inputs = 10; | ||
|
||
const getInput = index => { | ||
const result = []; | ||
for (let i = 0; i < inputs; i++) { | ||
result.push({ value: ((index % 2 === 0 ? -1 : 1) * (i + 1)).toString() }); | ||
} | ||
return result; | ||
} | ||
|
||
const data = []; | ||
for (let i = min; i <= max; i++) { | ||
height = 50 + (i + 1); | ||
data.push({ | ||
index: i, | ||
text: 'item #' + i, | ||
input: getInput(i) | ||
}); | ||
} | ||
|
||
$scope.datasource = { | ||
get: (index, count, success) => { | ||
console.log('Getting ' + count + ' items started from ' + index + '...'); | ||
setTimeout(() => { | ||
const result = []; | ||
const start = Math.max(min, index); | ||
const end = Math.min(index + count - 1, max); | ||
if (start <= end) { | ||
for (let i = start; i <= end; i++) { | ||
const _item = data.find(item => item.index === i); | ||
if (_item) { | ||
result.push(_item); | ||
} | ||
} | ||
} | ||
console.log('Got ' + result.length + ' items [' + start + '..' + end + ']'); | ||
success(result); | ||
}, delay); | ||
} | ||
}; | ||
|
||
$scope.getSum = item => | ||
item.input.reduce((a, i) => a + Number(i.value), 0); | ||
|
||
$scope.getMul = item => | ||
item.input.reduce((a, i) => a * Number(i.value), 1); | ||
|
||
$scope.getText = item => { | ||
const num = $scope.getMul(item).toString(); | ||
const result = []; | ||
for (let i = 0; i < item.text.length; i++) { | ||
result.push(item.text[i]); | ||
result.push(i < num.length ? num[i] : 'x'); | ||
} | ||
return result.join(''); | ||
} | ||
|
||
const perfSlowCountDefault = 2; | ||
$scope.perfSlowCount = perfSlowCountDefault; | ||
$scope.perfSlowCountList = []; | ||
$scope.$watch('perfSlowCount', () => { | ||
let size = Number($scope.perfSlowCount); | ||
if (isNaN(size)) { | ||
size = perfSlowCountDefault; | ||
} | ||
$scope.perfSlowCountList = (new Array(size)).fill(0); | ||
}) | ||
|
||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added demo, after
npm start
it is available ashttp://localhost:5005/fixedRowHeight/fixedRowHeight.html