physical-count.html
8.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!doctype html>
<html>
<head>
<title>physical count</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../../polymer/polymer.html">
<link rel="import" href="../../../paper-button/paper-button.html">
<link rel="import" href="../../iron-list.html">
<style is="custom-style">
body {
@apply(--layout-fullbleed);
}
.item {
background-color: green;
border-bottom: 1px solid white;
overflow:hidden;
}
.wrapper {
position: relative;
margin: 10px;
}
.wrapper .count {
background-color: red;
position: absolute;
top: 0;
right: 0;
z-index: 1;
}
.wrapper .stats {
background-color: red;
position: absolute;
top: 20px;
right: 0;
z-index: 1;
}
.wrapper iron-list {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.group {
float: left;
}
</style>
</head>
<body unresolved>
<template is="dom-bind">
<h1>Physical count</h1>
<p>In red you can see the last physical count values</p>
<div class="group">
<p>100 items, 50px tall</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list1" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]"><span>[[index]]</span> height: <span>[[item]]</span>
<div>
<paper-button raised>Test</paper-button>
<paper-button raised>Test</paper-button>
<paper-button raised>Test</paper-button>
<paper-button raised>Test</paper-button>
</div>
</div>
</template>
</iron-list>
</div>
</div>
<!--
<div class="group">
<p>100 items, 300px tall</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list2" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>1000 items, 2px tall</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list3" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>First two items: 2px tall, next 100 items are 300px tall</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list4" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>100 items, 600px tall</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list5" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>1 item that is 2px tall, <br /> and then add 100 items async with different heights </p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list6" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>200 items with random heights</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list7" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div>
<div class="group">
<p>200 items async with random heights</p>
<div class="wrapper" style="width: 300px; height: 300px;">
<iron-list id="list8" as="item">
<template>
<div class="item" style$="[[_getStyle(item)]]">
<span>[[index]]</span> height: <span>[[item]]</span>
</div>
</template>
</iron-list>
</div>
</div> -->
</template>
<script>
HTMLImports.whenReady(function() {
function observePhysicalCount(list) {
var div = document.createElement('div');
var stats = document.createElement('div');
var values = [];
var timer;
div.classList.add('count');
stats.classList.add('stats');
Object.observe(list, function(changes) {
var physicalCount = list._physicalCount;
changes.forEach(function(change) {
if (change.name === '_physicalCount') {
values.pop();
values.push(change.oldValue);
values.push(list._physicalCount);
div.innerText = values.join(' -> ');
} else if (change.name === '_lastPage') {
if (list._lastPage === 0) {
timer = Date.now();
} else if (list._lastPage === 1) {
stats.innerText = 'First paint: ' + (Date.now() - timer) + 'ms';
} else if (list._lastPage === list._maxPages) {
stats.innerText = stats.innerText + ' total: ' + (Date.now() - timer) + 'ms';
}
}
});
});
values.push(list._physicalCount);
div.innerText = list._physicalCount;
stats.innerText = 'Waiting for stats...';
Polymer.dom(list.parentNode).appendChild(div);
Polymer.dom(list.parentNode).appendChild(stats);
}
function arrayFill(size, value) {
return (new Array(size)).fill(value, 0, size);
}
function randomArrayFill(size, min, max) {
var a = [];
while (a.length < size) {
a.push(parseInt(Math.random() * (max-min+1)) + min);
}
return a;
}
function asyncJob(fn) {
if (fn()) {
setTimeout(asyncJob.bind(null, fn), 1);
}
}
document.querySelector('template[is=dom-bind]')._getStyle = function(item) {
return 'height:' + item + 'px; ';
};
setTimeout(function() {
var list1 = document.querySelector('#list1');
var list2 = document.querySelector('#list2');
var list3 = document.querySelector('#list3');
var list4 = document.querySelector('#list4');
var list5 = document.querySelector('#list5');
var list6 = document.querySelector('#list6');
var list7 = document.querySelector('#list7');
var list8 = document.querySelector('#list8');
var items = randomArrayFill(100, 1, 200);
list1.items = arrayFill(100, 50);
observePhysicalCount(list1);
// list2.items = arrayFill(100, 300);
// list3.items = arrayFill(1000, 2);
// list4.items = arrayFill(2, 2).concat(arrayFill(100, 300));
// list5.items = arrayFill(100, 600);
// list6.items = [2];
// setTimeout(function() {
// list6.push.apply(list6,
// ['items'].concat([512, 256, 128, 64, 16, 16, 16, 16, 16, 16, 8, 4])
// );
// }, 100);
// list7.items = randomArrayFill(100, 1, 200);
// list8.items = [];
// asyncJob(function() {
// list8.push('items', items.pop());
// return items.length > 0;
// });
// observePhysicalCount(list2);
// observePhysicalCount(list3);
// observePhysicalCount(list4);
// observePhysicalCount(list5);
// observePhysicalCount(list6);
// observePhysicalCount(list7);
// observePhysicalCount(list8);
}, 0);
});
</script>
</body>
</html>