-
Notifications
You must be signed in to change notification settings - Fork 46
/
px-vis-scheduler.html
338 lines (274 loc) · 69.7 KB
/
px-vis-scheduler.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!--
Copyright (c) 2018, General Electric
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.
-->
<link rel="import" href="px-vis-debugger.html"/>
<script>
(function(){
if(typeof Px === 'undefined') {
Px = {};
}
Px.vis = Px.vis || {};
if(!Px.vis.scheduler) {
window.dispatchEvent(new CustomEvent('px-vis-worker-init'));
//get number of cores
var scheduler = {},
threadCount = Px.vis.maxWorkerCount || navigator.hardwareConcurrency || 4,
initCounter = 0,
processDone,
startWork;
if(Px.vis.workerUrl) {
console.warn('Px.vis.workerUrl is no longer needed. Worker files are now loaded via a Blob. You may remove Px.vis.workerUrl and do not need to include the worker files in your build anymore.');
console.warn('### NOTE: If you are running custom scripts via registerCustomScript, you MUST use an absolute path. Relative paths no longer work with the blob.')
}
//!!!!!!!!DO NOT DELETE THE COMMENT BELOW, INSERTION POINT USED USED BY GULP FOR THE BLOB!!!!!!!!!
//start of blob
var blob = {"script":"!function(n,t){\"object\"==typeof exports&&\"undefined\"!=typeof module?t(exports,require(\"d3-color\")):\"function\"==typeof define&&define.amd?define([\"exports\",\"d3-color\"],t):t(n.d3={},n.d3Color)}(this,function(n,t){\"use strict\";var e=function(n,t){return n<t?-1:n>t?1:n>=t?0:NaN},r=function(n){var t;return 1===n.length&&(t=n,n=function(n,r){return e(t(n),r)}),{left:function(t,e,r,u){for(null==r&&(r=0),null==u&&(u=t.length);r<u;){var i=r+u>>>1;n(t[i],e)<0?r=i+1:u=i}return r},right:function(t,e,r,u){for(null==r&&(r=0),null==u&&(u=t.length);r<u;){var i=r+u>>>1;n(t[i],e)>0?u=i:r=i+1}return r}}};var u=r(e).right,i=function(n,t,e){n=+n,t=+t,e=(u=arguments.length)<2?(t=n,n=0,1):u<3?1:+e;for(var r=-1,u=0|Math.max(0,Math.ceil((t-n)/e)),i=new Array(u);++r<u;)i[r]=n+r*e;return i},o=Math.sqrt(50),a=Math.sqrt(10),c=Math.sqrt(2),f=function(n,t,e){var r,u,i,o,a=-1;if(e=+e,(n=+n)===(t=+t)&&e>0)return[n];if((r=t<n)&&(u=n,n=t,t=u),0===(o=l(n,t,e))||!isFinite(o))return[];if(o>0)for(n=Math.ceil(n/o),t=Math.floor(t/o),i=new Array(u=Math.ceil(t-n+1));++a<u;)i[a]=(n+a)*o;else for(n=Math.floor(n*o),t=Math.ceil(t*o),i=new Array(u=Math.ceil(n-t+1));++a<u;)i[a]=(n-a)/o;return r&&i.reverse(),i};function l(n,t,e){var r=(t-n)/Math.max(0,e),u=Math.floor(Math.log(r)/Math.LN10),i=r/Math.pow(10,u);return u>=0?(i>=o?10:i>=a?5:i>=c?2:1)*Math.pow(10,u):-Math.pow(10,-u)/(i>=o?10:i>=a?5:i>=c?2:1)}function s(n,t,e){var r=Math.abs(t-n)/Math.max(0,e),u=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),i=r/u;return i>=o?u*=10:i>=a?u*=5:i>=c&&(u*=2),t<n?-u:u}function h(){}function g(n,t){var e=new h;if(n instanceof h)n.each(function(n,t){e.set(t,n)});else if(Array.isArray(n)){var r,u=-1,i=n.length;if(null==t)for(;++u<i;)e.set(u,n[u]);else for(;++u<i;)e.set(t(r=n[u],u,n),r)}else if(n)for(var o in n)e.set(o,n[o]);return e}function v(){}h.prototype=g.prototype={constructor:h,has:function(n){return\"$\"+n in this},get:function(n){return this[\"$\"+n]},set:function(n,t){return this[\"$\"+n]=t,this},remove:function(n){var t=\"$\"+n;return t in this&&delete this[t]},clear:function(){for(var n in this)\"$\"===n[0]&&delete this[n]},keys:function(){var n=[];for(var t in this)\"$\"===t[0]&&n.push(t.slice(1));return n},values:function(){var n=[];for(var t in this)\"$\"===t[0]&&n.push(this[t]);return n},entries:function(){var n=[];for(var t in this)\"$\"===t[0]&&n.push({key:t.slice(1),value:this[t]});return n},size:function(){var n=0;for(var t in this)\"$\"===t[0]&&++n;return n},empty:function(){for(var n in this)if(\"$\"===n[0])return!1;return!0},each:function(n){for(var t in this)\"$\"===t[0]&&n(this[t],t.slice(1),this)}};var d=g.prototype;v.prototype=function(n,t){var e=new v;if(n instanceof v)n.each(function(n){e.add(n)});else if(n){var r=-1,u=n.length;if(null==t)for(;++r<u;)e.add(n[r]);else for(;++r<u;)e.add(t(n[r],r,n))}return e}.prototype={constructor:v,has:d.has,add:function(n){return this[\"$\"+(n+=\"\")]=n,this},remove:d.remove,clear:d.clear,values:d.keys,size:d.size,empty:d.empty,each:d.each};var M=Array.prototype,y=M.map,p=M.slice,m={name:\"implicit\"};function x(){var n,t,e=function n(t){var e=g(),r=[],u=m;function i(n){var i=n+\"\",o=e.get(i);if(!o){if(u!==m)return u;e.set(i,o=r.push(n))}return t[(o-1)%t.length]}return t=null==t?[]:p.call(t),i.domain=function(n){if(!arguments.length)return r.slice();r=[],e=g();for(var t,u,o=-1,a=n.length;++o<a;)e.has(u=(t=n[o])+\"\")||e.set(u,r.push(t));return i},i.range=function(n){return arguments.length?(t=p.call(n),i):t.slice()},i.unknown=function(n){return arguments.length?(u=n,i):u},i.copy=function(){return n().domain(r).range(t).unknown(u)},i}().unknown(void 0),r=e.domain,u=e.range,o=[0,1],a=!1,c=0,f=0,l=.5;function s(){var e=r().length,s=o[1]<o[0],h=o[s-0],g=o[1-s];n=(g-h)/Math.max(1,e-c+2*f),a&&(n=Math.floor(n)),h+=(g-h-n*(e-c))*l,t=n*(1-c),a&&(h=Math.round(h),t=Math.round(t));var v=i(e).map(function(t){return h+n*t});return u(s?v.reverse():v)}return delete e.unknown,e.domain=function(n){return arguments.length?(r(n),s()):r()},e.range=function(n){return arguments.length?(o=[+n[0],+n[1]],s()):o.slice()},e.rangeRound=function(n){return o=[+n[0],+n[1]],a=!0,s()},e.bandwidth=function(){return t},e.step=function(){return n},e.round=function(n){return arguments.length?(a=!!n,s()):a},e.padding=function(n){return arguments.length?(c=f=Math.max(0,Math.min(1,n)),s()):c},e.paddingInner=function(n){return arguments.length?(c=Math.max(0,Math.min(1,n)),s()):c},e.paddingOuter=function(n){return arguments.length?(f=Math.max(0,Math.min(1,n)),s()):f},e.align=function(n){return arguments.length?(l=Math.max(0,Math.min(1,n)),s()):l},e.copy=function(){return x().domain(r()).range(o).round(a).paddingInner(c).paddingOuter(f).align(l)},s()}var w=function(n){return function(){return n}};function T(n){return 1==(n=+n)?_:function(t,e){return e-t?(r=t,u=e,i=n,r=Math.pow(r,i),u=Math.pow(u,i)-r,i=1/i,function(n){return Math.pow(r+n*u,i)}):w(isNaN(t)?e:t);var r,u,i}}function _(n,t){var e,r,u=t-n;return u?(e=n,r=u,function(n){return e+n*r}):w(isNaN(n)?t:n)}var C=function n(e){var r=T(e);function u(n,e){var u=r((n=t.rgb(n)).r,(e=t.rgb(e)).r),i=r(n.g,e.g),o=r(n.b,e.b),a=_(n.opacity,e.opacity);return function(t){return n.r=u(t),n.g=i(t),n.b=o(t),n.opacity=a(t),n+\"\"}}return u.gamma=n,u}(1),U=function(n,t){return t-=n=+n,function(e){return n+t*e}},D=/[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,b=new RegExp(D.source,\"g\");var A=function(n,e){var r,u=typeof e;return null==e||\"boolean\"===u?w(e):(\"number\"===u?U:\"string\"===u?(r=t.color(e))?(e=r,C):function(n,t){var e,r,u,i,o,a=D.lastIndex=b.lastIndex=0,c=-1,f=[],l=[];for(n+=\"\",t+=\"\";(e=D.exec(n))&&(r=b.exec(t));)(u=r.index)>a&&(u=t.slice(a,u),f[c]?f[c]+=u:f[++c]=u),(e=e[0])===(r=r[0])?f[c]?f[c]+=r:f[++c]=r:(f[++c]=null,l.push({i:c,x:U(e,r)})),a=b.lastIndex;return a<t.length&&(u=t.slice(a),f[c]?f[c]+=u:f[++c]=u),f.length<2?l[0]?(o=l[0].x,function(n){return o(n)+\"\"}):(i=t,function(){return i}):(t=l.length,function(n){for(var e,r=0;r<t;++r)f[(e=l[r]).i]=e.x(n);return f.join(\"\")})}:e instanceof t.color?C:e instanceof Date?function(n,t){var e=new Date;return t-=n=+n,function(r){return e.setTime(n+t*r),e}}:Array.isArray(e)?function(n,t){var e,r=t?t.length:0,u=n?Math.min(r,n.length):0,i=new Array(u),o=new Array(r);for(e=0;e<u;++e)i[e]=A(n[e],t[e]);for(;e<r;++e)o[e]=t[e];return function(n){for(e=0;e<u;++e)o[e]=i[e](n);return o}}:\"function\"!=typeof e.valueOf&&\"function\"!=typeof e.toString||isNaN(e)?function(n,t){var e,r={},u={};null!==n&&\"object\"==typeof n||(n={}),null!==t&&\"object\"==typeof t||(t={});for(e in t)e in n?r[e]=A(n[e],t[e]):u[e]=t[e];return function(n){for(e in r)u[e]=r[e](n);return u}}:U)(n,e)},N=function(n,t){return t-=n=+n,function(e){return Math.round(n+t*e)}},F=(Math.PI,Math.SQRT2,new Date),S=new Date;function Y(n,t,e,r){function u(t){return n(t=new Date(+t)),t}return u.floor=u,u.ceil=function(e){return n(e=new Date(e-1)),t(e,1),n(e),e},u.round=function(n){var t=u(n),e=u.ceil(n);return n-t<e-n?t:e},u.offset=function(n,e){return t(n=new Date(+n),null==e?1:Math.floor(e)),n},u.range=function(e,r,i){var o,a=[];if(e=u.ceil(e),i=null==i?1:Math.floor(i),!(e<r&&i>0))return a;do{a.push(o=new Date(+e)),t(e,i),n(e)}while(o<e&&e<r);return a},u.filter=function(e){return Y(function(t){if(t>=t)for(;n(t),!e(t);)t.setTime(t-1)},function(n,r){if(n>=n)if(r<0)for(;++r<=0;)for(;t(n,-1),!e(n););else for(;--r>=0;)for(;t(n,1),!e(n););})},e&&(u.count=function(t,r){return F.setTime(+t),S.setTime(+r),n(F),n(S),Math.floor(e(F,S))},u.every=function(n){return n=Math.floor(n),isFinite(n)&&n>0?n>1?u.filter(r?function(t){return r(t)%n==0}:function(t){return u.count(0,t)%n==0}):u:null}),u}var H=Y(function(){},function(n,t){n.setTime(+n+t)},function(n,t){return t-n});H.every=function(n){return n=Math.floor(n),isFinite(n)&&n>0?n>1?Y(function(t){t.setTime(Math.floor(t/n)*n)},function(t,e){t.setTime(+t+e*n)},function(t,e){return(e-t)/n}):H:null};var k=6e4,L=6048e5,$=Y(function(n){n.setTime(1e3*Math.floor(n/1e3))},function(n,t){n.setTime(+n+1e3*t)},function(n,t){return(t-n)/1e3},function(n){return n.getUTCSeconds()}),j=Y(function(n){n.setTime(Math.floor(n/k)*k)},function(n,t){n.setTime(+n+t*k)},function(n,t){return(t-n)/k},function(n){return n.getMinutes()}),O=Y(function(n){var t=n.getTimezoneOffset()*k%36e5;t<0&&(t+=36e5),n.setTime(36e5*Math.floor((+n-t)/36e5)+t)},function(n,t){n.setTime(+n+36e5*t)},function(n,t){return(t-n)/36e5},function(n){return n.getHours()}),z=Y(function(n){n.setHours(0,0,0,0)},function(n,t){n.setDate(n.getDate()+t)},function(n,t){return(t-n-(t.getTimezoneOffset()-n.getTimezoneOffset())*k)/864e5},function(n){return n.getDate()-1});function I(n){return Y(function(t){t.setDate(t.getDate()-(t.getDay()+7-n)%7),t.setHours(0,0,0,0)},function(n,t){n.setDate(n.getDate()+7*t)},function(n,t){return(t-n-(t.getTimezoneOffset()-n.getTimezoneOffset())*k)/L})}var Z=I(0),P=I(1),E=(I(2),I(3),I(4)),W=(I(5),I(6),Y(function(n){n.setDate(1),n.setHours(0,0,0,0)},function(n,t){n.setMonth(n.getMonth()+t)},function(n,t){return t.getMonth()-n.getMonth()+12*(t.getFullYear()-n.getFullYear())},function(n){return n.getMonth()})),V=Y(function(n){n.setMonth(0,1),n.setHours(0,0,0,0)},function(n,t){n.setFullYear(n.getFullYear()+t)},function(n,t){return t.getFullYear()-n.getFullYear()},function(n){return n.getFullYear()});V.every=function(n){return isFinite(n=Math.floor(n))&&n>0?Y(function(t){t.setFullYear(Math.floor(t.getFullYear()/n)*n),t.setMonth(0,1),t.setHours(0,0,0,0)},function(t,e){t.setFullYear(t.getFullYear()+e*n)}):null};var Q=Y(function(n){n.setUTCSeconds(0,0)},function(n,t){n.setTime(+n+t*k)},function(n,t){return(t-n)/k},function(n){return n.getUTCMinutes()}),X=Y(function(n){n.setUTCMinutes(0,0,0)},function(n,t){n.setTime(+n+36e5*t)},function(n,t){return(t-n)/36e5},function(n){return n.getUTCHours()}),q=Y(function(n){n.setUTCHours(0,0,0,0)},function(n,t){n.setUTCDate(n.getUTCDate()+t)},function(n,t){return(t-n)/864e5},function(n){return n.getUTCDate()-1});function J(n){return Y(function(t){t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-n)%7),t.setUTCHours(0,0,0,0)},function(n,t){n.setUTCDate(n.getUTCDate()+7*t)},function(n,t){return(t-n)/L})}var B=J(0),R=J(1),G=(J(2),J(3),J(4)),K=(J(5),J(6),Y(function(n){n.setUTCDate(1),n.setUTCHours(0,0,0,0)},function(n,t){n.setUTCMonth(n.getUTCMonth()+t)},function(n,t){return t.getUTCMonth()-n.getUTCMonth()+12*(t.getUTCFullYear()-n.getUTCFullYear())},function(n){return n.getUTCMonth()})),nn=Y(function(n){n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},function(n,t){n.setUTCFullYear(n.getUTCFullYear()+t)},function(n,t){return t.getUTCFullYear()-n.getUTCFullYear()},function(n){return n.getUTCFullYear()});function tn(n){if(0<=n.y&&n.y<100){var t=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return t.setFullYear(n.y),t}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function en(n){if(0<=n.y&&n.y<100){var t=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return t.setUTCFullYear(n.y),t}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function rn(n){return{y:n,m:0,d:1,H:0,M:0,S:0,L:0}}nn.every=function(n){return isFinite(n=Math.floor(n))&&n>0?Y(function(t){t.setUTCFullYear(Math.floor(t.getUTCFullYear()/n)*n),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e*n)}):null};var un,on,an,cn,fn={\"-\":\"\",_:\" \",0:\"0\"},ln=/^\\s*\\d+/,sn=/^%/,hn=/[\\\\^$*+?|[\\]().{}]/g;function gn(n,t,e){var r=n<0?\"-\":\"\",u=(r?-n:n)+\"\",i=u.length;return r+(i<e?new Array(e-i+1).join(t)+u:u)}function vn(n){return n.replace(hn,\"\\\\$&\")}function dn(n){return new RegExp(\"^(?:\"+n.map(vn).join(\"|\")+\")\",\"i\")}function Mn(n){for(var t={},e=-1,r=n.length;++e<r;)t[n[e].toLowerCase()]=e;return t}function yn(n,t,e){var r=ln.exec(t.slice(e,e+1));return r?(n.w=+r[0],e+r[0].length):-1}function pn(n,t,e){var r=ln.exec(t.slice(e,e+1));return r?(n.u=+r[0],e+r[0].length):-1}function mn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.U=+r[0],e+r[0].length):-1}function xn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.V=+r[0],e+r[0].length):-1}function wn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.W=+r[0],e+r[0].length):-1}function Tn(n,t,e){var r=ln.exec(t.slice(e,e+4));return r?(n.y=+r[0],e+r[0].length):-1}function _n(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.y=+r[0]+(+r[0]>68?1900:2e3),e+r[0].length):-1}function Cn(n,t,e){var r=/^(Z)|([+-]\\d\\d)(?::?(\\d\\d))?/.exec(t.slice(e,e+6));return r?(n.Z=r[1]?0:-(r[2]+(r[3]||\"00\")),e+r[0].length):-1}function Un(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.m=r[0]-1,e+r[0].length):-1}function Dn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.d=+r[0],e+r[0].length):-1}function bn(n,t,e){var r=ln.exec(t.slice(e,e+3));return r?(n.m=0,n.d=+r[0],e+r[0].length):-1}function An(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.H=+r[0],e+r[0].length):-1}function Nn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.M=+r[0],e+r[0].length):-1}function Fn(n,t,e){var r=ln.exec(t.slice(e,e+2));return r?(n.S=+r[0],e+r[0].length):-1}function Sn(n,t,e){var r=ln.exec(t.slice(e,e+3));return r?(n.L=+r[0],e+r[0].length):-1}function Yn(n,t,e){var r=ln.exec(t.slice(e,e+6));return r?(n.L=Math.floor(r[0]/1e3),e+r[0].length):-1}function Hn(n,t,e){var r=sn.exec(t.slice(e,e+1));return r?e+r[0].length:-1}function kn(n,t,e){var r=ln.exec(t.slice(e));return r?(n.Q=+r[0],e+r[0].length):-1}function Ln(n,t,e){var r=ln.exec(t.slice(e));return r?(n.Q=1e3*+r[0],e+r[0].length):-1}function $n(n,t){return gn(n.getDate(),t,2)}function jn(n,t){return gn(n.getHours(),t,2)}function On(n,t){return gn(n.getHours()%12||12,t,2)}function zn(n,t){return gn(1+z.count(V(n),n),t,3)}function In(n,t){return gn(n.getMilliseconds(),t,3)}function Zn(n,t){return In(n,t)+\"000\"}function Pn(n,t){return gn(n.getMonth()+1,t,2)}function En(n,t){return gn(n.getMinutes(),t,2)}function Wn(n,t){return gn(n.getSeconds(),t,2)}function Vn(n){var t=n.getDay();return 0===t?7:t}function Qn(n,t){return gn(Z.count(V(n),n),t,2)}function Xn(n,t){var e=n.getDay();return n=e>=4||0===e?E(n):E.ceil(n),gn(E.count(V(n),n)+(4===V(n).getDay()),t,2)}function qn(n){return n.getDay()}function Jn(n,t){return gn(P.count(V(n),n),t,2)}function Bn(n,t){return gn(n.getFullYear()%100,t,2)}function Rn(n,t){return gn(n.getFullYear()%1e4,t,4)}function Gn(n){var t=n.getTimezoneOffset();return(t>0?\"-\":(t*=-1,\"+\"))+gn(t/60|0,\"0\",2)+gn(t%60,\"0\",2)}function Kn(n,t){return gn(n.getUTCDate(),t,2)}function nt(n,t){return gn(n.getUTCHours(),t,2)}function tt(n,t){return gn(n.getUTCHours()%12||12,t,2)}function et(n,t){return gn(1+q.count(nn(n),n),t,3)}function rt(n,t){return gn(n.getUTCMilliseconds(),t,3)}function ut(n,t){return rt(n,t)+\"000\"}function it(n,t){return gn(n.getUTCMonth()+1,t,2)}function ot(n,t){return gn(n.getUTCMinutes(),t,2)}function at(n,t){return gn(n.getUTCSeconds(),t,2)}function ct(n){var t=n.getUTCDay();return 0===t?7:t}function ft(n,t){return gn(B.count(nn(n),n),t,2)}function lt(n,t){var e=n.getUTCDay();return n=e>=4||0===e?G(n):G.ceil(n),gn(G.count(nn(n),n)+(4===nn(n).getUTCDay()),t,2)}function st(n){return n.getUTCDay()}function ht(n,t){return gn(R.count(nn(n),n),t,2)}function gt(n,t){return gn(n.getUTCFullYear()%100,t,2)}function vt(n,t){return gn(n.getUTCFullYear()%1e4,t,4)}function dt(){return\"+0000\"}function Mt(){return\"%\"}function yt(n){return+n}function pt(n){return Math.floor(+n/1e3)}un=function(n){var t=n.dateTime,e=n.date,r=n.time,u=n.periods,i=n.days,o=n.shortDays,a=n.months,c=n.shortMonths,f=dn(u),l=Mn(u),s=dn(i),h=Mn(i),g=dn(o),v=Mn(o),d=dn(a),M=Mn(a),y=dn(c),p=Mn(c),m={a:function(n){return o[n.getDay()]},A:function(n){return i[n.getDay()]},b:function(n){return c[n.getMonth()]},B:function(n){return a[n.getMonth()]},c:null,d:$n,e:$n,f:Zn,H:jn,I:On,j:zn,L:In,m:Pn,M:En,p:function(n){return u[+(n.getHours()>=12)]},Q:yt,s:pt,S:Wn,u:Vn,U:Qn,V:Xn,w:qn,W:Jn,x:null,X:null,y:Bn,Y:Rn,Z:Gn,\"%\":Mt},x={a:function(n){return o[n.getUTCDay()]},A:function(n){return i[n.getUTCDay()]},b:function(n){return c[n.getUTCMonth()]},B:function(n){return a[n.getUTCMonth()]},c:null,d:Kn,e:Kn,f:ut,H:nt,I:tt,j:et,L:rt,m:it,M:ot,p:function(n){return u[+(n.getUTCHours()>=12)]},Q:yt,s:pt,S:at,u:ct,U:ft,V:lt,w:st,W:ht,x:null,X:null,y:gt,Y:vt,Z:dt,\"%\":Mt},w={a:function(n,t,e){var r=g.exec(t.slice(e));return r?(n.w=v[r[0].toLowerCase()],e+r[0].length):-1},A:function(n,t,e){var r=s.exec(t.slice(e));return r?(n.w=h[r[0].toLowerCase()],e+r[0].length):-1},b:function(n,t,e){var r=y.exec(t.slice(e));return r?(n.m=p[r[0].toLowerCase()],e+r[0].length):-1},B:function(n,t,e){var r=d.exec(t.slice(e));return r?(n.m=M[r[0].toLowerCase()],e+r[0].length):-1},c:function(n,e,r){return C(n,t,e,r)},d:Dn,e:Dn,f:Yn,H:An,I:An,j:bn,L:Sn,m:Un,M:Nn,p:function(n,t,e){var r=f.exec(t.slice(e));return r?(n.p=l[r[0].toLowerCase()],e+r[0].length):-1},Q:kn,s:Ln,S:Fn,u:pn,U:mn,V:xn,w:yn,W:wn,x:function(n,t,r){return C(n,e,t,r)},X:function(n,t,e){return C(n,r,t,e)},y:_n,Y:Tn,Z:Cn,\"%\":Hn};function T(n,t){return function(e){var r,u,i,o=[],a=-1,c=0,f=n.length;for(e instanceof Date||(e=new Date(+e));++a<f;)37===n.charCodeAt(a)&&(o.push(n.slice(c,a)),null!=(u=fn[r=n.charAt(++a)])?r=n.charAt(++a):u=\"e\"===r?\" \":\"0\",(i=t[r])&&(r=i(e,u)),o.push(r),c=a+1);return o.push(n.slice(c,a)),o.join(\"\")}}function _(n,t){return function(e){var r,u,i=rn(1900);if(C(i,n,e+=\"\",0)!=e.length)return null;if(\"Q\"in i)return new Date(i.Q);if(\"p\"in i&&(i.H=i.H%12+12*i.p),\"V\"in i){if(i.V<1||i.V>53)return null;\"w\"in i||(i.w=1),\"Z\"in i?(r=(u=(r=en(rn(i.y))).getUTCDay())>4||0===u?R.ceil(r):R(r),r=q.offset(r,7*(i.V-1)),i.y=r.getUTCFullYear(),i.m=r.getUTCMonth(),i.d=r.getUTCDate()+(i.w+6)%7):(r=(u=(r=t(rn(i.y))).getDay())>4||0===u?P.ceil(r):P(r),r=z.offset(r,7*(i.V-1)),i.y=r.getFullYear(),i.m=r.getMonth(),i.d=r.getDate()+(i.w+6)%7)}else(\"W\"in i||\"U\"in i)&&(\"w\"in i||(i.w=\"u\"in i?i.u%7:\"W\"in i?1:0),u=\"Z\"in i?en(rn(i.y)).getUTCDay():t(rn(i.y)).getDay(),i.m=0,i.d=\"W\"in i?(i.w+6)%7+7*i.W-(u+5)%7:i.w+7*i.U-(u+6)%7);return\"Z\"in i?(i.H+=i.Z/100|0,i.M+=i.Z%100,en(i)):t(i)}}function C(n,t,e,r){for(var u,i,o=0,a=t.length,c=e.length;o<a;){if(r>=c)return-1;if(37===(u=t.charCodeAt(o++))){if(u=t.charAt(o++),!(i=w[u in fn?t.charAt(o++):u])||(r=i(n,e,r))<0)return-1}else if(u!=e.charCodeAt(r++))return-1}return r}return m.x=T(e,m),m.X=T(r,m),m.c=T(t,m),x.x=T(e,x),x.X=T(r,x),x.c=T(t,x),{format:function(n){var t=T(n+=\"\",m);return t.toString=function(){return n},t},parse:function(n){var t=_(n+=\"\",tn);return t.toString=function(){return n},t},utcFormat:function(n){var t=T(n+=\"\",x);return t.toString=function(){return n},t},utcParse:function(n){var t=_(n,en);return t.toString=function(){return n},t}}}({dateTime:\"%x, %X\",date:\"%-m/%-d/%Y\",time:\"%-I:%M:%S %p\",periods:[\"AM\",\"PM\"],days:[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"],shortDays:[\"Sun\",\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\"],months:[\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"],shortMonths:[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"]}),on=un.format,un.parse,an=un.utcFormat,cn=un.utcParse;var mt=\"%Y-%m-%dT%H:%M:%S.%LZ\";Date.prototype.toISOString||an(mt);+new Date(\"2000-01-01T00:00:00.000Z\")||cn(mt);var xt=function(n){return function(){return n}},wt=function(n){return+n},Tt=[0,1];function _t(n,t){return(t-=n=+n)?function(e){return(e-n)/t}:xt(t)}function Ct(n,t,e,r){var u=n[0],i=n[1],o=t[0],a=t[1];return i<u?(u=e(i,u),o=r(a,o)):(u=e(u,i),o=r(o,a)),function(n){return o(u(n))}}function Ut(n,t,e,r){var i=Math.min(n.length,t.length)-1,o=new Array(i),a=new Array(i),c=-1;for(n[i]<n[0]&&(n=n.slice().reverse(),t=t.slice().reverse());++c<i;)o[c]=e(n[c],n[c+1]),a[c]=r(t[c],t[c+1]);return function(t){var e=u(n,t,1,i)-1;return a[e](o[e](t))}}function Dt(n,t){return t.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp())}function bt(n,t){var e,r,u,i=Tt,o=Tt,a=A,c=!1;function f(){return e=Math.min(i.length,o.length)>2?Ut:Ct,r=u=null,l}function l(t){return(r||(r=e(i,o,c?(u=n,function(n,t){var e=u(n=+n,t=+t);return function(r){return r<=n?0:r>=t?1:e(r)}}):n,a)))(+t);var u}return l.invert=function(n){return(u||(u=e(o,i,_t,c?(r=t,function(n,t){var e=r(n=+n,t=+t);return function(r){return r<=0?n:r>=1?t:e(r)}}):t)))(+n);var r},l.domain=function(n){return arguments.length?(i=y.call(n,wt),f()):i.slice()},l.range=function(n){return arguments.length?(o=p.call(n),f()):o.slice()},l.rangeRound=function(n){return o=p.call(n),a=N,f()},l.clamp=function(n){return arguments.length?(c=!!n,f()):c},l.interpolate=function(n){return arguments.length?(a=n,f()):a},f()}var At=function(n,t){var e,r=0,u=(n=n.slice()).length-1,i=n[r],o=n[u];return o<i&&(e=r,r=u,u=e,e=i,i=o,o=e),n[r]=t.floor(i),n[u]=t.ceil(o),n},Nt=1e3,Ft=60*Nt,St=60*Ft,Yt=24*St,Ht=7*Yt,kt=30*Yt,Lt=365*Yt;function $t(n){return new Date(n)}function jt(n){return n instanceof Date?+n:+new Date(+n)}function Ot(n,t,e,u,i,o,a,c,f){var l=bt(_t,U),h=l.invert,g=l.domain,v=f(\".%L\"),d=f(\":%S\"),M=f(\"%I:%M\"),p=f(\"%I %p\"),m=f(\"%a %d\"),x=f(\"%b %d\"),w=f(\"%B\"),T=f(\"%Y\"),_=[[a,1,Nt],[a,5,5*Nt],[a,15,15*Nt],[a,30,30*Nt],[o,1,Ft],[o,5,5*Ft],[o,15,15*Ft],[o,30,30*Ft],[i,1,St],[i,3,3*St],[i,6,6*St],[i,12,12*St],[u,1,Yt],[u,2,2*Yt],[e,1,Ht],[t,1,kt],[t,3,3*kt],[n,1,Lt]];function C(r){return(a(r)<r?v:o(r)<r?d:i(r)<r?M:u(r)<r?p:t(r)<r?e(r)<r?m:x:n(r)<r?w:T)(r)}function D(t,e,u,i){if(null==t&&(t=10),\"number\"==typeof t){var o=Math.abs(u-e)/t,a=r(function(n){return n[2]}).right(_,o);a===_.length?(i=s(e/Lt,u/Lt,t),t=n):a?(i=(a=_[o/_[a-1][2]<_[a][2]/o?a-1:a])[1],t=a[0]):(i=Math.max(s(e,u,t),1),t=c)}return null==i?t:t.every(i)}return l.invert=function(n){return new Date(h(n))},l.domain=function(n){return arguments.length?g(y.call(n,jt)):g().map($t)},l.ticks=function(n,t){var e,r=g(),u=r[0],i=r[r.length-1],o=i<u;return o&&(e=u,u=i,i=e),e=(e=D(n,u,i,t))?e.range(u,i+1):[],o?e.reverse():e},l.tickFormat=function(n,t){return null==t?C:f(t)},l.nice=function(n,t){var e=g();return(n=D(n,e[0],e[e.length-1],t))?g(At(e,n)):l},l.copy=function(){return Dt(l,Ot(n,t,e,u,i,o,a,c,f))},l}var zt,It=function(n,t){if((e=(n=t?n.toExponential(t-1):n.toExponential()).indexOf(\"e\"))<0)return null;var e,r=n.slice(0,e);return[r.length>1?r[0]+r.slice(2):r,+n.slice(e+1)]},Zt=function(n){return(n=It(Math.abs(n)))?n[1]:NaN},Pt=function(n,t){var e=It(n,t);if(!e)return n+\"\";var r=e[0],u=e[1];return u<0?\"0.\"+new Array(-u).join(\"0\")+r:r.length>u+1?r.slice(0,u+1)+\".\"+r.slice(u+1):r+new Array(u-r.length+2).join(\"0\")},Et={\"\":function(n,t){n=n.toPrecision(t);n:for(var e,r=n.length,u=1,i=-1;u<r;++u)switch(n[u]){case\".\":i=e=u;break;case\"0\":0===i&&(i=u),e=u;break;case\"e\":break n;default:i>0&&(i=0)}return i>0?n.slice(0,i)+n.slice(e+1):n},\"%\":function(n,t){return(100*n).toFixed(t)},b:function(n){return Math.round(n).toString(2)},c:function(n){return n+\"\"},d:function(n){return Math.round(n).toString(10)},e:function(n,t){return n.toExponential(t)},f:function(n,t){return n.toFixed(t)},g:function(n,t){return n.toPrecision(t)},o:function(n){return Math.round(n).toString(8)},p:function(n,t){return Pt(100*n,t)},r:Pt,s:function(n,t){var e=It(n,t);if(!e)return n+\"\";var r=e[0],u=e[1],i=u-(zt=3*Math.max(-8,Math.min(8,Math.floor(u/3))))+1,o=r.length;return i===o?r:i>o?r+new Array(i-o+1).join(\"0\"):i>0?r.slice(0,i)+\".\"+r.slice(i):\"0.\"+new Array(1-i).join(\"0\")+It(n,Math.max(0,t+i-1))[0]},X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}},Wt=/^(?:(.)?([<>=^]))?([+\\-\\( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?([a-z%])?$/i;function Vt(n){return new Qt(n)}function Qt(n){if(!(t=Wt.exec(n)))throw new Error(\"invalid format: \"+n);var t,e=t[1]||\" \",r=t[2]||\">\",u=t[3]||\"-\",i=t[4]||\"\",o=!!t[5],a=t[6]&&+t[6],c=!!t[7],f=t[8]&&+t[8].slice(1),l=t[9]||\"\";\"n\"===l?(c=!0,l=\"g\"):Et[l]||(l=\"\"),(o||\"0\"===e&&\"=\"===r)&&(o=!0,e=\"0\",r=\"=\"),this.fill=e,this.align=r,this.sign=u,this.symbol=i,this.zero=o,this.width=a,this.comma=c,this.precision=f,this.type=l}Vt.prototype=Qt.prototype,Qt.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?\"0\":\"\")+(null==this.width?\"\":Math.max(1,0|this.width))+(this.comma?\",\":\"\")+(null==this.precision?\"\":\".\"+Math.max(0,0|this.precision))+this.type};var Xt,qt,Jt,Bt=function(n){return n},Rt=[\"y\",\"z\",\"a\",\"f\",\"p\",\"n\",\"µ\",\"m\",\"\",\"k\",\"M\",\"G\",\"T\",\"P\",\"E\",\"Z\",\"Y\"];Xt=function(n){var t,e,r,u=n.grouping&&n.thousands?(e=n.grouping,r=n.thousands,function(n,t){for(var u=n.length,i=[],o=0,a=e[0],c=0;u>0&&a>0&&(c+a+1>t&&(a=Math.max(1,t-c)),i.push(n.substring(u-=a,u+a)),!((c+=a+1)>t));)a=e[o=(o+1)%e.length];return i.reverse().join(r)}):Bt,i=n.currency,o=n.decimal,a=n.numerals?(t=n.numerals,function(n){return n.replace(/[0-9]/g,function(n){return t[+n]})}):Bt,c=n.percent||\"%\";function f(n){var t=(n=Vt(n)).fill,e=n.align,r=n.sign,f=n.symbol,l=n.zero,s=n.width,h=n.comma,g=n.precision,v=n.type,d=\"$\"===f?i[0]:\"#\"===f&&/[boxX]/.test(v)?\"0\"+v.toLowerCase():\"\",M=\"$\"===f?i[1]:/[%p]/.test(v)?c:\"\",y=Et[v],p=!v||/[defgprs%]/.test(v);function m(n){var i,c,f,m=d,x=M;if(\"c\"===v)x=y(n)+x,n=\"\";else{var w=(n=+n)<0;if(n=y(Math.abs(n),g),w&&0==+n&&(w=!1),m=(w?\"(\"===r?r:\"-\":\"-\"===r||\"(\"===r?\"\":r)+m,x=(\"s\"===v?Rt[8+zt/3]:\"\")+x+(w&&\"(\"===r?\")\":\"\"),p)for(i=-1,c=n.length;++i<c;)if(48>(f=n.charCodeAt(i))||f>57){x=(46===f?o+n.slice(i+1):n.slice(i))+x,n=n.slice(0,i);break}}h&&!l&&(n=u(n,1/0));var T=m.length+n.length+x.length,_=T<s?new Array(s-T+1).join(t):\"\";switch(h&&l&&(n=u(_+n,_.length?s-x.length:1/0),_=\"\"),e){case\"<\":n=m+n+x+_;break;case\"=\":n=m+_+n+x;break;case\"^\":n=_.slice(0,T=_.length>>1)+m+n+x+_.slice(T);break;default:n=_+m+n+x}return a(n)}return g=null==g?v?6:12:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),m.toString=function(){return n+\"\"},m}return{format:f,formatPrefix:function(n,t){var e=f(((n=Vt(n)).type=\"f\",n)),r=3*Math.max(-8,Math.min(8,Math.floor(Zt(t)/3))),u=Math.pow(10,-r),i=Rt[8+r/3];return function(n){return e(u*n)+i}}}}({decimal:\".\",thousands:\",\",grouping:[3],currency:[\"$\",\"\"]}),qt=Xt.format,Jt=Xt.formatPrefix;var Gt=function(n,t,e){var r,u,i,o,a,c,f=n[0],l=n[n.length-1],h=s(f,l,null==t?10:t);switch((e=Vt(null==e?\",f\":e)).type){case\"s\":var g=Math.max(Math.abs(f),Math.abs(l));return null!=e.precision||isNaN((a=h,c=g,r=Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Zt(c)/3)))-Zt(Math.abs(a)))))||(e.precision=r),Jt(e,g);case\"\":case\"e\":case\"g\":case\"p\":case\"r\":null!=e.precision||isNaN((i=h,o=Math.max(Math.abs(f),Math.abs(l)),i=Math.abs(i),o=Math.abs(o)-i,r=Math.max(0,Zt(o)-Zt(i))+1))||(e.precision=r-(\"e\"===e.type));break;case\"f\":case\"%\":null!=e.precision||isNaN((u=h,r=Math.max(0,-Zt(Math.abs(u)))))||(e.precision=r-2*(\"%\"===e.type))}return qt(e)};function Kt(n,t){return(t=Math.log(t/n))?function(e){return Math.log(e/n)/t}:xt(t)}function ne(n,t){return n<0?function(e){return-Math.pow(-t,e)*Math.pow(-n,1-e)}:function(e){return Math.pow(t,e)*Math.pow(n,1-e)}}function te(n){return isFinite(n)?+(\"1e\"+n):n<0?0:n}function ee(n){return 10===n?te:n===Math.E?Math.exp:function(t){return Math.pow(n,t)}}function re(n){return n===Math.E?Math.log:10===n&&Math.log10||2===n&&Math.log2||(n=Math.log(n),function(t){return Math.log(t)/n})}function ue(n){return function(t){return-n(-t)}}function ie(n,t,e,r){if(isNaN(t)||isNaN(e))return n;var u,i,o,a,c,f,l,s,h,g=n._root,v={data:r},d=n._x0,M=n._y0,y=n._x1,p=n._y1;if(!g)return n._root=v,n;for(;g.length;)if((f=t>=(i=(d+y)/2))?d=i:y=i,(l=e>=(o=(M+p)/2))?M=o:p=o,u=g,!(g=g[s=l<<1|f]))return u[s]=v,n;if(a=+n._x.call(null,g.data),c=+n._y.call(null,g.data),t===a&&e===c)return v.next=g,u?u[s]=v:n._root=v,n;do{u=u?u[s]=new Array(4):n._root=new Array(4),(f=t>=(i=(d+y)/2))?d=i:y=i,(l=e>=(o=(M+p)/2))?M=o:p=o}while((s=l<<1|f)==(h=(c>=o)<<1|a>=i));return u[h]=g,u[s]=v,n}var oe=function(n,t,e,r,u){this.node=n,this.x0=t,this.y0=e,this.x1=r,this.y1=u};function ae(n){return n[0]}function ce(n){return n[1]}function fe(n,t,e){var r=new le(null==t?ae:t,null==e?ce:e,NaN,NaN,NaN,NaN);return null==n?r:r.addAll(n)}function le(n,t,e,r,u,i){this._x=n,this._y=t,this._x0=e,this._y0=r,this._x1=u,this._y1=i,this._root=void 0}function se(n){for(var t={data:n.data},e=t;n=n.next;)e=e.next={data:n.data};return t}var he=fe.prototype=le.prototype;he.copy=function(){var n,t,e=new le(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=se(r),e;for(n=[{source:r,target:e._root=new Array(4)}];r=n.pop();)for(var u=0;u<4;++u)(t=r.source[u])&&(t.length?n.push({source:t,target:r.target[u]=new Array(4)}):r.target[u]=se(t));return e},he.add=function(n){var t=+this._x.call(null,n),e=+this._y.call(null,n);return ie(this.cover(t,e),t,e,n)},he.addAll=function(n){var t,e,r,u,i=n.length,o=new Array(i),a=new Array(i),c=1/0,f=1/0,l=-1/0,s=-1/0;for(e=0;e<i;++e)isNaN(r=+this._x.call(null,t=n[e]))||isNaN(u=+this._y.call(null,t))||(o[e]=r,a[e]=u,r<c&&(c=r),r>l&&(l=r),u<f&&(f=u),u>s&&(s=u));for(l<c&&(c=this._x0,l=this._x1),s<f&&(f=this._y0,s=this._y1),this.cover(c,f).cover(l,s),e=0;e<i;++e)ie(this,o[e],a[e],n[e]);return this},he.cover=function(n,t){if(isNaN(n=+n)||isNaN(t=+t))return this;var e=this._x0,r=this._y0,u=this._x1,i=this._y1;if(isNaN(e))u=(e=Math.floor(n))+1,i=(r=Math.floor(t))+1;else{if(!(e>n||n>u||r>t||t>i))return this;var o,a,c=u-e,f=this._root;switch(a=(t<(r+i)/2)<<1|n<(e+u)/2){case 0:do{o=new Array(4),o[a]=f,f=o}while(i=r+(c*=2),n>(u=e+c)||t>i);break;case 1:do{o=new Array(4),o[a]=f,f=o}while(i=r+(c*=2),(e=u-c)>n||t>i);break;case 2:do{o=new Array(4),o[a]=f,f=o}while(r=i-(c*=2),n>(u=e+c)||r>t);break;case 3:do{o=new Array(4),o[a]=f,f=o}while(r=i-(c*=2),(e=u-c)>n||r>t)}this._root&&this._root.length&&(this._root=f)}return this._x0=e,this._y0=r,this._x1=u,this._y1=i,this},he.data=function(){var n=[];return this.visit(function(t){if(!t.length)do{n.push(t.data)}while(t=t.next)}),n},he.extent=function(n){return arguments.length?this.cover(+n[0][0],+n[0][1]).cover(+n[1][0],+n[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},he.find=function(n,t,e){var r,u,i,o,a,c,f,l=this._x0,s=this._y0,h=this._x1,g=this._y1,v=[],d=this._root;for(d&&v.push(new oe(d,l,s,h,g)),null==e?e=1/0:(l=n-e,s=t-e,h=n+e,g=t+e,e*=e);c=v.pop();)if(!(!(d=c.node)||(u=c.x0)>h||(i=c.y0)>g||(o=c.x1)<l||(a=c.y1)<s))if(d.length){var M=(u+o)/2,y=(i+a)/2;v.push(new oe(d[3],M,y,o,a),new oe(d[2],u,y,M,a),new oe(d[1],M,i,o,y),new oe(d[0],u,i,M,y)),(f=(t>=y)<<1|n>=M)&&(c=v[v.length-1],v[v.length-1]=v[v.length-1-f],v[v.length-1-f]=c)}else{var p=n-+this._x.call(null,d.data),m=t-+this._y.call(null,d.data),x=p*p+m*m;if(x<e){var w=Math.sqrt(e=x);l=n-w,s=t-w,h=n+w,g=t+w,r=d.data}}return r},he.remove=function(n){if(isNaN(i=+this._x.call(null,n))||isNaN(o=+this._y.call(null,n)))return this;var t,e,r,u,i,o,a,c,f,l,s,h,g=this._root,v=this._x0,d=this._y0,M=this._x1,y=this._y1;if(!g)return this;if(g.length)for(;;){if((f=i>=(a=(v+M)/2))?v=a:M=a,(l=o>=(c=(d+y)/2))?d=c:y=c,t=g,!(g=g[s=l<<1|f]))return this;if(!g.length)break;(t[s+1&3]||t[s+2&3]||t[s+3&3])&&(e=t,h=s)}for(;g.data!==n;)if(r=g,!(g=g.next))return this;return(u=g.next)&&delete g.next,r?(u?r.next=u:delete r.next,this):t?(u?t[s]=u:delete t[s],(g=t[0]||t[1]||t[2]||t[3])&&g===(t[3]||t[2]||t[1]||t[0])&&!g.length&&(e?e[h]=g:this._root=g),this):(this._root=u,this)},he.removeAll=function(n){for(var t=0,e=n.length;t<e;++t)this.remove(n[t]);return this},he.root=function(){return this._root},he.size=function(){var n=0;return this.visit(function(t){if(!t.length)do{++n}while(t=t.next)}),n},he.visit=function(n){var t,e,r,u,i,o,a=[],c=this._root;for(c&&a.push(new oe(c,this._x0,this._y0,this._x1,this._y1));t=a.pop();)if(!n(c=t.node,r=t.x0,u=t.y0,i=t.x1,o=t.y1)&&c.length){var f=(r+i)/2,l=(u+o)/2;(e=c[3])&&a.push(new oe(e,f,l,i,o)),(e=c[2])&&a.push(new oe(e,r,l,f,o)),(e=c[1])&&a.push(new oe(e,f,u,i,l)),(e=c[0])&&a.push(new oe(e,r,u,f,l))}return this},he.visitAfter=function(n){var t,e=[],r=[];for(this._root&&e.push(new oe(this._root,this._x0,this._y0,this._x1,this._y1));t=e.pop();){var u=t.node;if(u.length){var i,o=t.x0,a=t.y0,c=t.x1,f=t.y1,l=(o+c)/2,s=(a+f)/2;(i=u[0])&&e.push(new oe(i,o,a,l,s)),(i=u[1])&&e.push(new oe(i,l,a,c,s)),(i=u[2])&&e.push(new oe(i,o,s,l,f)),(i=u[3])&&e.push(new oe(i,l,s,c,f))}r.push(t)}for(;t=r.pop();)n(t.node,t.x0,t.y0,t.x1,t.y1);return this},he.x=function(n){return arguments.length?(this._x=n,this):this._x},he.y=function(n){return arguments.length?(this._y=n,this):this._y},n.scaleBand=x,n.scalePoint=function(){return function n(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return n(e())},t}(x().paddingInner(1))},n.scaleTime=function(){return Ot(V,W,Z,z,O,j,$,H,on).domain([new Date(2e3,0,1),new Date(2e3,0,2)])},n.scaleUtc=function(){return Ot(nn,K,B,q,X,Q,$,H,an).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)])},n.scaleLinear=function n(){var t,e,r=bt(_t,U);return r.copy=function(){return Dt(r,n())},e=(t=r).domain,t.ticks=function(n){var t=e();return f(t[0],t[t.length-1],null==n?10:n)},t.tickFormat=function(n,t){return Gt(e(),n,t)},t.nice=function(n){null==n&&(n=10);var r,u=e(),i=0,o=u.length-1,a=u[i],c=u[o];return c<a&&(r=a,a=c,c=r,r=i,i=o,o=r),(r=l(a,c,n))>0?r=l(a=Math.floor(a/r)*r,c=Math.ceil(c/r)*r,n):r<0&&(r=l(a=Math.ceil(a*r)/r,c=Math.floor(c*r)/r,n)),r>0?(u[i]=Math.floor(a/r)*r,u[o]=Math.ceil(c/r)*r,e(u)):r<0&&(u[i]=Math.ceil(a*r)/r,u[o]=Math.floor(c*r)/r,e(u)),t},t},n.scaleLog=function n(){var t=bt(Kt,ne).domain([1,10]),e=t.domain,r=10,u=re(10),i=ee(10);function o(){return u=re(r),i=ee(r),e()[0]<0&&(u=ue(u),i=ue(i)),t}return t.base=function(n){return arguments.length?(r=+n,o()):r},t.domain=function(n){return arguments.length?(e(n),o()):e()},t.ticks=function(n){var t,o=e(),a=o[0],c=o[o.length-1];(t=c<a)&&(g=a,a=c,c=g);var l,s,h,g=u(a),v=u(c),d=null==n?10:+n,M=[];if(!(r%1)&&v-g<d){if(g=Math.round(g)-1,v=Math.round(v)+1,a>0){for(;g<v;++g)for(s=1,l=i(g);s<r;++s)if(!((h=l*s)<a)){if(h>c)break;M.push(h)}}else for(;g<v;++g)for(s=r-1,l=i(g);s>=1;--s)if(!((h=l*s)<a)){if(h>c)break;M.push(h)}}else M=f(g,v,Math.min(v-g,d)).map(i);return t?M.reverse():M},t.tickFormat=function(n,e){if(null==e&&(e=10===r?\".0e\":\",\"),\"function\"!=typeof e&&(e=qt(e)),n===1/0)return e;null==n&&(n=10);var o=Math.max(1,r*n/t.ticks().length);return function(n){var t=n/i(Math.round(u(n)));return t*r<r-.5&&(t*=r),t<=o?e(n):\"\"}},t.nice=function(){return e(At(e(),{floor:function(n){return i(Math.floor(u(n)))},ceil:function(n){return i(Math.ceil(u(n)))}}))},t.copy=function(){return Dt(t,n().base(r))},t},n.extent=function(n,t){var e,r,u,i=n.length,o=-1;if(null==t){for(;++o<i;)if(null!=(e=n[o])&&e>=e)for(r=u=e;++o<i;)null!=(e=n[o])&&(r>e&&(r=e),u<e&&(u=e))}else for(;++o<i;)if(null!=(e=t(n[o],o,n))&&e>=e)for(r=u=e;++o<i;)null!=(e=t(n[o],o,n))&&(r>e&&(r=e),u<e&&(u=e));return[r,u]},n.polygonContains=function(n,t){for(var e,r,u=n.length,i=n[u-1],o=t[0],a=t[1],c=i[0],f=i[1],l=!1,s=0;s<u;++s)e=(i=n[s])[0],(r=i[1])>a!=f>a&&o<(c-e)*(a-r)/(f-r)+e&&(l=!l),c=e,f=r;return l},n.quadtree=fe,Object.defineProperty(n,\"__esModule\",{value:!0})});var extentCalc={};extentCalc._defaultScaleValue={x:[Infinity,-Infinity],y:[Infinity,-Infinity]};extentCalc.determineExtents=function determineExtents(data){var xOrd=this.xAxisType===\"ordinal\"||this.xAxisType===\"scaleBand\",yOrd=this.yAxisType===\"ordinal\"||this.yAxisType===\"scaleBand\",xTime=this.xAxisType===\"time\"||this.xAxisType===\"timeLocal\",doX=xTime?false:true,doY=true,keys=Object.keys(this.completeSeriesConfig),extents={x:[],y:[]};extents.x=this._checkForExtents(xOrd,this.chartExtents,this.dataExtents,\"x\");extents.y=this.axes&&this.axes.length?this._calcMultiAxisExtents(data):this._checkForExtents(yOrd,this.chartExtents,this.dataExtents,\"y\");if(extents.x.length>0&&extents.x[0]!==Infinity&&extents.x[1]!==-Infinity){xTime=false;doX=false}if(!Array.isArray(extents.y)||extents.y.length>0&&extents.y[0]!==Infinity&&extents.y[1]!==-Infinity){doY=false}if(data.length===0){xTime=false;doX=false;doY=false}if(doX||doY||xTime){this._findMinMax(data,doX,doY,xOrd,yOrd,xTime,extents,keys)}if(extents.x[0]===Infinity){extents.x[0]=0}if(extents.x[1]===-Infinity){extents.x[1]=1}if(Array.isArray(extents.y)&&extents.y[0]===Infinity){extents.y[0]=0}if(Array.isArray(extents.y)&&extents.y[1]===-Infinity){extents.y[1]=1}if(extents.x[1]===extents.x[0]){extents.x[0]-=.5;extents.x[1]+=.5}if(Array.isArray(extents.y)){if(extents.y[1]===extents.y[0]){extents.y[0]-=.5;extents.y[1]+=.5}}else{var yKeys=Object.keys(extents.y);for(var i=0;i<yKeys.length;i++){if(extents.y[yKeys[i]][0]===extents.y[yKeys[i]][1]){extents.y[yKeys[i]][0]-=.5;extents.y[yKeys[i]][1]+=.5}}}return extents}.bind(extentCalc);extentCalc._checkForExtents=function _checkForExtents(isOrd,chartExtents,dataExtents,axis){var exts=[];if(isOrd){if(dataExtents&&dataExtents[axis]){exts=JSON.parse(JSON.stringify(dataExtents[axis]))}if(chartExtents&&chartExtents[axis]){exts=JSON.parse(JSON.stringify(chartExtents[axis]))}}else{var fromChartExtents=false;exts=this._checkChartExtents(chartExtents,axis);fromChartExtents=exts.length===2?true:false;exts=this._checkDataExtents(dataExtents,chartExtents,axis,fromChartExtents,exts);if(exts.length<2){exts=[this._defaultScaleValue[axis][0],this._defaultScaleValue[axis][1]]}}return exts}.bind(extentCalc);extentCalc._checkChartExtents=function _checkChartExtents(cExts,axis){var exts=[];if(cExts&&cExts[axis]&&cExts[axis].length===2){exts[0]=cExts[axis][0]===\"dynamic\"?Infinity:cExts[axis][0];exts[1]=cExts[axis][1]===\"dynamic\"?-Infinity:cExts[axis][1]}return exts}.bind(extentCalc);extentCalc._checkDataExtents=function _checkDataExtents(dExts,cExts,axis,bool,exts){var result=exts||[];if(dExts&&dExts[axis]&&dExts[axis].length===2){if(bool){result[0]=cExts[axis][0]===\"dynamic\"?dExts[axis][0]:cExts[axis][0];result[1]=cExts[axis][1]===\"dynamic\"?dExts[axis][1]:cExts[axis][1]}else{result[0]=Math.min(dExts[axis][0],this._defaultScaleValue[axis][0]);result[1]=Math.max(dExts[axis][1],this._defaultScaleValue[axis][1])}}return result}.bind(extentCalc);extentCalc._findMinMax=function _findMinMax(data,doX,doY,ordX,ordY,timeX,result,keys){var xVal,yVal,dLen=data.length,x=this.completeSeriesConfig[keys[0]].x,y=this.completeSeriesConfig[keys[0]].y,doX0=!ordX&&result.x[0]===Infinity?true:false,doX1=!ordX&&result.x[1]===-Infinity?true:false,doY0=!ordY&&result.y[0]===Infinity?true:false,doY1=!ordY&&result.y[1]===-Infinity?true:false;if(timeX){this._findTimeMM(result,data,dLen,x,doX0,doX1)}if(doX||doY){for(var i=0;i<dLen;i++){xVal=this._getDataExtents(data[i],keys,\"x\");yVal=this._getDataExtents(data[i],keys,\"y\");if(doX){this._processDataValues(ordX,result,data,\"x\",x,i,doX0,doX1,xVal[0],xVal[1])}if(doY){this._processDataValues(ordY,result,data,\"y\",y,i,doY0,doY1,yVal[0],yVal[1])}}}}.bind(extentCalc);extentCalc._getDataExtents=function _getDataExtents(d,keysArr,axis){var a=[];for(var i=0;i<keysArr.length;i++){var key=keysArr[i],val;if(!this.mutedSeries[keysArr[i]]){val=d[this.completeSeriesConfig[key][axis]];if(val||val===0){a.push(val)}}}return[Math.min.apply(null,a),Math.max.apply(null,a)]}.bind(extentCalc);extentCalc._findTimeMM=function _findTimeMM(result,d,l,x,doMin,doMax){if(doMin){this._setMin(result.x,d[0][x])}if(doMax){this._setMax(result.x,d[l-1][x])}}.bind(extentCalc);extentCalc._setMin=function _setMin(r,d){if(d===null){return}if(isNaN(r[0])||r[0]>d){r[0]=d}}.bind(extentCalc);extentCalc._setMax=function _setMax(r,d){if(d===null){return}if(isNaN(r[1])||r[1]<d){r[1]=d}}.bind(extentCalc);extentCalc._processDataValues=function _processDataValues(isOrd,r,d,axis,key,i,doMin,doMax,v0,v1){if(isOrd){if(r[axis].indexOf(d[i][key])===-1){r[axis].push(d[i][key])}}else{if(doMin){this._setMin(r[axis],v0)}if(doMax){this._setMax(r[axis],v1)}}}.bind(extentCalc);extentCalc._checkInSeriesConfig=function _checkInSeriesConfig(exts,a){for(var i=0;i<this.seriesToAxes[a].length;i++){var s=this.seriesToAxes[a][i];if(!this.hardMute||!this.mutedSeries[s]){exts[a][0]=this.completeSeriesConfig[s][\"yMin\"]||this.completeSeriesConfig[s][\"yMin\"]===0?Math.min(this.completeSeriesConfig[s][\"yMin\"],exts[a][0]):exts[a][0];exts[a][1]=this.completeSeriesConfig[s][\"yMax\"]||this.completeSeriesConfig[s][\"yMax\"]===0?Math.max(this.completeSeriesConfig[s][\"yMax\"],exts[a][1]):exts[a][1]}}}.bind(extentCalc);extentCalc._applyChartExtents=function _applyChartExtents(exts,a){var k=this.chartExtents[a]?a:\"y\";if(this.chartExtents[k]){if(this.chartExtents[k][0]===\"dynamic\"){exts[a][0]=exts[a][0]||exts[a][0]===0?exts[a][0]:Infinity}else{exts[a][0]=this.chartExtents[k][0]}if(this.chartExtents[k][1]===\"dynamic\"){exts[a][1]=exts[a][1]||exts[a][1]===0?exts[a][1]:-Infinity}else{exts[a][1]=this.chartExtents[k][1]}}}.bind(extentCalc);extentCalc._searchForExtents=function _searchForExtents(exts,seriesToSearch,data){var seriesList=Object.keys(seriesToSearch);for(var i=0;i<data.length;i++){for(var j=0;j<seriesList.length;j++){var s=seriesList[j],sY=this.completeSeriesConfig[s][\"y\"],series=seriesToSearch[s],axis=series[\"axis\"];if(series.min&&(data[i][sY]||data[i][sY]===0)){exts[axis][0]=Math.min(data[i][sY],exts[axis][0])}if(series.max&&(data[i][sY]||data[i][sY]===0)){exts[axis][1]=Math.max(data[i][sY],exts[axis][1])}}}}.bind(extentCalc);extentCalc._calcSeriesToSearch=function _calcSeriesToSearch(exts,a,seriesToSearch){for(var i=0;i<this.seriesToAxes[a].length;i++){var s=this.seriesToAxes[a][i];if(!this.hardMute||!this.mutedSeries[s]){seriesToSearch[s]={axis:a,min:exts[a][0]===Infinity?true:false,max:exts[a][1]===-Infinity?true:false}}}}.bind(extentCalc);extentCalc._calcMultiAxisExtents=function _calcMultiAxisExtents(data){var search=false,exts={},seriesToSearch={},a,keys;for(var i=0;i<this.axes.length;i++){a=this.axes[i];exts[a]=[];exts[a][0]=this._defaultScaleValue.y[0];exts[a][1]=this._defaultScaleValue.y[1];this._checkInSeriesConfig(exts,a);if(this.chartExtents){this._applyChartExtents(exts,a)}if(exts[a][0]===Infinity||exts[a][1]===-Infinity){search=true;this._calcSeriesToSearch(exts,a,seriesToSearch)}}if(search){this._searchForExtents(exts,seriesToSearch,data)}keys=Object.keys(exts);for(var i=0;i<keys.length;i++){if(exts[keys[i]][0]===Infinity||exts[keys[i]][1]===-Infinity){exts[keys[i]]=[0,1]}}return exts}.bind(extentCalc);var dataMapping={},quadtrees={};quadtreeBuilt=false;function reply(data){postMessage({data:data})}function updateData(eventData){dataMapping[eventData.chartId]=eventData.data.chartData;reply(null)}function deleteData(eventData){delete dataMapping[eventData.chartId];delete quadtrees[eventData.chartId];reply(null)}function recreateD3Scale(scaleObj){var result;if(scaleObj.type===\"time\"){result=d3.scaleUtc().nice().range(scaleObj.range).domain(scaleObj.domain)}else if(scaleObj.type===\"timeLocal\"){result=d3.scaleTime().nice().range(scaleObj.range).domain(scaleObj.domain)}else if(scaleObj.type===\"linear\"){result=d3.scaleLinear().nice().range(scaleObj.range).domain(scaleObj.domain)}else if(scaleObj.type===\"log\"){result=d3.scaleLog().nice().base(scaleObj.logBase).range(scaleObj.range).domain(scaleObj.domain)}else if(scaleObj.type===\"scaleBand\"){result=d3.scaleBand().range(scaleObj.range).domain(scaleObj.domain).round(true).paddingInner(.5)}else{result=d3.scalePoint().range(scaleObj.range).domain(scaleObj.domain).padding(.5)}return result}function getMultiScale(visData){var o={},k,axis;for(var i=0;i<visData.keys.length;i++){k=visData.keys[i];axis=visData.isMultiY?visData.completeSeriesConfig[k][\"axis\"][\"id\"]:\"defaultAxis\";if(!o[axis]){o[axis]=recreateD3Scale(visData.y[axis])}}return o}function createDataStub(){return{time:null,timeSeriesKey:null,series:[],seriesObj:{},rawData:[],timeStamps:[],timeStampsTracker:{},additionalPoints:[]}}function flattenData(visData,d,xScale,yScale,index,arr){for(var i=0;i<visData.keys.length;i++){if(visData.hardMute&&visData.mutedSeries[visData.keys[i]]){continue}var o={},k=visData.keys[i],axis=visData.completeSeriesConfig[k][\"axis\"]?visData.completeSeriesConfig[k][\"axis\"][\"id\"]:\"default\";o[\"i\"]=index;o[\"k\"]=k;if(visData.radial){var pix=calcPixelCoordForRadial(d[visData.completeSeriesConfig[k][\"x\"]],d[visData.completeSeriesConfig[k][\"y\"]],axis,visData);o[\"px\"]=Math.floor(pix[0]);o[\"py\"]=Math.floor(pix[1])}else{o[\"px\"]=Math.floor(xScale(d[visData.completeSeriesConfig[k][\"x\"]],axis));o[\"py\"]=Math.floor(yScale(d[visData.completeSeriesConfig[k][\"y\"]],axis))}arr.push(o)}return arr}function buildQuadtreeHelperObj(visData,k,index,xScale){var obj={},axis=visData.completeSeriesConfig[k][\"axis\"]?visData.completeSeriesConfig[k][\"axis\"][\"id\"]:null;obj.xKey=visData.completeSeriesConfig[k][\"x\"];obj.yKey=visData.completeSeriesConfig[k][\"y\"];if(visData.radial){var calcPx=function(d){return calcPixelCoordForRadial(d[obj.xKey],d[obj.yKey],axis,visData)};obj.xScale=function(d){return calcPx(d)[0]};obj.yScale=function(d){return calcPx(d)[1]};obj.yScale.index=index}else{obj.yScale=recreateD3Scale(visData.y[axis]);obj.yScale.index=index;obj.xScale=recreateD3Scale(visData.x)}return obj}function adjustAngleForPolarChart(angle,toDegrees,visData){var offset=toDegrees?180:Math.PI;if(!visData.counterClockwise&&!toDegrees||visData.counterClockwise&&toDegrees){angle*=-1}if(visData.useDegrees){if(toDegrees){return angle+offset}else{return angle/360*2*Math.PI+offset}}else{if(toDegrees){return angle/(2*Math.PI)*360+offset}else{return angle+offset}}}function calcPixelCoordForRadial(angle,amp,axis,visData){var yRange=visData.y[axis].range[1]-visData.y[axis].range[0],yDomainTot=visData.y[axis].domain[1]-visData.y[axis].domain[0],pixelAmplitude=yRange*(amp-visData.y[axis].domain[0])/yDomainTot;angle=adjustAngleForPolarChart(angle,false,visData);return[Math.sin(angle)*pixelAmplitude,Math.cos(angle)*pixelAmplitude]}function calcXScale(visData){if(!visData.radial){var x=recreateD3Scale(visData.x);return function(d){return x(d)}}}function calcYScale(visData){if(!visData.radial){var y=getMultiScale(visData);return function(d,axis){return y[axis](d)}}}function createSingleQuadtree(data){var visData=data.data,chartData=dataMapping[data.chartId],flatData,xScale=calcXScale(visData),yScale=calcYScale(visData),quadtree;if(chartData){quadtree=d3.quadtree().extent(visData.extents).x(function(d){return d.px}).y(function(d){return d.py});var allFlat=[];for(var i=0;i<chartData.length;i++){flattenData(visData,chartData[i],xScale,yScale,i,allFlat)}quadtree.addAll(allFlat);return quadtree}else{return null}}function createSeriesQuadtree(data){var visData=data.data,chartData=dataMapping[data.chartId],k,quadtree={},xScale=function(d){return visData.radial?this.xScale(d):this.xScale(d[this.xKey])},yScale=function(d){return visData.radial?this.yScale(d):this.yScale(d[this.yKey])};if(chartData){for(var i=0;i<visData.keys.length;i++){k=visData.keys[i];if(visData.hardMute&&visData.mutedSeries[k]){continue}var obj=buildQuadtreeHelperObj(visData,k,i);quadtree[k]=d3.quadtree().extent(visData.extents).x(xScale.bind(obj)).y(yScale.bind(obj)).addAll(chartData)}return quadtree}else{return null}}function createQuadtree(data){quadtreeBuilt=false;quadtrees[data.chartId]=data.data.searchType===\"pointPerSeries\"?createSeriesQuadtree(data):createSingleQuadtree(data);quadtreeBuilt=true;reply(null,null)}function _getPixelSpaceVal(d,chartScale,key,axis){return axis?chartScale[axis](d[key]):chartScale(d[key])}function calcValueQuadtree(d,x,y){var o={};o[x]=d[x];o[y]=d[y];return o}function calcCoordQuadtree(d,x,y,xScale,yScale,visData,axis){var a=[];if(visData.radial){a=calcPixelCoordForRadial(d[x],d[y],axis,visData)}else{a[0]=xScale(d[x]);a[1]=yScale(d[y])}return a}function calcDataSeriesQuadtree(d,k,xScale,yScale,visData,axis){var x=visData.completeSeriesConfig[k][\"x\"],y=visData.completeSeriesConfig[k][\"y\"];return{coord:calcCoordQuadtree(d,x,y,xScale,yScale,visData,axis),name:k,value:calcValueQuadtree(d,x,y)}}function calcClosestPoint(mousePos,foundPoint,series,time){var pixelX=series.coord[0],pixelY=series.coord[1],currDist=(pixelX-=mousePos[0])*pixelX+(pixelY-=mousePos[1])*pixelY;if(!foundPoint||foundPoint.dist>currDist){return{dist:currDist,time:time,key:series.name}}return foundPoint}function calcDataSingleQuadtree(rawData,k,visData){var x=visData.completeSeriesConfig[k][\"x\"],y=visData.completeSeriesConfig[k][\"y\"],axis=visData.completeSeriesConfig[k][\"axis\"]?visData.completeSeriesConfig[k][\"axis\"][\"id\"]:\"default\",value=calcValueQuadtree(rawData,x,y);return{coord:visData.radial?calcPixelCoordForRadial(value[x],value[y],axis,visData):[visData.xScale(value[x]),visData.yScale[axis](value[y])],name:k,value:value}}function addCrosshairDataQuadtree(dataObj,d,timeData){if(timeData&&!dataObj.timeStampsTracker[d[timeData]]){dataObj.rawData.push(d);dataObj.timeStamps.push(d[timeData]);dataObj.timeStampsTracker[d[timeData]]=true}else if(!timeData){dataObj.rawData.push(d)}return dataObj}function constructDataObj(result,dataObj,k,visData,isSingle,xScale){if(!result||visData.hardMute&&visData.mutedSeries[k]||visData.searchFor===\"point\"&&result.k!==k&&visData.searchType!==\"pointPerSeries\"){dataObj.series.push(emptySeries(k))}else if(isSingle){var rawData=this.dataMapping[visData.chartId][result.i];dataObj.seriesObj[k]=calcDataSingleQuadtree(rawData,k,visData);dataObj.series.push(dataObj.seriesObj[k]);if(visData.calcCrosshair&&visData.searchType!==\"allInArea\"){dataObj=addCrosshairDataQuadtree(dataObj,rawData,visData.timeData)}}else{var axis=visData.completeSeriesConfig[k][\"axis\"][\"id\"],yScale=recreateD3Scale(visData.y[axis]),series=calcDataSeriesQuadtree(result,k,xScale,yScale,visData,axis);dataObj.seriesObj[k]=series;dataObj.series.push(series);if(visData.timeData){dataObj.closest=calcClosestPoint(visData.mousePos,dataObj.closest,series,result[visData.timeData])}if(visData.calcCrosshair){dataObj=addCrosshairDataQuadtree(dataObj,result,visData.timeData)}}return dataObj}function calcBoxSize(visData){var x0=visData.mousePos[0]-visData.radius,x1=visData.mousePos[0]+visData.radius,y0=visData.mousePos[1]-visData.radius,y1=visData.mousePos[1]+visData.radius;return{x0:x0,x1:x1,y0:y0,y1:y1}}function calcPolygonExtents(polygon){var xExt=d3.extent(polygon,function(d){return d[0]}),yExt=d3.extent(polygon,function(d){return d[1]});return{x0:xExt[0],x1:xExt[1],y0:yExt[0],y1:yExt[1]}}function searchPolygonQuadtree(visData,dataObj,quadtree){var boxSize=calcPolygonExtents(visData.polygon),scanned=0,selected=0;if(visData.polygon.length){quadtree.visit(function(node,nodeX0,nodeY0,nodeX1,nodeY1){if(!node.length){do{var d=node.data;scanned++;if(d3.polygonContains(visData.polygon,[d.px,d.py])){dataObj=addCrosshairDataQuadtree(dataObj,this.dataMapping[visData.chartId][node.data.i],visData.timeData);selected++}}while(node=node.next);return true}return nodeX0>=boxSize.x1||nodeY0>=boxSize.y1||nodeX1<boxSize.x0||nodeY1<boxSize.y0})}return dataObj}function searchAreaBoxQuadtree(quadtree,visData,dataObj){var boxSize=calcBoxSize(visData);quadtree.visit(function(node,nodeX0,nodeY0,nodeX1,nodeY1){if(!node.length){do{var d=node.data;if(d.px>=boxSize.x0&&d.px<boxSize.x1&&d.py>=boxSize.y0&&d.py<boxSize.y1){dataObj=addCrosshairDataQuadtree(dataObj,d.data,visData.timeData)}}while(node=node.next)}return nodeX0>=boxSize.x1||nodeY0>=boxSize.y1||nodeX1<boxSize.x0||nodeY1<boxSize.y0});return dataObj}function searchAreaRadiusQuadtree(quadtree,visData,dataObj){var r2=visData.radius*visData.radius,boxSize=calcBoxSize(visData);quadtree.visit(function(node,nodeX0,nodeY0,nodeX1,nodeY1){if(!node.length){do{if(!visData.hardMute||!visData.mutedSeries[node.data.k]){if(Math.pow(node.data.px-visData.mousePos[0],2)+Math.pow(node.data.py-visData.mousePos[1],2)<=r2){dataObj=addCrosshairDataQuadtree(dataObj,this.dataMapping[visData.chartId][node.data.i],visData.timeData)}}}while(node=node.next)}return nodeX0>=boxSize.x1||nodeY0>=boxSize.y1||nodeX1<boxSize.x0||nodeY1<boxSize.y0});return dataObj}function searchAreaQuadtree(quadtree,visData,dataObj){return visData.radius?searchAreaRadiusQuadtree(quadtree,visData,dataObj):searchAreaBoxQuadtree(quadtree,visData,dataObj)}function buildQtSingleDataObj(visData,dataObj,result){for(var i=0;i<visData.keys.length;i++){dataObj=constructDataObj(result,dataObj,visData.keys[i],visData,true,null)}if(result){dataObj.time=dataMapping[visData.chartId][result.i][visData.timeData];dataObj.timeSeriesKey=visData.searchFor===\"point\"?result.k:\"\"}return dataObj}function findAllAtPoint(quadtreeData,point,visData){var allResults=[];quadtreeData.visit(function(node,nodeX0,nodeY0,nodeX1,nodeY1){if(!node.length){do{var d=node.data;if(d.px===point.px&&d.py===point.py){allResults.push(d)}}while(node=node.next)}return nodeX0>point.px||nodeY0>point.py||nodeX1<point.px||nodeY1<point.py});return allResults}function buildAdditionalPoints(visData,allResults,result){var points=[],additionObj,timeStamps={};timeStamps[result.i]=true;for(var i=0;i<allResults.length;i++){if(allResults[i][\"i\"]===result.i&&allResults[i][\"k\"]===result.k){continue}if(visData.searchFor!==\"point\"&&timeStamps[allResults[i][\"i\"]]){continue}additionObj=createDataStub();additionObj=buildQtSingleDataObj(visData,additionObj,allResults[i]);timeStamps[allResults[i][\"i\"]]=true;points.push(additionObj)}return points}function returnAllAtPoint(quadtreeData,visData,result,dataObj){var allResults=findAllAtPoint(quadtreeData,result,visData);if(allResults.length>1){dataObj.additionalPoints=buildAdditionalPoints(visData,allResults,result)}return dataObj}function searchQuadtreeSingle(visData,dataObj,quadtreeData){var r=visData.radius?visData.radius:Infinity,result=quadtreeData.find(visData.mousePos[0],visData.mousePos[1],r);dataObj=buildQtSingleDataObj(visData,dataObj,result);if(result){dataObj=returnAllAtPoint(quadtreeData,visData,result,dataObj)}if(visData.calcCrosshair){if(visData.searchType===\"allInArea\"){dataObj=searchAreaRadiusQuadtree(quadtreeData,visData,dataObj)}}return dataObj}function searchQuadtreeSeries(visData,dataObj,quadtreeData){var r=visData.radius?visData.radius:Infinity,xScale=!visData.radial?recreateD3Scale(visData.x):null,result,k;for(var i=0;i<visData.keys.length;i++){k=visData.keys[i];if(quadtreeData[k]){if(!visData.hardMute||!visData.mutedSeries[k]){result=quadtreeData[k].find(visData.mousePos[0],visData.mousePos[1],r);dataObj=constructDataObj(result,dataObj,k,visData,false,xScale)}}}if(dataObj.closest){dataObj.time=dataObj.closest.time;dataObj.timeSeriesKey=dataObj.closest.key;delete dataObj.closest}return dataObj}function returnClosestsQuadtreePoints(eventData,time){var visData=eventData.data,dataObj=createDataStub(),quadtreeData=quadtrees[eventData.chartId];if(quadtreeData){visData.chartId=eventData.chartId;visData.xScale=recreateD3Scale(visData.x);visData.yScale=getMultiScale(visData);if(visData.searchType===\"pointPerSeries\"){dataObj=searchQuadtreeSeries(visData,dataObj,quadtreeData)}else if(visData.searchType===\"lasso\"){dataObj=searchPolygonQuadtree(visData,dataObj,quadtreeData)}else{dataObj=searchQuadtreeSingle(visData,dataObj,quadtreeData)}}delete dataObj.timeStampsTracker;reply(dataObj)}function returnQuadtreePointsInArea(eventData){var visData=eventData.data,quadtreeData=quadtrees[eventData.chartId],dataObj=createDataStub();if(quadtreeData){visData.chartId=eventData.chartId;visData.xScale=recreateD3Scale(visData.x);visData.yScale=getMultiScale(visData);dataObj=searchAreaBoxQuadtree(quadtreeData,visData,dataObj)}reply(dataObj)}function emptySeries(k){return{coord:[],name:k,value:{}}}function addCrosshairData(dataObj,d){if(this.timeData&&!dataObj.timeStampsTracker[d[this.timeData]]){dataObj.rawData.push(d);dataObj.timeStamps.push(d[this.timeData]);dataObj.timeStampsTracker[d[this.timeData]]=true}else if(!this.timeData){dataObj.rawData.push(d)}return dataObj}function determineExtents(eventData){var visData=eventData.data,extents=null;extentCalc.xAxisType=visData.xAxisType;extentCalc.yAxisType=visData.yAxisType;extentCalc.completeSeriesConfig=visData.completeSeriesConfig;extentCalc.chartExtents=visData.chartExtents;extentCalc.dataExtents=visData.dataExtents;extentCalc.axes=visData.axes;extentCalc.seriesToAxes=visData.seriesToAxes;extentCalc.isYAxisObject=visData.isYAxisObject;extentCalc.mutedSeries=visData.mutedSeries;extentCalc.hardMute=visData.hardMute;if(dataMapping[eventData.chartId]){extents=extentCalc.determineExtents(dataMapping[eventData.chartId])}reply(extents)}onmessage=function(e){switch(e.data.action){case\"registerCustomScript\":if(e.data.data.url){importScripts(e.data.data.url)}reply(null);break;case\"runCustomFunction\":var obj=this[e.data.data.objectName],func,result;if(obj){func=obj[e.data.data.functionName];if(func){result=func(e.data.data.data,e.data.chartId)}else{throw\"Couldn't run custom function \"+e.data.data.functionName+\" on custom Object \"+e.data.data.objectName+\" because the specified function doesn't exist on the specified Object.\"}}else{throw\"Couldn't run custom function \"+e.data.data.functionName+\" on custom Object \"+e.data.data.objectName+\" because the specified Object doesn't exist. Make sure you have loaded your custom script defining the custom object.\"}reply(result);break;case\"updateData\":updateData(e.data);break;case\"createQuadtree\":createQuadtree(e.data);break;case\"findQuadtreePoints\":if(quadtreeBuilt){returnClosestsQuadtreePoints(e.data)}else{reply(null)}break;case\"findQuadtreePointsInArea\":if(quadtreeBuilt){returnQuadtreePointsInArea(e.data)}else{reply(null)}break;case\"returnQuadtreeData\":if(quadtreeBuilt){reply(quadtrees[e.data.chartId])}else{reply(null)}break;case\"determineExtents\":determineExtents(e.data);break;case\"unregisterChart\":deleteData(e.data);break;default:reply(null)}};"};
//end of blob
//!!!!!!!!DO NOT DELETE COMMENT ABOVE, USED BY GULP FOR INSERTING THE BLOB
Px.vis.blobUrl = window.URL.createObjectURL(new Blob([blob.script]));
scheduler.workers = [];
scheduler.queue = [];
//mapping between chart and webworker: {chartId: webWorkerIndex}
scheduler.chartWorkerMapping = {};
scheduler.hasChartData = {};
//each chart will always use the same web worker. This is to get around
//the problem of passing a lot of data around, so the thread will have
//to keep the data for charts in sync
var getWorkerIndexForChart = function(chartId) {
//if this chart hasn't been registered yet do it
if(!scheduler.chartWorkerMapping[chartId] && scheduler.chartWorkerMapping[chartId] !== 0) {
//crudely "balance" workload by distributing charts equally among threads.
var mappingKeys = Object.keys(scheduler.chartWorkerMapping),
workerChartCount = [],
minCount = Number.MAX_VALUE,
workerIndex = 0;
for(var k=0; k<scheduler.workers.length; k++) {
workerChartCount.push(0);
}
for(var i=0; i<mappingKeys.length; i++) {
//count the number of charts for each worker
workerChartCount[scheduler.chartWorkerMapping[mappingKeys[i]]]++;
}
//pick the web worker with the least charts
for(var j=0; j<workerChartCount.length; j++) {
if(workerChartCount[j] < minCount) {
minCount = workerChartCount[j];
workerIndex = j;
}
}
//finally assign the worker index for the chart
scheduler.chartWorkerMapping[chartId] = workerIndex;
}
return scheduler.chartWorkerMapping[chartId];
}
startWork = function(worker, ctx) {
worker.inUse = true;
//don't copy the callback around, just remember it
worker.ctx = {};
worker.ctx.successCallback = ctx.successCallback;
worker.ctx.errorCallback = ctx.errorCallback;
worker.ctx.action = ctx.action;
worker.ctx.chartId = ctx.chartId;
worker.ctx.originatorName = ctx.originatorName;
Px.vis.debug.log('Starting work "' + ctx.action + '" for chart ' + ctx.chartId + ' [' + ctx.originatorName + ']', 'scheduler');
window.dispatchEvent(new CustomEvent('px-vis-scheduler-work-start', {'detail': { 'action': ctx.action, 'data': ctx.data, 'chartId': ctx.chartId, 'originatorName': ctx.originatorName}}));
worker.postMessage({ 'action': ctx.action, 'data': ctx.data, 'chartId': ctx.chartId});
}
/**
* Method to request some work from the web worker. The context object
* can have the following properties:
* - action: action to be run in the webworker. See below for list of actions
* - originatorName: arbitrary string representing who sent the request
* - chartId: Id of the chart this request relates to. Used to identify which webworker to use and what dataset to use in the webworker
* - successCallback (optional): callback after successfully running an action in the webworker. The callback will have one parameter holding the result of that action
* - errorCallback (optional): Callback after an error has been fired during the webworker.
*
* Please note successCallback and errorCallback are mutually exclusive:
* one will be called or the other. If both are defined you are guaranteed
* to have feedback on your request
*
* Each request is uniquely identified through the triplet "action
* originatorName chartId". When a webworker is busy and a request comes
* in for this webworker then the request will be queued. If another
* request with the same triplet identifier comes in it will trump the
* previously queued request: the request initially queued will be
* destroyed and the new one will be queued
*
* The current list of significant actions is as follows (more can be
* found by inspecting px-vis-worker.js but are usually meant to be used
* internally):
* - runCustomFunction: used to run a function on a custom script that you
explicitely loaded in the web workers through Px.vis.registerCustomScript. Pass "functionName" and "objectName" in the "data" object of the context
* - updateData: register a new dataset or update a dataset in the web worker. It will be stored in the dataMapping object, the key being chartId and the value the dataset. pass "chartData" in the data object
*
*/
scheduler.process = function(context) {
//find worker for this chart
var worker = scheduler.workers[getWorkerIndexForChart(context.chartId)]
Px.vis.debug.log('Request for work "' + context.action + '" for chart ' + context.chartId + ' [' + context.originatorName + ']', 'scheduler');
startOrQueueWork(context, worker);
};
var startOrQueueWork = function(context, worker) {
// check if we have run updateData before so we can stick stuff in a queue if not
var hasData = scheduler.hasChartData[context.chartId] ?
scheduler.hasChartData[context.chartId] : (context.action === 'updateData');
//start work or queue
if(!worker.inUse && (hasData || context.action === 'unregisterChart')) {
scheduler.hasChartData[context.chartId] = hasData;
startWork(worker, context);
} else {
//worker not available, queue
var obj,
found;
Px.vis.debug.log('Queue work "' + context.action + '" for chart ' + context.chartId + ' [' + context.originatorName + ']. Worker in use: ' + worker.inUse + ', worker has data: ' + hasData, 'scheduler');
//if we already have an action of this type for this chart remove the old one and replace it with this one
for(var i=0; i<scheduler.queue[worker.index].length; i++) {
var obj = scheduler.queue[worker.index][i];
if(obj.chartId === context.chartId && obj.action === context.action && obj.originatorName === context.originatorName) {
found = i;
break;
}
}
if(found || found === 0) {
scheduler.queue[worker.index].splice(found, 1);
}
//now queue
scheduler.queue[worker.index].push(context);
}
};
//called once a worker has finished a piece of work
processDone = function(e) {
window.dispatchEvent(new CustomEvent('px-vis-scheduler-work-end', {'detail': { 'action': this.ctx.action, 'data': e.data.data, 'chartId': this.ctx.chartId, 'originatorName': this.ctx.originatorName}}));
Px.vis.debug.log('Work "' + this.ctx.action + '" done for chart ' + this.ctx.chartId + ' [' + this.ctx.originatorName + ']. Result: ' + JSON.stringify(e.data.data), 'scheduler');
//store callback and kick off new work before processing results
var callback = this.ctx.successCallback;
//cleanup if chart has been unregistered
if(this.ctx.action === 'unregisterChart') {
//TODO: clean queues in case something has been added while deleting?
delete scheduler.chartWorkerMapping[this.ctx.chartId];
delete scheduler.hasChartData[this.ctx.chartId];
//clear everything related to this chart
scheduler.queue[this.index] = scheduler.queue[this.index].filter(function(elem) {
return elem.chartId !== this.ctx.chartId;
}.bind(this));
}
Px.vis.debug.info('Release web worker ' + this.index, 'scheduler');
this.inUse = false;
//use thread if work queued
if(scheduler.queue[this.index].length) {
//get and do work
var ctx = scheduler.queue[this.index].splice(0, 1)[0];
startOrQueueWork(ctx, this);
}
//run callback with the result
if(callback) {
Px.vis.debug.info('Calling callback for "' + this.ctx.action + '" chart ' + this.ctx.chartId + ' [' + this.ctx.originatorName + ']', 'scheduler');
callback(e.data);
}
};
var webWorkerError = function(e) {
window.dispatchEvent(new CustomEvent('px-vis-scheduler-work-error', { 'detail': { 'action': this.ctx.action, 'chartId': this.ctx.chartId, 'originatorName': this.ctx.originatorName}}));
Px.vis.debug.warn('ERROR in work "' + this.ctx.action + '" for chart ' + this.ctx.chartId + ' [' + this.ctx.originatorName + ']. Message: ' + e.message, 'scheduler');
//cleanup if chart has been unregistered
if(this.ctx.action === 'unregisterChart') {
//TODO: clean queues in case something has been added while deleting?
delete scheduler.chartWorkerMapping[this.ctx.chartId];
}
//store callback and kick off new work before processing results
var callback = this.ctx.errorCallback;
//use thread if work queued
if(scheduler.queue[this.index].length) {
//get and do work
var ctx = scheduler.queue[this.index].splice(0, 1)[0];
startOrQueueWork(ctx, this);
} else {
Px.vis.debug.info('Release web worker ' + this.index, 'scheduler');
this.inUse = false;
}
if(callback) {
Px.vis.debug.info('Calling callback for "' + this.ctx.action + '" chart ' + this.ctx.chartId + ' [' + this.ctx.originatorName + ']', 'scheduler');
callback();
}
};
//create workers and init queue
for(var i=0; i<threadCount; i++) {
try {
var worker = new Worker(Px.vis.blobUrl);
} catch(e) {
//failure
console.warn('failed to find px-vis web worker file at ' + Px.vis.blobUrl);
console.warn('the charts won\'t be able to determine their extents or find values')
return;
}
//we can load the worker through a data uri if needed
scheduler.workers.push(worker);
worker.inUse = true;
worker.index = i;
worker.onmessage = processDone;
worker.onerror = webWorkerError;
worker.ctx = {};
worker.ctx.action = 'init';
//kick a first dummy communication for each worker.
//The first comm for each worker is slow (needs to parse script)
//so do it now in order not to suffer the slowdown when actually needing it
worker.postMessage({'action': 'init', 'd3Url': Px.vis.workerD3Url});
scheduler.queue.push([]);
}
scheduler.registerCustomScript = function(scriptUrl, successCallback, errorCallback) {
var regCallback,
errCallback,
successCounter = 0,
errCounter = 0,
ctx;
//it should be either all registration will fail or all will succeed
regCallback = function() {
successCounter++;
if(successCounter === scheduler.workers.length) {
//registration on all ww done
if(successCallback) {
successCallback();
}
} else if(errCounter > 0 && errorCallback) {
//got some error, some success... just fire error
errorCallback();
}
};
errCallback = function() {
errCounter++;
if(errCounter === scheduler.workers.length) {
//all reg failed
if(errorCallback) {
errorCallback();
}
} else if(successCounter > 0 && errorCallback) {
//got some error, some success... just fire error
errorCallback();
}
};
ctx = {
'action': 'registerCustomScript',
'data': {
'url': scriptUrl
},
'successCallback': regCallback,
'errorCallback': errCallback
};
//run registration on each worker
for(var i=0; i<scheduler.workers.length; i++) {
startWork(scheduler.workers[i], ctx);
}
}
Px.vis.scheduler = scheduler;
window.dispatchEvent(new CustomEvent('px-vis-worker-ready'));
}
}());
</script>