Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20591 lines
572 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. // https://d3js.org v7.8.0 Copyright 2010-2022 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
  6. })(this, (function (exports) { 'use strict';
  7. var version = "7.8.0";
  8. function ascending$3(a, b) {
  9. return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function descending$2(a, b) {
  12. return a == null || b == null ? NaN
  13. : b < a ? -1
  14. : b > a ? 1
  15. : b >= a ? 0
  16. : NaN;
  17. }
  18. function bisector(f) {
  19. let compare1, compare2, delta;
  20. // If an accessor is specified, promote it to a comparator. In this case we
  21. // can test whether the search value is (self-) comparable. We can’t do this
  22. // for a comparator (except for specific, known comparators) because we can’t
  23. // tell if the comparator is symmetric, and an asymmetric comparator can’t be
  24. // used to test whether a single value is comparable.
  25. if (f.length !== 2) {
  26. compare1 = ascending$3;
  27. compare2 = (d, x) => ascending$3(f(d), x);
  28. delta = (d, x) => f(d) - x;
  29. } else {
  30. compare1 = f === ascending$3 || f === descending$2 ? f : zero$1;
  31. compare2 = f;
  32. delta = f;
  33. }
  34. function left(a, x, lo = 0, hi = a.length) {
  35. if (lo < hi) {
  36. if (compare1(x, x) !== 0) return hi;
  37. do {
  38. const mid = (lo + hi) >>> 1;
  39. if (compare2(a[mid], x) < 0) lo = mid + 1;
  40. else hi = mid;
  41. } while (lo < hi);
  42. }
  43. return lo;
  44. }
  45. function right(a, x, lo = 0, hi = a.length) {
  46. if (lo < hi) {
  47. if (compare1(x, x) !== 0) return hi;
  48. do {
  49. const mid = (lo + hi) >>> 1;
  50. if (compare2(a[mid], x) <= 0) lo = mid + 1;
  51. else hi = mid;
  52. } while (lo < hi);
  53. }
  54. return lo;
  55. }
  56. function center(a, x, lo = 0, hi = a.length) {
  57. const i = left(a, x, lo, hi - 1);
  58. return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
  59. }
  60. return {left, center, right};
  61. }
  62. function zero$1() {
  63. return 0;
  64. }
  65. function number$3(x) {
  66. return x === null ? NaN : +x;
  67. }
  68. function* numbers(values, valueof) {
  69. if (valueof === undefined) {
  70. for (let value of values) {
  71. if (value != null && (value = +value) >= value) {
  72. yield value;
  73. }
  74. }
  75. } else {
  76. let index = -1;
  77. for (let value of values) {
  78. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  79. yield value;
  80. }
  81. }
  82. }
  83. }
  84. const ascendingBisect = bisector(ascending$3);
  85. const bisectRight = ascendingBisect.right;
  86. const bisectLeft = ascendingBisect.left;
  87. const bisectCenter = bisector(number$3).center;
  88. var bisect = bisectRight;
  89. function blur(values, r) {
  90. if (!((r = +r) >= 0)) throw new RangeError("invalid r");
  91. let length = values.length;
  92. if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
  93. if (!length || !r) return values;
  94. const blur = blurf(r);
  95. const temp = values.slice();
  96. blur(values, temp, 0, length, 1);
  97. blur(temp, values, 0, length, 1);
  98. blur(values, temp, 0, length, 1);
  99. return values;
  100. }
  101. const blur2 = Blur2(blurf);
  102. const blurImage = Blur2(blurfImage);
  103. function Blur2(blur) {
  104. return function(data, rx, ry = rx) {
  105. if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
  106. if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
  107. let {data: values, width, height} = data;
  108. if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
  109. if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
  110. if (!width || !height || (!rx && !ry)) return data;
  111. const blurx = rx && blur(rx);
  112. const blury = ry && blur(ry);
  113. const temp = values.slice();
  114. if (blurx && blury) {
  115. blurh(blurx, temp, values, width, height);
  116. blurh(blurx, values, temp, width, height);
  117. blurh(blurx, temp, values, width, height);
  118. blurv(blury, values, temp, width, height);
  119. blurv(blury, temp, values, width, height);
  120. blurv(blury, values, temp, width, height);
  121. } else if (blurx) {
  122. blurh(blurx, values, temp, width, height);
  123. blurh(blurx, temp, values, width, height);
  124. blurh(blurx, values, temp, width, height);
  125. } else if (blury) {
  126. blurv(blury, values, temp, width, height);
  127. blurv(blury, temp, values, width, height);
  128. blurv(blury, values, temp, width, height);
  129. }
  130. return data;
  131. };
  132. }
  133. function blurh(blur, T, S, w, h) {
  134. for (let y = 0, n = w * h; y < n;) {
  135. blur(T, S, y, y += w, 1);
  136. }
  137. }
  138. function blurv(blur, T, S, w, h) {
  139. for (let x = 0, n = w * h; x < w; ++x) {
  140. blur(T, S, x, x + n, w);
  141. }
  142. }
  143. function blurfImage(radius) {
  144. const blur = blurf(radius);
  145. return (T, S, start, stop, step) => {
  146. start <<= 2, stop <<= 2, step <<= 2;
  147. blur(T, S, start + 0, stop + 0, step);
  148. blur(T, S, start + 1, stop + 1, step);
  149. blur(T, S, start + 2, stop + 2, step);
  150. blur(T, S, start + 3, stop + 3, step);
  151. };
  152. }
  153. // Given a target array T, a source array S, sets each value T[i] to the average
  154. // of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop,
  155. // for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between
  156. // S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an
  157. // integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted
  158. // according to r - ⌊radius⌋.
  159. function blurf(radius) {
  160. const radius0 = Math.floor(radius);
  161. if (radius0 === radius) return bluri(radius);
  162. const t = radius - radius0;
  163. const w = 2 * radius + 1;
  164. return (T, S, start, stop, step) => { // stop must be aligned!
  165. if (!((stop -= step) >= start)) return; // inclusive stop
  166. let sum = radius0 * S[start];
  167. const s0 = step * radius0;
  168. const s1 = s0 + step;
  169. for (let i = start, j = start + s0; i < j; i += step) {
  170. sum += S[Math.min(stop, i)];
  171. }
  172. for (let i = start, j = stop; i <= j; i += step) {
  173. sum += S[Math.min(stop, i + s0)];
  174. T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
  175. sum -= S[Math.max(start, i - s0)];
  176. }
  177. };
  178. }
  179. // Like blurf, but optimized for integer radius.
  180. function bluri(radius) {
  181. const w = 2 * radius + 1;
  182. return (T, S, start, stop, step) => { // stop must be aligned!
  183. if (!((stop -= step) >= start)) return; // inclusive stop
  184. let sum = radius * S[start];
  185. const s = step * radius;
  186. for (let i = start, j = start + s; i < j; i += step) {
  187. sum += S[Math.min(stop, i)];
  188. }
  189. for (let i = start, j = stop; i <= j; i += step) {
  190. sum += S[Math.min(stop, i + s)];
  191. T[i] = sum / w;
  192. sum -= S[Math.max(start, i - s)];
  193. }
  194. };
  195. }
  196. function count$1(values, valueof) {
  197. let count = 0;
  198. if (valueof === undefined) {
  199. for (let value of values) {
  200. if (value != null && (value = +value) >= value) {
  201. ++count;
  202. }
  203. }
  204. } else {
  205. let index = -1;
  206. for (let value of values) {
  207. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  208. ++count;
  209. }
  210. }
  211. }
  212. return count;
  213. }
  214. function length$3(array) {
  215. return array.length | 0;
  216. }
  217. function empty$2(length) {
  218. return !(length > 0);
  219. }
  220. function arrayify(values) {
  221. return typeof values !== "object" || "length" in values ? values : Array.from(values);
  222. }
  223. function reducer(reduce) {
  224. return values => reduce(...values);
  225. }
  226. function cross$2(...values) {
  227. const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
  228. values = values.map(arrayify);
  229. const lengths = values.map(length$3);
  230. const j = values.length - 1;
  231. const index = new Array(j + 1).fill(0);
  232. const product = [];
  233. if (j < 0 || lengths.some(empty$2)) return product;
  234. while (true) {
  235. product.push(index.map((j, i) => values[i][j]));
  236. let i = j;
  237. while (++index[i] === lengths[i]) {
  238. if (i === 0) return reduce ? product.map(reduce) : product;
  239. index[i--] = 0;
  240. }
  241. }
  242. }
  243. function cumsum(values, valueof) {
  244. var sum = 0, index = 0;
  245. return Float64Array.from(values, valueof === undefined
  246. ? v => (sum += +v || 0)
  247. : v => (sum += +valueof(v, index++, values) || 0));
  248. }
  249. function variance(values, valueof) {
  250. let count = 0;
  251. let delta;
  252. let mean = 0;
  253. let sum = 0;
  254. if (valueof === undefined) {
  255. for (let value of values) {
  256. if (value != null && (value = +value) >= value) {
  257. delta = value - mean;
  258. mean += delta / ++count;
  259. sum += delta * (value - mean);
  260. }
  261. }
  262. } else {
  263. let index = -1;
  264. for (let value of values) {
  265. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  266. delta = value - mean;
  267. mean += delta / ++count;
  268. sum += delta * (value - mean);
  269. }
  270. }
  271. }
  272. if (count > 1) return sum / (count - 1);
  273. }
  274. function deviation(values, valueof) {
  275. const v = variance(values, valueof);
  276. return v ? Math.sqrt(v) : v;
  277. }
  278. function extent$1(values, valueof) {
  279. let min;
  280. let max;
  281. if (valueof === undefined) {
  282. for (const value of values) {
  283. if (value != null) {
  284. if (min === undefined) {
  285. if (value >= value) min = max = value;
  286. } else {
  287. if (min > value) min = value;
  288. if (max < value) max = value;
  289. }
  290. }
  291. }
  292. } else {
  293. let index = -1;
  294. for (let value of values) {
  295. if ((value = valueof(value, ++index, values)) != null) {
  296. if (min === undefined) {
  297. if (value >= value) min = max = value;
  298. } else {
  299. if (min > value) min = value;
  300. if (max < value) max = value;
  301. }
  302. }
  303. }
  304. }
  305. return [min, max];
  306. }
  307. // https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
  308. class Adder {
  309. constructor() {
  310. this._partials = new Float64Array(32);
  311. this._n = 0;
  312. }
  313. add(x) {
  314. const p = this._partials;
  315. let i = 0;
  316. for (let j = 0; j < this._n && j < 32; j++) {
  317. const y = p[j],
  318. hi = x + y,
  319. lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
  320. if (lo) p[i++] = lo;
  321. x = hi;
  322. }
  323. p[i] = x;
  324. this._n = i + 1;
  325. return this;
  326. }
  327. valueOf() {
  328. const p = this._partials;
  329. let n = this._n, x, y, lo, hi = 0;
  330. if (n > 0) {
  331. hi = p[--n];
  332. while (n > 0) {
  333. x = hi;
  334. y = p[--n];
  335. hi = x + y;
  336. lo = y - (hi - x);
  337. if (lo) break;
  338. }
  339. if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
  340. y = lo * 2;
  341. x = hi + y;
  342. if (y == x - hi) hi = x;
  343. }
  344. }
  345. return hi;
  346. }
  347. }
  348. function fsum(values, valueof) {
  349. const adder = new Adder();
  350. if (valueof === undefined) {
  351. for (let value of values) {
  352. if (value = +value) {
  353. adder.add(value);
  354. }
  355. }
  356. } else {
  357. let index = -1;
  358. for (let value of values) {
  359. if (value = +valueof(value, ++index, values)) {
  360. adder.add(value);
  361. }
  362. }
  363. }
  364. return +adder;
  365. }
  366. function fcumsum(values, valueof) {
  367. const adder = new Adder();
  368. let index = -1;
  369. return Float64Array.from(values, valueof === undefined
  370. ? v => adder.add(+v || 0)
  371. : v => adder.add(+valueof(v, ++index, values) || 0)
  372. );
  373. }
  374. class InternMap extends Map {
  375. constructor(entries, key = keyof) {
  376. super();
  377. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  378. if (entries != null) for (const [key, value] of entries) this.set(key, value);
  379. }
  380. get(key) {
  381. return super.get(intern_get(this, key));
  382. }
  383. has(key) {
  384. return super.has(intern_get(this, key));
  385. }
  386. set(key, value) {
  387. return super.set(intern_set(this, key), value);
  388. }
  389. delete(key) {
  390. return super.delete(intern_delete(this, key));
  391. }
  392. }
  393. class InternSet extends Set {
  394. constructor(values, key = keyof) {
  395. super();
  396. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  397. if (values != null) for (const value of values) this.add(value);
  398. }
  399. has(value) {
  400. return super.has(intern_get(this, value));
  401. }
  402. add(value) {
  403. return super.add(intern_set(this, value));
  404. }
  405. delete(value) {
  406. return super.delete(intern_delete(this, value));
  407. }
  408. }
  409. function intern_get({_intern, _key}, value) {
  410. const key = _key(value);
  411. return _intern.has(key) ? _intern.get(key) : value;
  412. }
  413. function intern_set({_intern, _key}, value) {
  414. const key = _key(value);
  415. if (_intern.has(key)) return _intern.get(key);
  416. _intern.set(key, value);
  417. return value;
  418. }
  419. function intern_delete({_intern, _key}, value) {
  420. const key = _key(value);
  421. if (_intern.has(key)) {
  422. value = _intern.get(key);
  423. _intern.delete(key);
  424. }
  425. return value;
  426. }
  427. function keyof(value) {
  428. return value !== null && typeof value === "object" ? value.valueOf() : value;
  429. }
  430. function identity$9(x) {
  431. return x;
  432. }
  433. function group(values, ...keys) {
  434. return nest(values, identity$9, identity$9, keys);
  435. }
  436. function groups(values, ...keys) {
  437. return nest(values, Array.from, identity$9, keys);
  438. }
  439. function flatten$1(groups, keys) {
  440. for (let i = 1, n = keys.length; i < n; ++i) {
  441. groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value]));
  442. }
  443. return groups;
  444. }
  445. function flatGroup(values, ...keys) {
  446. return flatten$1(groups(values, ...keys), keys);
  447. }
  448. function flatRollup(values, reduce, ...keys) {
  449. return flatten$1(rollups(values, reduce, ...keys), keys);
  450. }
  451. function rollup(values, reduce, ...keys) {
  452. return nest(values, identity$9, reduce, keys);
  453. }
  454. function rollups(values, reduce, ...keys) {
  455. return nest(values, Array.from, reduce, keys);
  456. }
  457. function index$4(values, ...keys) {
  458. return nest(values, identity$9, unique, keys);
  459. }
  460. function indexes(values, ...keys) {
  461. return nest(values, Array.from, unique, keys);
  462. }
  463. function unique(values) {
  464. if (values.length !== 1) throw new Error("duplicate key");
  465. return values[0];
  466. }
  467. function nest(values, map, reduce, keys) {
  468. return (function regroup(values, i) {
  469. if (i >= keys.length) return reduce(values);
  470. const groups = new InternMap();
  471. const keyof = keys[i++];
  472. let index = -1;
  473. for (const value of values) {
  474. const key = keyof(value, ++index, values);
  475. const group = groups.get(key);
  476. if (group) group.push(value);
  477. else groups.set(key, [value]);
  478. }
  479. for (const [key, values] of groups) {
  480. groups.set(key, regroup(values, i));
  481. }
  482. return map(groups);
  483. })(values, 0);
  484. }
  485. function permute(source, keys) {
  486. return Array.from(keys, key => source[key]);
  487. }
  488. function sort(values, ...F) {
  489. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  490. values = Array.from(values);
  491. let [f] = F;
  492. if ((f && f.length !== 2) || F.length > 1) {
  493. const index = Uint32Array.from(values, (d, i) => i);
  494. if (F.length > 1) {
  495. F = F.map(f => values.map(f));
  496. index.sort((i, j) => {
  497. for (const f of F) {
  498. const c = ascendingDefined(f[i], f[j]);
  499. if (c) return c;
  500. }
  501. });
  502. } else {
  503. f = values.map(f);
  504. index.sort((i, j) => ascendingDefined(f[i], f[j]));
  505. }
  506. return permute(values, index);
  507. }
  508. return values.sort(compareDefined(f));
  509. }
  510. function compareDefined(compare = ascending$3) {
  511. if (compare === ascending$3) return ascendingDefined;
  512. if (typeof compare !== "function") throw new TypeError("compare is not a function");
  513. return (a, b) => {
  514. const x = compare(a, b);
  515. if (x || x === 0) return x;
  516. return (compare(b, b) === 0) - (compare(a, a) === 0);
  517. };
  518. }
  519. function ascendingDefined(a, b) {
  520. return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
  521. }
  522. function groupSort(values, reduce, key) {
  523. return (reduce.length !== 2
  524. ? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk)))
  525. : sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk))))
  526. .map(([key]) => key);
  527. }
  528. var array$5 = Array.prototype;
  529. var slice$3 = array$5.slice;
  530. function constant$b(x) {
  531. return () => x;
  532. }
  533. var e10 = Math.sqrt(50),
  534. e5 = Math.sqrt(10),
  535. e2 = Math.sqrt(2);
  536. function ticks(start, stop, count) {
  537. var reverse,
  538. i = -1,
  539. n,
  540. ticks,
  541. step;
  542. stop = +stop, start = +start, count = +count;
  543. if (start === stop && count > 0) return [start];
  544. if (reverse = stop < start) n = start, start = stop, stop = n;
  545. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  546. if (step > 0) {
  547. let r0 = Math.round(start / step), r1 = Math.round(stop / step);
  548. if (r0 * step < start) ++r0;
  549. if (r1 * step > stop) --r1;
  550. ticks = new Array(n = r1 - r0 + 1);
  551. while (++i < n) ticks[i] = (r0 + i) * step;
  552. } else {
  553. step = -step;
  554. let r0 = Math.round(start * step), r1 = Math.round(stop * step);
  555. if (r0 / step < start) ++r0;
  556. if (r1 / step > stop) --r1;
  557. ticks = new Array(n = r1 - r0 + 1);
  558. while (++i < n) ticks[i] = (r0 + i) / step;
  559. }
  560. if (reverse) ticks.reverse();
  561. return ticks;
  562. }
  563. function tickIncrement(start, stop, count) {
  564. var step = (stop - start) / Math.max(0, count),
  565. power = Math.floor(Math.log(step) / Math.LN10),
  566. error = step / Math.pow(10, power);
  567. return power >= 0
  568. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  569. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  570. }
  571. function tickStep(start, stop, count) {
  572. var step0 = Math.abs(stop - start) / Math.max(0, count),
  573. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  574. error = step0 / step1;
  575. if (error >= e10) step1 *= 10;
  576. else if (error >= e5) step1 *= 5;
  577. else if (error >= e2) step1 *= 2;
  578. return stop < start ? -step1 : step1;
  579. }
  580. function nice$1(start, stop, count) {
  581. let prestep;
  582. while (true) {
  583. const step = tickIncrement(start, stop, count);
  584. if (step === prestep || step === 0 || !isFinite(step)) {
  585. return [start, stop];
  586. } else if (step > 0) {
  587. start = Math.floor(start / step) * step;
  588. stop = Math.ceil(stop / step) * step;
  589. } else if (step < 0) {
  590. start = Math.ceil(start * step) / step;
  591. stop = Math.floor(stop * step) / step;
  592. }
  593. prestep = step;
  594. }
  595. }
  596. function thresholdSturges(values) {
  597. return Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1;
  598. }
  599. function bin() {
  600. var value = identity$9,
  601. domain = extent$1,
  602. threshold = thresholdSturges;
  603. function histogram(data) {
  604. if (!Array.isArray(data)) data = Array.from(data);
  605. var i,
  606. n = data.length,
  607. x,
  608. step,
  609. values = new Array(n);
  610. for (i = 0; i < n; ++i) {
  611. values[i] = value(data[i], i, data);
  612. }
  613. var xz = domain(values),
  614. x0 = xz[0],
  615. x1 = xz[1],
  616. tz = threshold(values, x0, x1);
  617. // Convert number of thresholds into uniform thresholds, and nice the
  618. // default domain accordingly.
  619. if (!Array.isArray(tz)) {
  620. const max = x1, tn = +tz;
  621. if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
  622. tz = ticks(x0, x1, tn);
  623. // If the domain is aligned with the first tick (which it will by
  624. // default), then we can use quantization rather than bisection to bin
  625. // values, which is substantially faster.
  626. if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
  627. // If the last threshold is coincident with the domain’s upper bound, the
  628. // last bin will be zero-width. If the default domain is used, and this
  629. // last threshold is coincident with the maximum input value, we can
  630. // extend the niced upper bound by one tick to ensure uniform bin widths;
  631. // otherwise, we simply remove the last threshold. Note that we don’t
  632. // coerce values or the domain to numbers, and thus must be careful to
  633. // compare order (>=) rather than strict equality (===)!
  634. if (tz[tz.length - 1] >= x1) {
  635. if (max >= x1 && domain === extent$1) {
  636. const step = tickIncrement(x0, x1, tn);
  637. if (isFinite(step)) {
  638. if (step > 0) {
  639. x1 = (Math.floor(x1 / step) + 1) * step;
  640. } else if (step < 0) {
  641. x1 = (Math.ceil(x1 * -step) + 1) / -step;
  642. }
  643. }
  644. } else {
  645. tz.pop();
  646. }
  647. }
  648. }
  649. // Remove any thresholds outside the domain.
  650. // Be careful not to mutate an array owned by the user!
  651. var m = tz.length, a = 0, b = m;
  652. while (tz[a] <= x0) ++a;
  653. while (tz[b - 1] > x1) --b;
  654. if (a || b < m) tz = tz.slice(a, b), m = b - a;
  655. var bins = new Array(m + 1),
  656. bin;
  657. // Initialize bins.
  658. for (i = 0; i <= m; ++i) {
  659. bin = bins[i] = [];
  660. bin.x0 = i > 0 ? tz[i - 1] : x0;
  661. bin.x1 = i < m ? tz[i] : x1;
  662. }
  663. // Assign data to bins by value, ignoring any outside the domain.
  664. if (isFinite(step)) {
  665. if (step > 0) {
  666. for (i = 0; i < n; ++i) {
  667. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  668. bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
  669. }
  670. }
  671. } else if (step < 0) {
  672. for (i = 0; i < n; ++i) {
  673. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  674. const j = Math.floor((x0 - x) * step);
  675. bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding
  676. }
  677. }
  678. }
  679. } else {
  680. for (i = 0; i < n; ++i) {
  681. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  682. bins[bisect(tz, x, 0, m)].push(data[i]);
  683. }
  684. }
  685. }
  686. return bins;
  687. }
  688. histogram.value = function(_) {
  689. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
  690. };
  691. histogram.domain = function(_) {
  692. return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
  693. };
  694. histogram.thresholds = function(_) {
  695. return arguments.length ? (threshold = typeof _ === "function" ? _ : constant$b(Array.isArray(_) ? slice$3.call(_) : _), histogram) : threshold;
  696. };
  697. return histogram;
  698. }
  699. function max$3(values, valueof) {
  700. let max;
  701. if (valueof === undefined) {
  702. for (const value of values) {
  703. if (value != null
  704. && (max < value || (max === undefined && value >= value))) {
  705. max = value;
  706. }
  707. }
  708. } else {
  709. let index = -1;
  710. for (let value of values) {
  711. if ((value = valueof(value, ++index, values)) != null
  712. && (max < value || (max === undefined && value >= value))) {
  713. max = value;
  714. }
  715. }
  716. }
  717. return max;
  718. }
  719. function maxIndex(values, valueof) {
  720. let max;
  721. let maxIndex = -1;
  722. let index = -1;
  723. if (valueof === undefined) {
  724. for (const value of values) {
  725. ++index;
  726. if (value != null
  727. && (max < value || (max === undefined && value >= value))) {
  728. max = value, maxIndex = index;
  729. }
  730. }
  731. } else {
  732. for (let value of values) {
  733. if ((value = valueof(value, ++index, values)) != null
  734. && (max < value || (max === undefined && value >= value))) {
  735. max = value, maxIndex = index;
  736. }
  737. }
  738. }
  739. return maxIndex;
  740. }
  741. function min$2(values, valueof) {
  742. let min;
  743. if (valueof === undefined) {
  744. for (const value of values) {
  745. if (value != null
  746. && (min > value || (min === undefined && value >= value))) {
  747. min = value;
  748. }
  749. }
  750. } else {
  751. let index = -1;
  752. for (let value of values) {
  753. if ((value = valueof(value, ++index, values)) != null
  754. && (min > value || (min === undefined && value >= value))) {
  755. min = value;
  756. }
  757. }
  758. }
  759. return min;
  760. }
  761. function minIndex(values, valueof) {
  762. let min;
  763. let minIndex = -1;
  764. let index = -1;
  765. if (valueof === undefined) {
  766. for (const value of values) {
  767. ++index;
  768. if (value != null
  769. && (min > value || (min === undefined && value >= value))) {
  770. min = value, minIndex = index;
  771. }
  772. }
  773. } else {
  774. for (let value of values) {
  775. if ((value = valueof(value, ++index, values)) != null
  776. && (min > value || (min === undefined && value >= value))) {
  777. min = value, minIndex = index;
  778. }
  779. }
  780. }
  781. return minIndex;
  782. }
  783. // Based on https://github.com/mourner/quickselect
  784. // ISC license, Copyright 2018 Vladimir Agafonkin.
  785. function quickselect(array, k, left = 0, right = Infinity, compare) {
  786. k = Math.floor(k);
  787. left = Math.floor(Math.max(0, left));
  788. right = Math.floor(Math.min(array.length - 1, right));
  789. if (!(left <= k && k <= right)) return array;
  790. compare = compare === undefined ? ascendingDefined : compareDefined(compare);
  791. while (right > left) {
  792. if (right - left > 600) {
  793. const n = right - left + 1;
  794. const m = k - left + 1;
  795. const z = Math.log(n);
  796. const s = 0.5 * Math.exp(2 * z / 3);
  797. const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  798. const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  799. const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  800. quickselect(array, k, newLeft, newRight, compare);
  801. }
  802. const t = array[k];
  803. let i = left;
  804. let j = right;
  805. swap$1(array, left, k);
  806. if (compare(array[right], t) > 0) swap$1(array, left, right);
  807. while (i < j) {
  808. swap$1(array, i, j), ++i, --j;
  809. while (compare(array[i], t) < 0) ++i;
  810. while (compare(array[j], t) > 0) --j;
  811. }
  812. if (compare(array[left], t) === 0) swap$1(array, left, j);
  813. else ++j, swap$1(array, j, right);
  814. if (j <= k) left = j + 1;
  815. if (k <= j) right = j - 1;
  816. }
  817. return array;
  818. }
  819. function swap$1(array, i, j) {
  820. const t = array[i];
  821. array[i] = array[j];
  822. array[j] = t;
  823. }
  824. function greatest(values, compare = ascending$3) {
  825. let max;
  826. let defined = false;
  827. if (compare.length === 1) {
  828. let maxValue;
  829. for (const element of values) {
  830. const value = compare(element);
  831. if (defined
  832. ? ascending$3(value, maxValue) > 0
  833. : ascending$3(value, value) === 0) {
  834. max = element;
  835. maxValue = value;
  836. defined = true;
  837. }
  838. }
  839. } else {
  840. for (const value of values) {
  841. if (defined
  842. ? compare(value, max) > 0
  843. : compare(value, value) === 0) {
  844. max = value;
  845. defined = true;
  846. }
  847. }
  848. }
  849. return max;
  850. }
  851. function quantile$1(values, p, valueof) {
  852. values = Float64Array.from(numbers(values, valueof));
  853. if (!(n = values.length) || isNaN(p = +p)) return;
  854. if (p <= 0 || n < 2) return min$2(values);
  855. if (p >= 1) return max$3(values);
  856. var n,
  857. i = (n - 1) * p,
  858. i0 = Math.floor(i),
  859. value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
  860. value1 = min$2(values.subarray(i0 + 1));
  861. return value0 + (value1 - value0) * (i - i0);
  862. }
  863. function quantileSorted(values, p, valueof = number$3) {
  864. if (!(n = values.length) || isNaN(p = +p)) return;
  865. if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
  866. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  867. var n,
  868. i = (n - 1) * p,
  869. i0 = Math.floor(i),
  870. value0 = +valueof(values[i0], i0, values),
  871. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  872. return value0 + (value1 - value0) * (i - i0);
  873. }
  874. function quantileIndex(values, p, valueof) {
  875. values = Float64Array.from(numbers(values, valueof));
  876. if (!(n = values.length) || isNaN(p = +p)) return;
  877. if (p <= 0 || n < 2) return minIndex(values);
  878. if (p >= 1) return maxIndex(values);
  879. var n,
  880. i = Math.floor((n - 1) * p),
  881. order = (i, j) => ascendingDefined(values[i], values[j]),
  882. index = quickselect(Uint32Array.from(values, (_, i) => i), i, 0, n - 1, order);
  883. return greatest(index.subarray(0, i + 1), i => values[i]);
  884. }
  885. function thresholdFreedmanDiaconis(values, min, max) {
  886. return Math.ceil((max - min) / (2 * (quantile$1(values, 0.75) - quantile$1(values, 0.25)) * Math.pow(count$1(values), -1 / 3)));
  887. }
  888. function thresholdScott(values, min, max) {
  889. return Math.ceil((max - min) * Math.cbrt(count$1(values)) / (3.49 * deviation(values)));
  890. }
  891. function mean(values, valueof) {
  892. let count = 0;
  893. let sum = 0;
  894. if (valueof === undefined) {
  895. for (let value of values) {
  896. if (value != null && (value = +value) >= value) {
  897. ++count, sum += value;
  898. }
  899. }
  900. } else {
  901. let index = -1;
  902. for (let value of values) {
  903. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  904. ++count, sum += value;
  905. }
  906. }
  907. }
  908. if (count) return sum / count;
  909. }
  910. function median(values, valueof) {
  911. return quantile$1(values, 0.5, valueof);
  912. }
  913. function medianIndex(values, valueof) {
  914. return quantileIndex(values, 0.5, valueof);
  915. }
  916. function* flatten(arrays) {
  917. for (const array of arrays) {
  918. yield* array;
  919. }
  920. }
  921. function merge(arrays) {
  922. return Array.from(flatten(arrays));
  923. }
  924. function mode(values, valueof) {
  925. const counts = new InternMap();
  926. if (valueof === undefined) {
  927. for (let value of values) {
  928. if (value != null && value >= value) {
  929. counts.set(value, (counts.get(value) || 0) + 1);
  930. }
  931. }
  932. } else {
  933. let index = -1;
  934. for (let value of values) {
  935. if ((value = valueof(value, ++index, values)) != null && value >= value) {
  936. counts.set(value, (counts.get(value) || 0) + 1);
  937. }
  938. }
  939. }
  940. let modeValue;
  941. let modeCount = 0;
  942. for (const [value, count] of counts) {
  943. if (count > modeCount) {
  944. modeCount = count;
  945. modeValue = value;
  946. }
  947. }
  948. return modeValue;
  949. }
  950. function pairs(values, pairof = pair) {
  951. const pairs = [];
  952. let previous;
  953. let first = false;
  954. for (const value of values) {
  955. if (first) pairs.push(pairof(previous, value));
  956. previous = value;
  957. first = true;
  958. }
  959. return pairs;
  960. }
  961. function pair(a, b) {
  962. return [a, b];
  963. }
  964. function range$2(start, stop, step) {
  965. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  966. var i = -1,
  967. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  968. range = new Array(n);
  969. while (++i < n) {
  970. range[i] = start + i * step;
  971. }
  972. return range;
  973. }
  974. function rank(values, valueof = ascending$3) {
  975. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  976. let V = Array.from(values);
  977. const R = new Float64Array(V.length);
  978. if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
  979. const compareIndex = (i, j) => valueof(V[i], V[j]);
  980. let k, r;
  981. Uint32Array
  982. .from(V, (_, i) => i)
  983. .sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex))
  984. .forEach((j, i) => {
  985. const c = compareIndex(j, k === undefined ? j : k);
  986. if (c >= 0) {
  987. if (k === undefined || c > 0) k = j, r = i;
  988. R[j] = r;
  989. } else {
  990. R[j] = NaN;
  991. }
  992. });
  993. return R;
  994. }
  995. function least(values, compare = ascending$3) {
  996. let min;
  997. let defined = false;
  998. if (compare.length === 1) {
  999. let minValue;
  1000. for (const element of values) {
  1001. const value = compare(element);
  1002. if (defined
  1003. ? ascending$3(value, minValue) < 0
  1004. : ascending$3(value, value) === 0) {
  1005. min = element;
  1006. minValue = value;
  1007. defined = true;
  1008. }
  1009. }
  1010. } else {
  1011. for (const value of values) {
  1012. if (defined
  1013. ? compare(value, min) < 0
  1014. : compare(value, value) === 0) {
  1015. min = value;
  1016. defined = true;
  1017. }
  1018. }
  1019. }
  1020. return min;
  1021. }
  1022. function leastIndex(values, compare = ascending$3) {
  1023. if (compare.length === 1) return minIndex(values, compare);
  1024. let minValue;
  1025. let min = -1;
  1026. let index = -1;
  1027. for (const value of values) {
  1028. ++index;
  1029. if (min < 0
  1030. ? compare(value, value) === 0
  1031. : compare(value, minValue) < 0) {
  1032. minValue = value;
  1033. min = index;
  1034. }
  1035. }
  1036. return min;
  1037. }
  1038. function greatestIndex(values, compare = ascending$3) {
  1039. if (compare.length === 1) return maxIndex(values, compare);
  1040. let maxValue;
  1041. let max = -1;
  1042. let index = -1;
  1043. for (const value of values) {
  1044. ++index;
  1045. if (max < 0
  1046. ? compare(value, value) === 0
  1047. : compare(value, maxValue) > 0) {
  1048. maxValue = value;
  1049. max = index;
  1050. }
  1051. }
  1052. return max;
  1053. }
  1054. function scan(values, compare) {
  1055. const index = leastIndex(values, compare);
  1056. return index < 0 ? undefined : index;
  1057. }
  1058. var shuffle$1 = shuffler(Math.random);
  1059. function shuffler(random) {
  1060. return function shuffle(array, i0 = 0, i1 = array.length) {
  1061. let m = i1 - (i0 = +i0);
  1062. while (m) {
  1063. const i = random() * m-- | 0, t = array[m + i0];
  1064. array[m + i0] = array[i + i0];
  1065. array[i + i0] = t;
  1066. }
  1067. return array;
  1068. };
  1069. }
  1070. function sum$2(values, valueof) {
  1071. let sum = 0;
  1072. if (valueof === undefined) {
  1073. for (let value of values) {
  1074. if (value = +value) {
  1075. sum += value;
  1076. }
  1077. }
  1078. } else {
  1079. let index = -1;
  1080. for (let value of values) {
  1081. if (value = +valueof(value, ++index, values)) {
  1082. sum += value;
  1083. }
  1084. }
  1085. }
  1086. return sum;
  1087. }
  1088. function transpose(matrix) {
  1089. if (!(n = matrix.length)) return [];
  1090. for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
  1091. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  1092. row[j] = matrix[j][i];
  1093. }
  1094. }
  1095. return transpose;
  1096. }
  1097. function length$2(d) {
  1098. return d.length;
  1099. }
  1100. function zip() {
  1101. return transpose(arguments);
  1102. }
  1103. function every(values, test) {
  1104. if (typeof test !== "function") throw new TypeError("test is not a function");
  1105. let index = -1;
  1106. for (const value of values) {
  1107. if (!test(value, ++index, values)) {
  1108. return false;
  1109. }
  1110. }
  1111. return true;
  1112. }
  1113. function some(values, test) {
  1114. if (typeof test !== "function") throw new TypeError("test is not a function");
  1115. let index = -1;
  1116. for (const value of values) {
  1117. if (test(value, ++index, values)) {
  1118. return true;
  1119. }
  1120. }
  1121. return false;
  1122. }
  1123. function filter$1(values, test) {
  1124. if (typeof test !== "function") throw new TypeError("test is not a function");
  1125. const array = [];
  1126. let index = -1;
  1127. for (const value of values) {
  1128. if (test(value, ++index, values)) {
  1129. array.push(value);
  1130. }
  1131. }
  1132. return array;
  1133. }
  1134. function map$1(values, mapper) {
  1135. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1136. if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
  1137. return Array.from(values, (value, index) => mapper(value, index, values));
  1138. }
  1139. function reduce(values, reducer, value) {
  1140. if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
  1141. const iterator = values[Symbol.iterator]();
  1142. let done, next, index = -1;
  1143. if (arguments.length < 3) {
  1144. ({done, value} = iterator.next());
  1145. if (done) return;
  1146. ++index;
  1147. }
  1148. while (({done, value: next} = iterator.next()), !done) {
  1149. value = reducer(value, next, ++index, values);
  1150. }
  1151. return value;
  1152. }
  1153. function reverse$1(values) {
  1154. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1155. return Array.from(values).reverse();
  1156. }
  1157. function difference(values, ...others) {
  1158. values = new InternSet(values);
  1159. for (const other of others) {
  1160. for (const value of other) {
  1161. values.delete(value);
  1162. }
  1163. }
  1164. return values;
  1165. }
  1166. function disjoint(values, other) {
  1167. const iterator = other[Symbol.iterator](), set = new InternSet();
  1168. for (const v of values) {
  1169. if (set.has(v)) return false;
  1170. let value, done;
  1171. while (({value, done} = iterator.next())) {
  1172. if (done) break;
  1173. if (Object.is(v, value)) return false;
  1174. set.add(value);
  1175. }
  1176. }
  1177. return true;
  1178. }
  1179. function intersection(values, ...others) {
  1180. values = new InternSet(values);
  1181. others = others.map(set$2);
  1182. out: for (const value of values) {
  1183. for (const other of others) {
  1184. if (!other.has(value)) {
  1185. values.delete(value);
  1186. continue out;
  1187. }
  1188. }
  1189. }
  1190. return values;
  1191. }
  1192. function set$2(values) {
  1193. return values instanceof InternSet ? values : new InternSet(values);
  1194. }
  1195. function superset(values, other) {
  1196. const iterator = values[Symbol.iterator](), set = new Set();
  1197. for (const o of other) {
  1198. const io = intern(o);
  1199. if (set.has(io)) continue;
  1200. let value, done;
  1201. while (({value, done} = iterator.next())) {
  1202. if (done) return false;
  1203. const ivalue = intern(value);
  1204. set.add(ivalue);
  1205. if (Object.is(io, ivalue)) break;
  1206. }
  1207. }
  1208. return true;
  1209. }
  1210. function intern(value) {
  1211. return value !== null && typeof value === "object" ? value.valueOf() : value;
  1212. }
  1213. function subset(values, other) {
  1214. return superset(other, values);
  1215. }
  1216. function union(...others) {
  1217. const set = new InternSet();
  1218. for (const other of others) {
  1219. for (const o of other) {
  1220. set.add(o);
  1221. }
  1222. }
  1223. return set;
  1224. }
  1225. function identity$8(x) {
  1226. return x;
  1227. }
  1228. var top = 1,
  1229. right = 2,
  1230. bottom = 3,
  1231. left = 4,
  1232. epsilon$6 = 1e-6;
  1233. function translateX(x) {
  1234. return "translate(" + x + ",0)";
  1235. }
  1236. function translateY(y) {
  1237. return "translate(0," + y + ")";
  1238. }
  1239. function number$2(scale) {
  1240. return d => +scale(d);
  1241. }
  1242. function center$1(scale, offset) {
  1243. offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
  1244. if (scale.round()) offset = Math.round(offset);
  1245. return d => +scale(d) + offset;
  1246. }
  1247. function entering() {
  1248. return !this.__axis;
  1249. }
  1250. function axis(orient, scale) {
  1251. var tickArguments = [],
  1252. tickValues = null,
  1253. tickFormat = null,
  1254. tickSizeInner = 6,
  1255. tickSizeOuter = 6,
  1256. tickPadding = 3,
  1257. offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
  1258. k = orient === top || orient === left ? -1 : 1,
  1259. x = orient === left || orient === right ? "x" : "y",
  1260. transform = orient === top || orient === bottom ? translateX : translateY;
  1261. function axis(context) {
  1262. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  1263. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
  1264. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  1265. range = scale.range(),
  1266. range0 = +range[0] + offset,
  1267. range1 = +range[range.length - 1] + offset,
  1268. position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
  1269. selection = context.selection ? context.selection() : context,
  1270. path = selection.selectAll(".domain").data([null]),
  1271. tick = selection.selectAll(".tick").data(values, scale).order(),
  1272. tickExit = tick.exit(),
  1273. tickEnter = tick.enter().append("g").attr("class", "tick"),
  1274. line = tick.select("line"),
  1275. text = tick.select("text");
  1276. path = path.merge(path.enter().insert("path", ".tick")
  1277. .attr("class", "domain")
  1278. .attr("stroke", "currentColor"));
  1279. tick = tick.merge(tickEnter);
  1280. line = line.merge(tickEnter.append("line")
  1281. .attr("stroke", "currentColor")
  1282. .attr(x + "2", k * tickSizeInner));
  1283. text = text.merge(tickEnter.append("text")
  1284. .attr("fill", "currentColor")
  1285. .attr(x, k * spacing)
  1286. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  1287. if (context !== selection) {
  1288. path = path.transition(context);
  1289. tick = tick.transition(context);
  1290. line = line.transition(context);
  1291. text = text.transition(context);
  1292. tickExit = tickExit.transition(context)
  1293. .attr("opacity", epsilon$6)
  1294. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
  1295. tickEnter
  1296. .attr("opacity", epsilon$6)
  1297. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
  1298. }
  1299. tickExit.remove();
  1300. path
  1301. .attr("d", orient === left || orient === right
  1302. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
  1303. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
  1304. tick
  1305. .attr("opacity", 1)
  1306. .attr("transform", function(d) { return transform(position(d) + offset); });
  1307. line
  1308. .attr(x + "2", k * tickSizeInner);
  1309. text
  1310. .attr(x, k * spacing)
  1311. .text(format);
  1312. selection.filter(entering)
  1313. .attr("fill", "none")
  1314. .attr("font-size", 10)
  1315. .attr("font-family", "sans-serif")
  1316. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  1317. selection
  1318. .each(function() { this.__axis = position; });
  1319. }
  1320. axis.scale = function(_) {
  1321. return arguments.length ? (scale = _, axis) : scale;
  1322. };
  1323. axis.ticks = function() {
  1324. return tickArguments = Array.from(arguments), axis;
  1325. };
  1326. axis.tickArguments = function(_) {
  1327. return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
  1328. };
  1329. axis.tickValues = function(_) {
  1330. return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
  1331. };
  1332. axis.tickFormat = function(_) {
  1333. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  1334. };
  1335. axis.tickSize = function(_) {
  1336. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  1337. };
  1338. axis.tickSizeInner = function(_) {
  1339. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  1340. };
  1341. axis.tickSizeOuter = function(_) {
  1342. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  1343. };
  1344. axis.tickPadding = function(_) {
  1345. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  1346. };
  1347. axis.offset = function(_) {
  1348. return arguments.length ? (offset = +_, axis) : offset;
  1349. };
  1350. return axis;
  1351. }
  1352. function axisTop(scale) {
  1353. return axis(top, scale);
  1354. }
  1355. function axisRight(scale) {
  1356. return axis(right, scale);
  1357. }
  1358. function axisBottom(scale) {
  1359. return axis(bottom, scale);
  1360. }
  1361. function axisLeft(scale) {
  1362. return axis(left, scale);
  1363. }
  1364. var noop$3 = {value: () => {}};
  1365. function dispatch() {
  1366. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  1367. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  1368. _[t] = [];
  1369. }
  1370. return new Dispatch(_);
  1371. }
  1372. function Dispatch(_) {
  1373. this._ = _;
  1374. }
  1375. function parseTypenames$1(typenames, types) {
  1376. return typenames.trim().split(/^|\s+/).map(function(t) {
  1377. var name = "", i = t.indexOf(".");
  1378. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1379. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  1380. return {type: t, name: name};
  1381. });
  1382. }
  1383. Dispatch.prototype = dispatch.prototype = {
  1384. constructor: Dispatch,
  1385. on: function(typename, callback) {
  1386. var _ = this._,
  1387. T = parseTypenames$1(typename + "", _),
  1388. t,
  1389. i = -1,
  1390. n = T.length;
  1391. // If no callback was specified, return the callback of the given type and name.
  1392. if (arguments.length < 2) {
  1393. while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
  1394. return;
  1395. }
  1396. // If a type was specified, set the callback for the given type and name.
  1397. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  1398. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  1399. while (++i < n) {
  1400. if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
  1401. else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
  1402. }
  1403. return this;
  1404. },
  1405. copy: function() {
  1406. var copy = {}, _ = this._;
  1407. for (var t in _) copy[t] = _[t].slice();
  1408. return new Dispatch(copy);
  1409. },
  1410. call: function(type, that) {
  1411. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  1412. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1413. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1414. },
  1415. apply: function(type, that, args) {
  1416. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1417. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1418. }
  1419. };
  1420. function get$1(type, name) {
  1421. for (var i = 0, n = type.length, c; i < n; ++i) {
  1422. if ((c = type[i]).name === name) {
  1423. return c.value;
  1424. }
  1425. }
  1426. }
  1427. function set$1(type, name, callback) {
  1428. for (var i = 0, n = type.length; i < n; ++i) {
  1429. if (type[i].name === name) {
  1430. type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
  1431. break;
  1432. }
  1433. }
  1434. if (callback != null) type.push({name: name, value: callback});
  1435. return type;
  1436. }
  1437. var xhtml = "http://www.w3.org/1999/xhtml";
  1438. var namespaces = {
  1439. svg: "http://www.w3.org/2000/svg",
  1440. xhtml: xhtml,
  1441. xlink: "http://www.w3.org/1999/xlink",
  1442. xml: "http://www.w3.org/XML/1998/namespace",
  1443. xmlns: "http://www.w3.org/2000/xmlns/"
  1444. };
  1445. function namespace(name) {
  1446. var prefix = name += "", i = prefix.indexOf(":");
  1447. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  1448. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
  1449. }
  1450. function creatorInherit(name) {
  1451. return function() {
  1452. var document = this.ownerDocument,
  1453. uri = this.namespaceURI;
  1454. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  1455. ? document.createElement(name)
  1456. : document.createElementNS(uri, name);
  1457. };
  1458. }
  1459. function creatorFixed(fullname) {
  1460. return function() {
  1461. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  1462. };
  1463. }
  1464. function creator(name) {
  1465. var fullname = namespace(name);
  1466. return (fullname.local
  1467. ? creatorFixed
  1468. : creatorInherit)(fullname);
  1469. }
  1470. function none$2() {}
  1471. function selector(selector) {
  1472. return selector == null ? none$2 : function() {
  1473. return this.querySelector(selector);
  1474. };
  1475. }
  1476. function selection_select(select) {
  1477. if (typeof select !== "function") select = selector(select);
  1478. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1479. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  1480. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  1481. if ("__data__" in node) subnode.__data__ = node.__data__;
  1482. subgroup[i] = subnode;
  1483. }
  1484. }
  1485. }
  1486. return new Selection$1(subgroups, this._parents);
  1487. }
  1488. // Given something array like (or null), returns something that is strictly an
  1489. // array. This is used to ensure that array-like objects passed to d3.selectAll
  1490. // or selection.selectAll are converted into proper arrays when creating a
  1491. // selection; we don’t ever want to create a selection backed by a live
  1492. // HTMLCollection or NodeList. However, note that selection.selectAll will use a
  1493. // static NodeList as a group, since it safely derived from querySelectorAll.
  1494. function array$4(x) {
  1495. return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
  1496. }
  1497. function empty$1() {
  1498. return [];
  1499. }
  1500. function selectorAll(selector) {
  1501. return selector == null ? empty$1 : function() {
  1502. return this.querySelectorAll(selector);
  1503. };
  1504. }
  1505. function arrayAll(select) {
  1506. return function() {
  1507. return array$4(select.apply(this, arguments));
  1508. };
  1509. }
  1510. function selection_selectAll(select) {
  1511. if (typeof select === "function") select = arrayAll(select);
  1512. else select = selectorAll(select);
  1513. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  1514. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  1515. if (node = group[i]) {
  1516. subgroups.push(select.call(node, node.__data__, i, group));
  1517. parents.push(node);
  1518. }
  1519. }
  1520. }
  1521. return new Selection$1(subgroups, parents);
  1522. }
  1523. function matcher(selector) {
  1524. return function() {
  1525. return this.matches(selector);
  1526. };
  1527. }
  1528. function childMatcher(selector) {
  1529. return function(node) {
  1530. return node.matches(selector);
  1531. };
  1532. }
  1533. var find$1 = Array.prototype.find;
  1534. function childFind(match) {
  1535. return function() {
  1536. return find$1.call(this.children, match);
  1537. };
  1538. }
  1539. function childFirst() {
  1540. return this.firstElementChild;
  1541. }
  1542. function selection_selectChild(match) {
  1543. return this.select(match == null ? childFirst
  1544. : childFind(typeof match === "function" ? match : childMatcher(match)));
  1545. }
  1546. var filter = Array.prototype.filter;
  1547. function children() {
  1548. return Array.from(this.children);
  1549. }
  1550. function childrenFilter(match) {
  1551. return function() {
  1552. return filter.call(this.children, match);
  1553. };
  1554. }
  1555. function selection_selectChildren(match) {
  1556. return this.selectAll(match == null ? children
  1557. : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
  1558. }
  1559. function selection_filter(match) {
  1560. if (typeof match !== "function") match = matcher(match);
  1561. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1562. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  1563. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  1564. subgroup.push(node);
  1565. }
  1566. }
  1567. }
  1568. return new Selection$1(subgroups, this._parents);
  1569. }
  1570. function sparse(update) {
  1571. return new Array(update.length);
  1572. }
  1573. function selection_enter() {
  1574. return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
  1575. }
  1576. function EnterNode(parent, datum) {
  1577. this.ownerDocument = parent.ownerDocument;
  1578. this.namespaceURI = parent.namespaceURI;
  1579. this._next = null;
  1580. this._parent = parent;
  1581. this.__data__ = datum;
  1582. }
  1583. EnterNode.prototype = {
  1584. constructor: EnterNode,
  1585. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  1586. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  1587. querySelector: function(selector) { return this._parent.querySelector(selector); },
  1588. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  1589. };
  1590. function constant$a(x) {
  1591. return function() {
  1592. return x;
  1593. };
  1594. }
  1595. function bindIndex(parent, group, enter, update, exit, data) {
  1596. var i = 0,
  1597. node,
  1598. groupLength = group.length,
  1599. dataLength = data.length;
  1600. // Put any non-null nodes that fit into update.
  1601. // Put any null nodes into enter.
  1602. // Put any remaining data into enter.
  1603. for (; i < dataLength; ++i) {
  1604. if (node = group[i]) {
  1605. node.__data__ = data[i];
  1606. update[i] = node;
  1607. } else {
  1608. enter[i] = new EnterNode(parent, data[i]);
  1609. }
  1610. }
  1611. // Put any non-null nodes that don’t fit into exit.
  1612. for (; i < groupLength; ++i) {
  1613. if (node = group[i]) {
  1614. exit[i] = node;
  1615. }
  1616. }
  1617. }
  1618. function bindKey(parent, group, enter, update, exit, data, key) {
  1619. var i,
  1620. node,
  1621. nodeByKeyValue = new Map,
  1622. groupLength = group.length,
  1623. dataLength = data.length,
  1624. keyValues = new Array(groupLength),
  1625. keyValue;
  1626. // Compute the key for each node.
  1627. // If multiple nodes have the same key, the duplicates are added to exit.
  1628. for (i = 0; i < groupLength; ++i) {
  1629. if (node = group[i]) {
  1630. keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
  1631. if (nodeByKeyValue.has(keyValue)) {
  1632. exit[i] = node;
  1633. } else {
  1634. nodeByKeyValue.set(keyValue, node);
  1635. }
  1636. }
  1637. }
  1638. // Compute the key for each datum.
  1639. // If there a node associated with this key, join and add it to update.
  1640. // If there is not (or the key is a duplicate), add it to enter.
  1641. for (i = 0; i < dataLength; ++i) {
  1642. keyValue = key.call(parent, data[i], i, data) + "";
  1643. if (node = nodeByKeyValue.get(keyValue)) {
  1644. update[i] = node;
  1645. node.__data__ = data[i];
  1646. nodeByKeyValue.delete(keyValue);
  1647. } else {
  1648. enter[i] = new EnterNode(parent, data[i]);
  1649. }
  1650. }
  1651. // Add any remaining nodes that were not bound to data to exit.
  1652. for (i = 0; i < groupLength; ++i) {
  1653. if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
  1654. exit[i] = node;
  1655. }
  1656. }
  1657. }
  1658. function datum(node) {
  1659. return node.__data__;
  1660. }
  1661. function selection_data(value, key) {
  1662. if (!arguments.length) return Array.from(this, datum);
  1663. var bind = key ? bindKey : bindIndex,
  1664. parents = this._parents,
  1665. groups = this._groups;
  1666. if (typeof value !== "function") value = constant$a(value);
  1667. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1668. var parent = parents[j],
  1669. group = groups[j],
  1670. groupLength = group.length,
  1671. data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
  1672. dataLength = data.length,
  1673. enterGroup = enter[j] = new Array(dataLength),
  1674. updateGroup = update[j] = new Array(dataLength),
  1675. exitGroup = exit[j] = new Array(groupLength);
  1676. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1677. // Now connect the enter nodes to their following update node, such that
  1678. // appendChild can insert the materialized enter node before this node,
  1679. // rather than at the end of the parent node.
  1680. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1681. if (previous = enterGroup[i0]) {
  1682. if (i0 >= i1) i1 = i0 + 1;
  1683. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1684. previous._next = next || null;
  1685. }
  1686. }
  1687. }
  1688. update = new Selection$1(update, parents);
  1689. update._enter = enter;
  1690. update._exit = exit;
  1691. return update;
  1692. }
  1693. // Given some data, this returns an array-like view of it: an object that
  1694. // exposes a length property and allows numeric indexing. Note that unlike
  1695. // selectAll, this isn’t worried about “live” collections because the resulting
  1696. // array will only be used briefly while data is being bound. (It is possible to
  1697. // cause the data to change while iterating by using a key function, but please
  1698. // don’t; we’d rather avoid a gratuitous copy.)
  1699. function arraylike(data) {
  1700. return typeof data === "object" && "length" in data
  1701. ? data // Array, TypedArray, NodeList, array-like
  1702. : Array.from(data); // Map, Set, iterable, string, or anything else
  1703. }
  1704. function selection_exit() {
  1705. return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
  1706. }
  1707. function selection_join(onenter, onupdate, onexit) {
  1708. var enter = this.enter(), update = this, exit = this.exit();
  1709. if (typeof onenter === "function") {
  1710. enter = onenter(enter);
  1711. if (enter) enter = enter.selection();
  1712. } else {
  1713. enter = enter.append(onenter + "");
  1714. }
  1715. if (onupdate != null) {
  1716. update = onupdate(update);
  1717. if (update) update = update.selection();
  1718. }
  1719. if (onexit == null) exit.remove(); else onexit(exit);
  1720. return enter && update ? enter.merge(update).order() : update;
  1721. }
  1722. function selection_merge(context) {
  1723. var selection = context.selection ? context.selection() : context;
  1724. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1725. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1726. if (node = group0[i] || group1[i]) {
  1727. merge[i] = node;
  1728. }
  1729. }
  1730. }
  1731. for (; j < m0; ++j) {
  1732. merges[j] = groups0[j];
  1733. }
  1734. return new Selection$1(merges, this._parents);
  1735. }
  1736. function selection_order() {
  1737. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1738. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1739. if (node = group[i]) {
  1740. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  1741. next = node;
  1742. }
  1743. }
  1744. }
  1745. return this;
  1746. }
  1747. function selection_sort(compare) {
  1748. if (!compare) compare = ascending$2;
  1749. function compareNode(a, b) {
  1750. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1751. }
  1752. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1753. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1754. if (node = group[i]) {
  1755. sortgroup[i] = node;
  1756. }
  1757. }
  1758. sortgroup.sort(compareNode);
  1759. }
  1760. return new Selection$1(sortgroups, this._parents).order();
  1761. }
  1762. function ascending$2(a, b) {
  1763. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1764. }
  1765. function selection_call() {
  1766. var callback = arguments[0];
  1767. arguments[0] = this;
  1768. callback.apply(null, arguments);
  1769. return this;
  1770. }
  1771. function selection_nodes() {
  1772. return Array.from(this);
  1773. }
  1774. function selection_node() {
  1775. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1776. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1777. var node = group[i];
  1778. if (node) return node;
  1779. }
  1780. }
  1781. return null;
  1782. }
  1783. function selection_size() {
  1784. let size = 0;
  1785. for (const node of this) ++size; // eslint-disable-line no-unused-vars
  1786. return size;
  1787. }
  1788. function selection_empty() {
  1789. return !this.node();
  1790. }
  1791. function selection_each(callback) {
  1792. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1793. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1794. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1795. }
  1796. }
  1797. return this;
  1798. }
  1799. function attrRemove$1(name) {
  1800. return function() {
  1801. this.removeAttribute(name);
  1802. };
  1803. }
  1804. function attrRemoveNS$1(fullname) {
  1805. return function() {
  1806. this.removeAttributeNS(fullname.space, fullname.local);
  1807. };
  1808. }
  1809. function attrConstant$1(name, value) {
  1810. return function() {
  1811. this.setAttribute(name, value);
  1812. };
  1813. }
  1814. function attrConstantNS$1(fullname, value) {
  1815. return function() {
  1816. this.setAttributeNS(fullname.space, fullname.local, value);
  1817. };
  1818. }
  1819. function attrFunction$1(name, value) {
  1820. return function() {
  1821. var v = value.apply(this, arguments);
  1822. if (v == null) this.removeAttribute(name);
  1823. else this.setAttribute(name, v);
  1824. };
  1825. }
  1826. function attrFunctionNS$1(fullname, value) {
  1827. return function() {
  1828. var v = value.apply(this, arguments);
  1829. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1830. else this.setAttributeNS(fullname.space, fullname.local, v);
  1831. };
  1832. }
  1833. function selection_attr(name, value) {
  1834. var fullname = namespace(name);
  1835. if (arguments.length < 2) {
  1836. var node = this.node();
  1837. return fullname.local
  1838. ? node.getAttributeNS(fullname.space, fullname.local)
  1839. : node.getAttribute(fullname);
  1840. }
  1841. return this.each((value == null
  1842. ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
  1843. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
  1844. : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
  1845. }
  1846. function defaultView(node) {
  1847. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1848. || (node.document && node) // node is a Window
  1849. || node.defaultView; // node is a Document
  1850. }
  1851. function styleRemove$1(name) {
  1852. return function() {
  1853. this.style.removeProperty(name);
  1854. };
  1855. }
  1856. function styleConstant$1(name, value, priority) {
  1857. return function() {
  1858. this.style.setProperty(name, value, priority);
  1859. };
  1860. }
  1861. function styleFunction$1(name, value, priority) {
  1862. return function() {
  1863. var v = value.apply(this, arguments);
  1864. if (v == null) this.style.removeProperty(name);
  1865. else this.style.setProperty(name, v, priority);
  1866. };
  1867. }
  1868. function selection_style(name, value, priority) {
  1869. return arguments.length > 1
  1870. ? this.each((value == null
  1871. ? styleRemove$1 : typeof value === "function"
  1872. ? styleFunction$1
  1873. : styleConstant$1)(name, value, priority == null ? "" : priority))
  1874. : styleValue(this.node(), name);
  1875. }
  1876. function styleValue(node, name) {
  1877. return node.style.getPropertyValue(name)
  1878. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1879. }
  1880. function propertyRemove(name) {
  1881. return function() {
  1882. delete this[name];
  1883. };
  1884. }
  1885. function propertyConstant(name, value) {
  1886. return function() {
  1887. this[name] = value;
  1888. };
  1889. }
  1890. function propertyFunction(name, value) {
  1891. return function() {
  1892. var v = value.apply(this, arguments);
  1893. if (v == null) delete this[name];
  1894. else this[name] = v;
  1895. };
  1896. }
  1897. function selection_property(name, value) {
  1898. return arguments.length > 1
  1899. ? this.each((value == null
  1900. ? propertyRemove : typeof value === "function"
  1901. ? propertyFunction
  1902. : propertyConstant)(name, value))
  1903. : this.node()[name];
  1904. }
  1905. function classArray(string) {
  1906. return string.trim().split(/^|\s+/);
  1907. }
  1908. function classList(node) {
  1909. return node.classList || new ClassList(node);
  1910. }
  1911. function ClassList(node) {
  1912. this._node = node;
  1913. this._names = classArray(node.getAttribute("class") || "");
  1914. }
  1915. ClassList.prototype = {
  1916. add: function(name) {
  1917. var i = this._names.indexOf(name);
  1918. if (i < 0) {
  1919. this._names.push(name);
  1920. this._node.setAttribute("class", this._names.join(" "));
  1921. }
  1922. },
  1923. remove: function(name) {
  1924. var i = this._names.indexOf(name);
  1925. if (i >= 0) {
  1926. this._names.splice(i, 1);
  1927. this._node.setAttribute("class", this._names.join(" "));
  1928. }
  1929. },
  1930. contains: function(name) {
  1931. return this._names.indexOf(name) >= 0;
  1932. }
  1933. };
  1934. function classedAdd(node, names) {
  1935. var list = classList(node), i = -1, n = names.length;
  1936. while (++i < n) list.add(names[i]);
  1937. }
  1938. function classedRemove(node, names) {
  1939. var list = classList(node), i = -1, n = names.length;
  1940. while (++i < n) list.remove(names[i]);
  1941. }
  1942. function classedTrue(names) {
  1943. return function() {
  1944. classedAdd(this, names);
  1945. };
  1946. }
  1947. function classedFalse(names) {
  1948. return function() {
  1949. classedRemove(this, names);
  1950. };
  1951. }
  1952. function classedFunction(names, value) {
  1953. return function() {
  1954. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1955. };
  1956. }
  1957. function selection_classed(name, value) {
  1958. var names = classArray(name + "");
  1959. if (arguments.length < 2) {
  1960. var list = classList(this.node()), i = -1, n = names.length;
  1961. while (++i < n) if (!list.contains(names[i])) return false;
  1962. return true;
  1963. }
  1964. return this.each((typeof value === "function"
  1965. ? classedFunction : value
  1966. ? classedTrue
  1967. : classedFalse)(names, value));
  1968. }
  1969. function textRemove() {
  1970. this.textContent = "";
  1971. }
  1972. function textConstant$1(value) {
  1973. return function() {
  1974. this.textContent = value;
  1975. };
  1976. }
  1977. function textFunction$1(value) {
  1978. return function() {
  1979. var v = value.apply(this, arguments);
  1980. this.textContent = v == null ? "" : v;
  1981. };
  1982. }
  1983. function selection_text(value) {
  1984. return arguments.length
  1985. ? this.each(value == null
  1986. ? textRemove : (typeof value === "function"
  1987. ? textFunction$1
  1988. : textConstant$1)(value))
  1989. : this.node().textContent;
  1990. }
  1991. function htmlRemove() {
  1992. this.innerHTML = "";
  1993. }
  1994. function htmlConstant(value) {
  1995. return function() {
  1996. this.innerHTML = value;
  1997. };
  1998. }
  1999. function htmlFunction(value) {
  2000. return function() {
  2001. var v = value.apply(this, arguments);
  2002. this.innerHTML = v == null ? "" : v;
  2003. };
  2004. }
  2005. function selection_html(value) {
  2006. return arguments.length
  2007. ? this.each(value == null
  2008. ? htmlRemove : (typeof value === "function"
  2009. ? htmlFunction
  2010. : htmlConstant)(value))
  2011. : this.node().innerHTML;
  2012. }
  2013. function raise() {
  2014. if (this.nextSibling) this.parentNode.appendChild(this);
  2015. }
  2016. function selection_raise() {
  2017. return this.each(raise);
  2018. }
  2019. function lower() {
  2020. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  2021. }
  2022. function selection_lower() {
  2023. return this.each(lower);
  2024. }
  2025. function selection_append(name) {
  2026. var create = typeof name === "function" ? name : creator(name);
  2027. return this.select(function() {
  2028. return this.appendChild(create.apply(this, arguments));
  2029. });
  2030. }
  2031. function constantNull() {
  2032. return null;
  2033. }
  2034. function selection_insert(name, before) {
  2035. var create = typeof name === "function" ? name : creator(name),
  2036. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  2037. return this.select(function() {
  2038. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  2039. });
  2040. }
  2041. function remove() {
  2042. var parent = this.parentNode;
  2043. if (parent) parent.removeChild(this);
  2044. }
  2045. function selection_remove() {
  2046. return this.each(remove);
  2047. }
  2048. function selection_cloneShallow() {
  2049. var clone = this.cloneNode(false), parent = this.parentNode;
  2050. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2051. }
  2052. function selection_cloneDeep() {
  2053. var clone = this.cloneNode(true), parent = this.parentNode;
  2054. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2055. }
  2056. function selection_clone(deep) {
  2057. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  2058. }
  2059. function selection_datum(value) {
  2060. return arguments.length
  2061. ? this.property("__data__", value)
  2062. : this.node().__data__;
  2063. }
  2064. function contextListener(listener) {
  2065. return function(event) {
  2066. listener.call(this, event, this.__data__);
  2067. };
  2068. }
  2069. function parseTypenames(typenames) {
  2070. return typenames.trim().split(/^|\s+/).map(function(t) {
  2071. var name = "", i = t.indexOf(".");
  2072. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  2073. return {type: t, name: name};
  2074. });
  2075. }
  2076. function onRemove(typename) {
  2077. return function() {
  2078. var on = this.__on;
  2079. if (!on) return;
  2080. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  2081. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  2082. this.removeEventListener(o.type, o.listener, o.options);
  2083. } else {
  2084. on[++i] = o;
  2085. }
  2086. }
  2087. if (++i) on.length = i;
  2088. else delete this.__on;
  2089. };
  2090. }
  2091. function onAdd(typename, value, options) {
  2092. return function() {
  2093. var on = this.__on, o, listener = contextListener(value);
  2094. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  2095. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  2096. this.removeEventListener(o.type, o.listener, o.options);
  2097. this.addEventListener(o.type, o.listener = listener, o.options = options);
  2098. o.value = value;
  2099. return;
  2100. }
  2101. }
  2102. this.addEventListener(typename.type, listener, options);
  2103. o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
  2104. if (!on) this.__on = [o];
  2105. else on.push(o);
  2106. };
  2107. }
  2108. function selection_on(typename, value, options) {
  2109. var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
  2110. if (arguments.length < 2) {
  2111. var on = this.node().__on;
  2112. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  2113. for (i = 0, o = on[j]; i < n; ++i) {
  2114. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  2115. return o.value;
  2116. }
  2117. }
  2118. }
  2119. return;
  2120. }
  2121. on = value ? onAdd : onRemove;
  2122. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
  2123. return this;
  2124. }
  2125. function dispatchEvent(node, type, params) {
  2126. var window = defaultView(node),
  2127. event = window.CustomEvent;
  2128. if (typeof event === "function") {
  2129. event = new event(type, params);
  2130. } else {
  2131. event = window.document.createEvent("Event");
  2132. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  2133. else event.initEvent(type, false, false);
  2134. }
  2135. node.dispatchEvent(event);
  2136. }
  2137. function dispatchConstant(type, params) {
  2138. return function() {
  2139. return dispatchEvent(this, type, params);
  2140. };
  2141. }
  2142. function dispatchFunction(type, params) {
  2143. return function() {
  2144. return dispatchEvent(this, type, params.apply(this, arguments));
  2145. };
  2146. }
  2147. function selection_dispatch(type, params) {
  2148. return this.each((typeof params === "function"
  2149. ? dispatchFunction
  2150. : dispatchConstant)(type, params));
  2151. }
  2152. function* selection_iterator() {
  2153. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  2154. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  2155. if (node = group[i]) yield node;
  2156. }
  2157. }
  2158. }
  2159. var root$1 = [null];
  2160. function Selection$1(groups, parents) {
  2161. this._groups = groups;
  2162. this._parents = parents;
  2163. }
  2164. function selection() {
  2165. return new Selection$1([[document.documentElement]], root$1);
  2166. }
  2167. function selection_selection() {
  2168. return this;
  2169. }
  2170. Selection$1.prototype = selection.prototype = {
  2171. constructor: Selection$1,
  2172. select: selection_select,
  2173. selectAll: selection_selectAll,
  2174. selectChild: selection_selectChild,
  2175. selectChildren: selection_selectChildren,
  2176. filter: selection_filter,
  2177. data: selection_data,
  2178. enter: selection_enter,
  2179. exit: selection_exit,
  2180. join: selection_join,
  2181. merge: selection_merge,
  2182. selection: selection_selection,
  2183. order: selection_order,
  2184. sort: selection_sort,
  2185. call: selection_call,
  2186. nodes: selection_nodes,
  2187. node: selection_node,
  2188. size: selection_size,
  2189. empty: selection_empty,
  2190. each: selection_each,
  2191. attr: selection_attr,
  2192. style: selection_style,
  2193. property: selection_property,
  2194. classed: selection_classed,
  2195. text: selection_text,
  2196. html: selection_html,
  2197. raise: selection_raise,
  2198. lower: selection_lower,
  2199. append: selection_append,
  2200. insert: selection_insert,
  2201. remove: selection_remove,
  2202. clone: selection_clone,
  2203. datum: selection_datum,
  2204. on: selection_on,
  2205. dispatch: selection_dispatch,
  2206. [Symbol.iterator]: selection_iterator
  2207. };
  2208. function select(selector) {
  2209. return typeof selector === "string"
  2210. ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
  2211. : new Selection$1([[selector]], root$1);
  2212. }
  2213. function create$1(name) {
  2214. return select(creator(name).call(document.documentElement));
  2215. }
  2216. var nextId = 0;
  2217. function local$1() {
  2218. return new Local;
  2219. }
  2220. function Local() {
  2221. this._ = "@" + (++nextId).toString(36);
  2222. }
  2223. Local.prototype = local$1.prototype = {
  2224. constructor: Local,
  2225. get: function(node) {
  2226. var id = this._;
  2227. while (!(id in node)) if (!(node = node.parentNode)) return;
  2228. return node[id];
  2229. },
  2230. set: function(node, value) {
  2231. return node[this._] = value;
  2232. },
  2233. remove: function(node) {
  2234. return this._ in node && delete node[this._];
  2235. },
  2236. toString: function() {
  2237. return this._;
  2238. }
  2239. };
  2240. function sourceEvent(event) {
  2241. let sourceEvent;
  2242. while (sourceEvent = event.sourceEvent) event = sourceEvent;
  2243. return event;
  2244. }
  2245. function pointer(event, node) {
  2246. event = sourceEvent(event);
  2247. if (node === undefined) node = event.currentTarget;
  2248. if (node) {
  2249. var svg = node.ownerSVGElement || node;
  2250. if (svg.createSVGPoint) {
  2251. var point = svg.createSVGPoint();
  2252. point.x = event.clientX, point.y = event.clientY;
  2253. point = point.matrixTransform(node.getScreenCTM().inverse());
  2254. return [point.x, point.y];
  2255. }
  2256. if (node.getBoundingClientRect) {
  2257. var rect = node.getBoundingClientRect();
  2258. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  2259. }
  2260. }
  2261. return [event.pageX, event.pageY];
  2262. }
  2263. function pointers(events, node) {
  2264. if (events.target) { // i.e., instanceof Event, not TouchList or iterable
  2265. events = sourceEvent(events);
  2266. if (node === undefined) node = events.currentTarget;
  2267. events = events.touches || [events];
  2268. }
  2269. return Array.from(events, event => pointer(event, node));
  2270. }
  2271. function selectAll(selector) {
  2272. return typeof selector === "string"
  2273. ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
  2274. : new Selection$1([array$4(selector)], root$1);
  2275. }
  2276. // These are typically used in conjunction with noevent to ensure that we can
  2277. // preventDefault on the event.
  2278. const nonpassive = {passive: false};
  2279. const nonpassivecapture = {capture: true, passive: false};
  2280. function nopropagation$2(event) {
  2281. event.stopImmediatePropagation();
  2282. }
  2283. function noevent$2(event) {
  2284. event.preventDefault();
  2285. event.stopImmediatePropagation();
  2286. }
  2287. function dragDisable(view) {
  2288. var root = view.document.documentElement,
  2289. selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture);
  2290. if ("onselectstart" in root) {
  2291. selection.on("selectstart.drag", noevent$2, nonpassivecapture);
  2292. } else {
  2293. root.__noselect = root.style.MozUserSelect;
  2294. root.style.MozUserSelect = "none";
  2295. }
  2296. }
  2297. function yesdrag(view, noclick) {
  2298. var root = view.document.documentElement,
  2299. selection = select(view).on("dragstart.drag", null);
  2300. if (noclick) {
  2301. selection.on("click.drag", noevent$2, nonpassivecapture);
  2302. setTimeout(function() { selection.on("click.drag", null); }, 0);
  2303. }
  2304. if ("onselectstart" in root) {
  2305. selection.on("selectstart.drag", null);
  2306. } else {
  2307. root.style.MozUserSelect = root.__noselect;
  2308. delete root.__noselect;
  2309. }
  2310. }
  2311. var constant$9 = x => () => x;
  2312. function DragEvent(type, {
  2313. sourceEvent,
  2314. subject,
  2315. target,
  2316. identifier,
  2317. active,
  2318. x, y, dx, dy,
  2319. dispatch
  2320. }) {
  2321. Object.defineProperties(this, {
  2322. type: {value: type, enumerable: true, configurable: true},
  2323. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  2324. subject: {value: subject, enumerable: true, configurable: true},
  2325. target: {value: target, enumerable: true, configurable: true},
  2326. identifier: {value: identifier, enumerable: true, configurable: true},
  2327. active: {value: active, enumerable: true, configurable: true},
  2328. x: {value: x, enumerable: true, configurable: true},
  2329. y: {value: y, enumerable: true, configurable: true},
  2330. dx: {value: dx, enumerable: true, configurable: true},
  2331. dy: {value: dy, enumerable: true, configurable: true},
  2332. _: {value: dispatch}
  2333. });
  2334. }
  2335. DragEvent.prototype.on = function() {
  2336. var value = this._.on.apply(this._, arguments);
  2337. return value === this._ ? this : value;
  2338. };
  2339. // Ignore right-click, since that should open the context menu.
  2340. function defaultFilter$2(event) {
  2341. return !event.ctrlKey && !event.button;
  2342. }
  2343. function defaultContainer() {
  2344. return this.parentNode;
  2345. }
  2346. function defaultSubject(event, d) {
  2347. return d == null ? {x: event.x, y: event.y} : d;
  2348. }
  2349. function defaultTouchable$2() {
  2350. return navigator.maxTouchPoints || ("ontouchstart" in this);
  2351. }
  2352. function drag() {
  2353. var filter = defaultFilter$2,
  2354. container = defaultContainer,
  2355. subject = defaultSubject,
  2356. touchable = defaultTouchable$2,
  2357. gestures = {},
  2358. listeners = dispatch("start", "drag", "end"),
  2359. active = 0,
  2360. mousedownx,
  2361. mousedowny,
  2362. mousemoving,
  2363. touchending,
  2364. clickDistance2 = 0;
  2365. function drag(selection) {
  2366. selection
  2367. .on("mousedown.drag", mousedowned)
  2368. .filter(touchable)
  2369. .on("touchstart.drag", touchstarted)
  2370. .on("touchmove.drag", touchmoved, nonpassive)
  2371. .on("touchend.drag touchcancel.drag", touchended)
  2372. .style("touch-action", "none")
  2373. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  2374. }
  2375. function mousedowned(event, d) {
  2376. if (touchending || !filter.call(this, event, d)) return;
  2377. var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
  2378. if (!gesture) return;
  2379. select(event.view)
  2380. .on("mousemove.drag", mousemoved, nonpassivecapture)
  2381. .on("mouseup.drag", mouseupped, nonpassivecapture);
  2382. dragDisable(event.view);
  2383. nopropagation$2(event);
  2384. mousemoving = false;
  2385. mousedownx = event.clientX;
  2386. mousedowny = event.clientY;
  2387. gesture("start", event);
  2388. }
  2389. function mousemoved(event) {
  2390. noevent$2(event);
  2391. if (!mousemoving) {
  2392. var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
  2393. mousemoving = dx * dx + dy * dy > clickDistance2;
  2394. }
  2395. gestures.mouse("drag", event);
  2396. }
  2397. function mouseupped(event) {
  2398. select(event.view).on("mousemove.drag mouseup.drag", null);
  2399. yesdrag(event.view, mousemoving);
  2400. noevent$2(event);
  2401. gestures.mouse("end", event);
  2402. }
  2403. function touchstarted(event, d) {
  2404. if (!filter.call(this, event, d)) return;
  2405. var touches = event.changedTouches,
  2406. c = container.call(this, event, d),
  2407. n = touches.length, i, gesture;
  2408. for (i = 0; i < n; ++i) {
  2409. if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
  2410. nopropagation$2(event);
  2411. gesture("start", event, touches[i]);
  2412. }
  2413. }
  2414. }
  2415. function touchmoved(event) {
  2416. var touches = event.changedTouches,
  2417. n = touches.length, i, gesture;
  2418. for (i = 0; i < n; ++i) {
  2419. if (gesture = gestures[touches[i].identifier]) {
  2420. noevent$2(event);
  2421. gesture("drag", event, touches[i]);
  2422. }
  2423. }
  2424. }
  2425. function touchended(event) {
  2426. var touches = event.changedTouches,
  2427. n = touches.length, i, gesture;
  2428. if (touchending) clearTimeout(touchending);
  2429. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  2430. for (i = 0; i < n; ++i) {
  2431. if (gesture = gestures[touches[i].identifier]) {
  2432. nopropagation$2(event);
  2433. gesture("end", event, touches[i]);
  2434. }
  2435. }
  2436. }
  2437. function beforestart(that, container, event, d, identifier, touch) {
  2438. var dispatch = listeners.copy(),
  2439. p = pointer(touch || event, container), dx, dy,
  2440. s;
  2441. if ((s = subject.call(that, new DragEvent("beforestart", {
  2442. sourceEvent: event,
  2443. target: drag,
  2444. identifier,
  2445. active,
  2446. x: p[0],
  2447. y: p[1],
  2448. dx: 0,
  2449. dy: 0,
  2450. dispatch
  2451. }), d)) == null) return;
  2452. dx = s.x - p[0] || 0;
  2453. dy = s.y - p[1] || 0;
  2454. return function gesture(type, event, touch) {
  2455. var p0 = p, n;
  2456. switch (type) {
  2457. case "start": gestures[identifier] = gesture, n = active++; break;
  2458. case "end": delete gestures[identifier], --active; // falls through
  2459. case "drag": p = pointer(touch || event, container), n = active; break;
  2460. }
  2461. dispatch.call(
  2462. type,
  2463. that,
  2464. new DragEvent(type, {
  2465. sourceEvent: event,
  2466. subject: s,
  2467. target: drag,
  2468. identifier,
  2469. active: n,
  2470. x: p[0] + dx,
  2471. y: p[1] + dy,
  2472. dx: p[0] - p0[0],
  2473. dy: p[1] - p0[1],
  2474. dispatch
  2475. }),
  2476. d
  2477. );
  2478. };
  2479. }
  2480. drag.filter = function(_) {
  2481. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
  2482. };
  2483. drag.container = function(_) {
  2484. return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
  2485. };
  2486. drag.subject = function(_) {
  2487. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
  2488. };
  2489. drag.touchable = function(_) {
  2490. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
  2491. };
  2492. drag.on = function() {
  2493. var value = listeners.on.apply(listeners, arguments);
  2494. return value === listeners ? drag : value;
  2495. };
  2496. drag.clickDistance = function(_) {
  2497. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  2498. };
  2499. return drag;
  2500. }
  2501. function define(constructor, factory, prototype) {
  2502. constructor.prototype = factory.prototype = prototype;
  2503. prototype.constructor = constructor;
  2504. }
  2505. function extend(parent, definition) {
  2506. var prototype = Object.create(parent.prototype);
  2507. for (var key in definition) prototype[key] = definition[key];
  2508. return prototype;
  2509. }
  2510. function Color() {}
  2511. var darker = 0.7;
  2512. var brighter = 1 / darker;
  2513. var reI = "\\s*([+-]?\\d+)\\s*",
  2514. reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  2515. reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  2516. reHex = /^#([0-9a-f]{3,8})$/,
  2517. reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
  2518. reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
  2519. reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
  2520. reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
  2521. reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
  2522. reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
  2523. var named = {
  2524. aliceblue: 0xf0f8ff,
  2525. antiquewhite: 0xfaebd7,
  2526. aqua: 0x00ffff,
  2527. aquamarine: 0x7fffd4,
  2528. azure: 0xf0ffff,
  2529. beige: 0xf5f5dc,
  2530. bisque: 0xffe4c4,
  2531. black: 0x000000,
  2532. blanchedalmond: 0xffebcd,
  2533. blue: 0x0000ff,
  2534. blueviolet: 0x8a2be2,
  2535. brown: 0xa52a2a,
  2536. burlywood: 0xdeb887,
  2537. cadetblue: 0x5f9ea0,
  2538. chartreuse: 0x7fff00,
  2539. chocolate: 0xd2691e,
  2540. coral: 0xff7f50,
  2541. cornflowerblue: 0x6495ed,
  2542. cornsilk: 0xfff8dc,
  2543. crimson: 0xdc143c,
  2544. cyan: 0x00ffff,
  2545. darkblue: 0x00008b,
  2546. darkcyan: 0x008b8b,
  2547. darkgoldenrod: 0xb8860b,
  2548. darkgray: 0xa9a9a9,
  2549. darkgreen: 0x006400,
  2550. darkgrey: 0xa9a9a9,
  2551. darkkhaki: 0xbdb76b,
  2552. darkmagenta: 0x8b008b,
  2553. darkolivegreen: 0x556b2f,
  2554. darkorange: 0xff8c00,
  2555. darkorchid: 0x9932cc,
  2556. darkred: 0x8b0000,
  2557. darksalmon: 0xe9967a,
  2558. darkseagreen: 0x8fbc8f,
  2559. darkslateblue: 0x483d8b,
  2560. darkslategray: 0x2f4f4f,
  2561. darkslategrey: 0x2f4f4f,
  2562. darkturquoise: 0x00ced1,
  2563. darkviolet: 0x9400d3,
  2564. deeppink: 0xff1493,
  2565. deepskyblue: 0x00bfff,
  2566. dimgray: 0x696969,
  2567. dimgrey: 0x696969,
  2568. dodgerblue: 0x1e90ff,
  2569. firebrick: 0xb22222,
  2570. floralwhite: 0xfffaf0,
  2571. forestgreen: 0x228b22,
  2572. fuchsia: 0xff00ff,
  2573. gainsboro: 0xdcdcdc,
  2574. ghostwhite: 0xf8f8ff,
  2575. gold: 0xffd700,
  2576. goldenrod: 0xdaa520,
  2577. gray: 0x808080,
  2578. green: 0x008000,
  2579. greenyellow: 0xadff2f,
  2580. grey: 0x808080,
  2581. honeydew: 0xf0fff0,
  2582. hotpink: 0xff69b4,
  2583. indianred: 0xcd5c5c,
  2584. indigo: 0x4b0082,
  2585. ivory: 0xfffff0,
  2586. khaki: 0xf0e68c,
  2587. lavender: 0xe6e6fa,
  2588. lavenderblush: 0xfff0f5,
  2589. lawngreen: 0x7cfc00,
  2590. lemonchiffon: 0xfffacd,
  2591. lightblue: 0xadd8e6,
  2592. lightcoral: 0xf08080,
  2593. lightcyan: 0xe0ffff,
  2594. lightgoldenrodyellow: 0xfafad2,
  2595. lightgray: 0xd3d3d3,
  2596. lightgreen: 0x90ee90,
  2597. lightgrey: 0xd3d3d3,
  2598. lightpink: 0xffb6c1,
  2599. lightsalmon: 0xffa07a,
  2600. lightseagreen: 0x20b2aa,
  2601. lightskyblue: 0x87cefa,
  2602. lightslategray: 0x778899,
  2603. lightslategrey: 0x778899,
  2604. lightsteelblue: 0xb0c4de,
  2605. lightyellow: 0xffffe0,
  2606. lime: 0x00ff00,
  2607. limegreen: 0x32cd32,
  2608. linen: 0xfaf0e6,
  2609. magenta: 0xff00ff,
  2610. maroon: 0x800000,
  2611. mediumaquamarine: 0x66cdaa,
  2612. mediumblue: 0x0000cd,
  2613. mediumorchid: 0xba55d3,
  2614. mediumpurple: 0x9370db,
  2615. mediumseagreen: 0x3cb371,
  2616. mediumslateblue: 0x7b68ee,
  2617. mediumspringgreen: 0x00fa9a,
  2618. mediumturquoise: 0x48d1cc,
  2619. mediumvioletred: 0xc71585,
  2620. midnightblue: 0x191970,
  2621. mintcream: 0xf5fffa,
  2622. mistyrose: 0xffe4e1,
  2623. moccasin: 0xffe4b5,
  2624. navajowhite: 0xffdead,
  2625. navy: 0x000080,
  2626. oldlace: 0xfdf5e6,
  2627. olive: 0x808000,
  2628. olivedrab: 0x6b8e23,
  2629. orange: 0xffa500,
  2630. orangered: 0xff4500,
  2631. orchid: 0xda70d6,
  2632. palegoldenrod: 0xeee8aa,
  2633. palegreen: 0x98fb98,
  2634. paleturquoise: 0xafeeee,
  2635. palevioletred: 0xdb7093,
  2636. papayawhip: 0xffefd5,
  2637. peachpuff: 0xffdab9,
  2638. peru: 0xcd853f,
  2639. pink: 0xffc0cb,
  2640. plum: 0xdda0dd,
  2641. powderblue: 0xb0e0e6,
  2642. purple: 0x800080,
  2643. rebeccapurple: 0x663399,
  2644. red: 0xff0000,
  2645. rosybrown: 0xbc8f8f,
  2646. royalblue: 0x4169e1,
  2647. saddlebrown: 0x8b4513,
  2648. salmon: 0xfa8072,
  2649. sandybrown: 0xf4a460,
  2650. seagreen: 0x2e8b57,
  2651. seashell: 0xfff5ee,
  2652. sienna: 0xa0522d,
  2653. silver: 0xc0c0c0,
  2654. skyblue: 0x87ceeb,
  2655. slateblue: 0x6a5acd,
  2656. slategray: 0x708090,
  2657. slategrey: 0x708090,
  2658. snow: 0xfffafa,
  2659. springgreen: 0x00ff7f,
  2660. steelblue: 0x4682b4,
  2661. tan: 0xd2b48c,
  2662. teal: 0x008080,
  2663. thistle: 0xd8bfd8,
  2664. tomato: 0xff6347,
  2665. turquoise: 0x40e0d0,
  2666. violet: 0xee82ee,
  2667. wheat: 0xf5deb3,
  2668. white: 0xffffff,
  2669. whitesmoke: 0xf5f5f5,
  2670. yellow: 0xffff00,
  2671. yellowgreen: 0x9acd32
  2672. };
  2673. define(Color, color, {
  2674. copy(channels) {
  2675. return Object.assign(new this.constructor, this, channels);
  2676. },
  2677. displayable() {
  2678. return this.rgb().displayable();
  2679. },
  2680. hex: color_formatHex, // Deprecated! Use color.formatHex.
  2681. formatHex: color_formatHex,
  2682. formatHex8: color_formatHex8,
  2683. formatHsl: color_formatHsl,
  2684. formatRgb: color_formatRgb,
  2685. toString: color_formatRgb
  2686. });
  2687. function color_formatHex() {
  2688. return this.rgb().formatHex();
  2689. }
  2690. function color_formatHex8() {
  2691. return this.rgb().formatHex8();
  2692. }
  2693. function color_formatHsl() {
  2694. return hslConvert(this).formatHsl();
  2695. }
  2696. function color_formatRgb() {
  2697. return this.rgb().formatRgb();
  2698. }
  2699. function color(format) {
  2700. var m, l;
  2701. format = (format + "").trim().toLowerCase();
  2702. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  2703. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  2704. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  2705. : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
  2706. : null) // invalid hex
  2707. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  2708. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  2709. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  2710. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  2711. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  2712. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  2713. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  2714. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  2715. : null;
  2716. }
  2717. function rgbn(n) {
  2718. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  2719. }
  2720. function rgba(r, g, b, a) {
  2721. if (a <= 0) r = g = b = NaN;
  2722. return new Rgb(r, g, b, a);
  2723. }
  2724. function rgbConvert(o) {
  2725. if (!(o instanceof Color)) o = color(o);
  2726. if (!o) return new Rgb;
  2727. o = o.rgb();
  2728. return new Rgb(o.r, o.g, o.b, o.opacity);
  2729. }
  2730. function rgb(r, g, b, opacity) {
  2731. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  2732. }
  2733. function Rgb(r, g, b, opacity) {
  2734. this.r = +r;
  2735. this.g = +g;
  2736. this.b = +b;
  2737. this.opacity = +opacity;
  2738. }
  2739. define(Rgb, rgb, extend(Color, {
  2740. brighter(k) {
  2741. k = k == null ? brighter : Math.pow(brighter, k);
  2742. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2743. },
  2744. darker(k) {
  2745. k = k == null ? darker : Math.pow(darker, k);
  2746. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2747. },
  2748. rgb() {
  2749. return this;
  2750. },
  2751. clamp() {
  2752. return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
  2753. },
  2754. displayable() {
  2755. return (-0.5 <= this.r && this.r < 255.5)
  2756. && (-0.5 <= this.g && this.g < 255.5)
  2757. && (-0.5 <= this.b && this.b < 255.5)
  2758. && (0 <= this.opacity && this.opacity <= 1);
  2759. },
  2760. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  2761. formatHex: rgb_formatHex,
  2762. formatHex8: rgb_formatHex8,
  2763. formatRgb: rgb_formatRgb,
  2764. toString: rgb_formatRgb
  2765. }));
  2766. function rgb_formatHex() {
  2767. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
  2768. }
  2769. function rgb_formatHex8() {
  2770. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
  2771. }
  2772. function rgb_formatRgb() {
  2773. const a = clampa(this.opacity);
  2774. return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
  2775. }
  2776. function clampa(opacity) {
  2777. return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
  2778. }
  2779. function clampi(value) {
  2780. return Math.max(0, Math.min(255, Math.round(value) || 0));
  2781. }
  2782. function hex(value) {
  2783. value = clampi(value);
  2784. return (value < 16 ? "0" : "") + value.toString(16);
  2785. }
  2786. function hsla(h, s, l, a) {
  2787. if (a <= 0) h = s = l = NaN;
  2788. else if (l <= 0 || l >= 1) h = s = NaN;
  2789. else if (s <= 0) h = NaN;
  2790. return new Hsl(h, s, l, a);
  2791. }
  2792. function hslConvert(o) {
  2793. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  2794. if (!(o instanceof Color)) o = color(o);
  2795. if (!o) return new Hsl;
  2796. if (o instanceof Hsl) return o;
  2797. o = o.rgb();
  2798. var r = o.r / 255,
  2799. g = o.g / 255,
  2800. b = o.b / 255,
  2801. min = Math.min(r, g, b),
  2802. max = Math.max(r, g, b),
  2803. h = NaN,
  2804. s = max - min,
  2805. l = (max + min) / 2;
  2806. if (s) {
  2807. if (r === max) h = (g - b) / s + (g < b) * 6;
  2808. else if (g === max) h = (b - r) / s + 2;
  2809. else h = (r - g) / s + 4;
  2810. s /= l < 0.5 ? max + min : 2 - max - min;
  2811. h *= 60;
  2812. } else {
  2813. s = l > 0 && l < 1 ? 0 : h;
  2814. }
  2815. return new Hsl(h, s, l, o.opacity);
  2816. }
  2817. function hsl$2(h, s, l, opacity) {
  2818. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  2819. }
  2820. function Hsl(h, s, l, opacity) {
  2821. this.h = +h;
  2822. this.s = +s;
  2823. this.l = +l;
  2824. this.opacity = +opacity;
  2825. }
  2826. define(Hsl, hsl$2, extend(Color, {
  2827. brighter(k) {
  2828. k = k == null ? brighter : Math.pow(brighter, k);
  2829. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2830. },
  2831. darker(k) {
  2832. k = k == null ? darker : Math.pow(darker, k);
  2833. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2834. },
  2835. rgb() {
  2836. var h = this.h % 360 + (this.h < 0) * 360,
  2837. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  2838. l = this.l,
  2839. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  2840. m1 = 2 * l - m2;
  2841. return new Rgb(
  2842. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2843. hsl2rgb(h, m1, m2),
  2844. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2845. this.opacity
  2846. );
  2847. },
  2848. clamp() {
  2849. return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
  2850. },
  2851. displayable() {
  2852. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2853. && (0 <= this.l && this.l <= 1)
  2854. && (0 <= this.opacity && this.opacity <= 1);
  2855. },
  2856. formatHsl() {
  2857. const a = clampa(this.opacity);
  2858. return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
  2859. }
  2860. }));
  2861. function clamph(value) {
  2862. value = (value || 0) % 360;
  2863. return value < 0 ? value + 360 : value;
  2864. }
  2865. function clampt(value) {
  2866. return Math.max(0, Math.min(1, value || 0));
  2867. }
  2868. /* From FvD 13.37, CSS Color Module Level 3 */
  2869. function hsl2rgb(h, m1, m2) {
  2870. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2871. : h < 180 ? m2
  2872. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2873. : m1) * 255;
  2874. }
  2875. const radians$1 = Math.PI / 180;
  2876. const degrees$2 = 180 / Math.PI;
  2877. // https://observablehq.com/@mbostock/lab-and-rgb
  2878. const K = 18,
  2879. Xn = 0.96422,
  2880. Yn = 1,
  2881. Zn = 0.82521,
  2882. t0$1 = 4 / 29,
  2883. t1$1 = 6 / 29,
  2884. t2 = 3 * t1$1 * t1$1,
  2885. t3 = t1$1 * t1$1 * t1$1;
  2886. function labConvert(o) {
  2887. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2888. if (o instanceof Hcl) return hcl2lab(o);
  2889. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2890. var r = rgb2lrgb(o.r),
  2891. g = rgb2lrgb(o.g),
  2892. b = rgb2lrgb(o.b),
  2893. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2894. if (r === g && g === b) x = z = y; else {
  2895. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2896. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2897. }
  2898. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2899. }
  2900. function gray(l, opacity) {
  2901. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2902. }
  2903. function lab$1(l, a, b, opacity) {
  2904. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2905. }
  2906. function Lab(l, a, b, opacity) {
  2907. this.l = +l;
  2908. this.a = +a;
  2909. this.b = +b;
  2910. this.opacity = +opacity;
  2911. }
  2912. define(Lab, lab$1, extend(Color, {
  2913. brighter(k) {
  2914. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2915. },
  2916. darker(k) {
  2917. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2918. },
  2919. rgb() {
  2920. var y = (this.l + 16) / 116,
  2921. x = isNaN(this.a) ? y : y + this.a / 500,
  2922. z = isNaN(this.b) ? y : y - this.b / 200;
  2923. x = Xn * lab2xyz(x);
  2924. y = Yn * lab2xyz(y);
  2925. z = Zn * lab2xyz(z);
  2926. return new Rgb(
  2927. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2928. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2929. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2930. this.opacity
  2931. );
  2932. }
  2933. }));
  2934. function xyz2lab(t) {
  2935. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
  2936. }
  2937. function lab2xyz(t) {
  2938. return t > t1$1 ? t * t * t : t2 * (t - t0$1);
  2939. }
  2940. function lrgb2rgb(x) {
  2941. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2942. }
  2943. function rgb2lrgb(x) {
  2944. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2945. }
  2946. function hclConvert(o) {
  2947. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2948. if (!(o instanceof Lab)) o = labConvert(o);
  2949. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2950. var h = Math.atan2(o.b, o.a) * degrees$2;
  2951. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2952. }
  2953. function lch(l, c, h, opacity) {
  2954. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2955. }
  2956. function hcl$2(h, c, l, opacity) {
  2957. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2958. }
  2959. function Hcl(h, c, l, opacity) {
  2960. this.h = +h;
  2961. this.c = +c;
  2962. this.l = +l;
  2963. this.opacity = +opacity;
  2964. }
  2965. function hcl2lab(o) {
  2966. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2967. var h = o.h * radians$1;
  2968. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2969. }
  2970. define(Hcl, hcl$2, extend(Color, {
  2971. brighter(k) {
  2972. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2973. },
  2974. darker(k) {
  2975. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2976. },
  2977. rgb() {
  2978. return hcl2lab(this).rgb();
  2979. }
  2980. }));
  2981. var A = -0.14861,
  2982. B$1 = +1.78277,
  2983. C = -0.29227,
  2984. D$1 = -0.90649,
  2985. E = +1.97294,
  2986. ED = E * D$1,
  2987. EB = E * B$1,
  2988. BC_DA = B$1 * C - D$1 * A;
  2989. function cubehelixConvert(o) {
  2990. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2991. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2992. var r = o.r / 255,
  2993. g = o.g / 255,
  2994. b = o.b / 255,
  2995. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2996. bl = b - l,
  2997. k = (E * (g - l) - C * bl) / D$1,
  2998. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2999. h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
  3000. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  3001. }
  3002. function cubehelix$3(h, s, l, opacity) {
  3003. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  3004. }
  3005. function Cubehelix(h, s, l, opacity) {
  3006. this.h = +h;
  3007. this.s = +s;
  3008. this.l = +l;
  3009. this.opacity = +opacity;
  3010. }
  3011. define(Cubehelix, cubehelix$3, extend(Color, {
  3012. brighter(k) {
  3013. k = k == null ? brighter : Math.pow(brighter, k);
  3014. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3015. },
  3016. darker(k) {
  3017. k = k == null ? darker : Math.pow(darker, k);
  3018. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3019. },
  3020. rgb() {
  3021. var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
  3022. l = +this.l,
  3023. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  3024. cosh = Math.cos(h),
  3025. sinh = Math.sin(h);
  3026. return new Rgb(
  3027. 255 * (l + a * (A * cosh + B$1 * sinh)),
  3028. 255 * (l + a * (C * cosh + D$1 * sinh)),
  3029. 255 * (l + a * (E * cosh)),
  3030. this.opacity
  3031. );
  3032. }
  3033. }));
  3034. function basis$1(t1, v0, v1, v2, v3) {
  3035. var t2 = t1 * t1, t3 = t2 * t1;
  3036. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  3037. + (4 - 6 * t2 + 3 * t3) * v1
  3038. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  3039. + t3 * v3) / 6;
  3040. }
  3041. function basis$2(values) {
  3042. var n = values.length - 1;
  3043. return function(t) {
  3044. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  3045. v1 = values[i],
  3046. v2 = values[i + 1],
  3047. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  3048. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  3049. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3050. };
  3051. }
  3052. function basisClosed$1(values) {
  3053. var n = values.length;
  3054. return function(t) {
  3055. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  3056. v0 = values[(i + n - 1) % n],
  3057. v1 = values[i % n],
  3058. v2 = values[(i + 1) % n],
  3059. v3 = values[(i + 2) % n];
  3060. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3061. };
  3062. }
  3063. var constant$8 = x => () => x;
  3064. function linear$2(a, d) {
  3065. return function(t) {
  3066. return a + t * d;
  3067. };
  3068. }
  3069. function exponential$1(a, b, y) {
  3070. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  3071. return Math.pow(a + t * b, y);
  3072. };
  3073. }
  3074. function hue$1(a, b) {
  3075. var d = b - a;
  3076. return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
  3077. }
  3078. function gamma$1(y) {
  3079. return (y = +y) === 1 ? nogamma : function(a, b) {
  3080. return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
  3081. };
  3082. }
  3083. function nogamma(a, b) {
  3084. var d = b - a;
  3085. return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
  3086. }
  3087. var interpolateRgb = (function rgbGamma(y) {
  3088. var color = gamma$1(y);
  3089. function rgb$1(start, end) {
  3090. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  3091. g = color(start.g, end.g),
  3092. b = color(start.b, end.b),
  3093. opacity = nogamma(start.opacity, end.opacity);
  3094. return function(t) {
  3095. start.r = r(t);
  3096. start.g = g(t);
  3097. start.b = b(t);
  3098. start.opacity = opacity(t);
  3099. return start + "";
  3100. };
  3101. }
  3102. rgb$1.gamma = rgbGamma;
  3103. return rgb$1;
  3104. })(1);
  3105. function rgbSpline(spline) {
  3106. return function(colors) {
  3107. var n = colors.length,
  3108. r = new Array(n),
  3109. g = new Array(n),
  3110. b = new Array(n),
  3111. i, color;
  3112. for (i = 0; i < n; ++i) {
  3113. color = rgb(colors[i]);
  3114. r[i] = color.r || 0;
  3115. g[i] = color.g || 0;
  3116. b[i] = color.b || 0;
  3117. }
  3118. r = spline(r);
  3119. g = spline(g);
  3120. b = spline(b);
  3121. color.opacity = 1;
  3122. return function(t) {
  3123. color.r = r(t);
  3124. color.g = g(t);
  3125. color.b = b(t);
  3126. return color + "";
  3127. };
  3128. };
  3129. }
  3130. var rgbBasis = rgbSpline(basis$2);
  3131. var rgbBasisClosed = rgbSpline(basisClosed$1);
  3132. function numberArray(a, b) {
  3133. if (!b) b = [];
  3134. var n = a ? Math.min(b.length, a.length) : 0,
  3135. c = b.slice(),
  3136. i;
  3137. return function(t) {
  3138. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  3139. return c;
  3140. };
  3141. }
  3142. function isNumberArray(x) {
  3143. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  3144. }
  3145. function array$3(a, b) {
  3146. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  3147. }
  3148. function genericArray(a, b) {
  3149. var nb = b ? b.length : 0,
  3150. na = a ? Math.min(nb, a.length) : 0,
  3151. x = new Array(na),
  3152. c = new Array(nb),
  3153. i;
  3154. for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
  3155. for (; i < nb; ++i) c[i] = b[i];
  3156. return function(t) {
  3157. for (i = 0; i < na; ++i) c[i] = x[i](t);
  3158. return c;
  3159. };
  3160. }
  3161. function date$1(a, b) {
  3162. var d = new Date;
  3163. return a = +a, b = +b, function(t) {
  3164. return d.setTime(a * (1 - t) + b * t), d;
  3165. };
  3166. }
  3167. function interpolateNumber(a, b) {
  3168. return a = +a, b = +b, function(t) {
  3169. return a * (1 - t) + b * t;
  3170. };
  3171. }
  3172. function object$1(a, b) {
  3173. var i = {},
  3174. c = {},
  3175. k;
  3176. if (a === null || typeof a !== "object") a = {};
  3177. if (b === null || typeof b !== "object") b = {};
  3178. for (k in b) {
  3179. if (k in a) {
  3180. i[k] = interpolate$2(a[k], b[k]);
  3181. } else {
  3182. c[k] = b[k];
  3183. }
  3184. }
  3185. return function(t) {
  3186. for (k in i) c[k] = i[k](t);
  3187. return c;
  3188. };
  3189. }
  3190. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  3191. reB = new RegExp(reA.source, "g");
  3192. function zero(b) {
  3193. return function() {
  3194. return b;
  3195. };
  3196. }
  3197. function one(b) {
  3198. return function(t) {
  3199. return b(t) + "";
  3200. };
  3201. }
  3202. function interpolateString(a, b) {
  3203. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  3204. am, // current match in a
  3205. bm, // current match in b
  3206. bs, // string preceding current number in b, if any
  3207. i = -1, // index in s
  3208. s = [], // string constants and placeholders
  3209. q = []; // number interpolators
  3210. // Coerce inputs to strings.
  3211. a = a + "", b = b + "";
  3212. // Interpolate pairs of numbers in a & b.
  3213. while ((am = reA.exec(a))
  3214. && (bm = reB.exec(b))) {
  3215. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  3216. bs = b.slice(bi, bs);
  3217. if (s[i]) s[i] += bs; // coalesce with previous string
  3218. else s[++i] = bs;
  3219. }
  3220. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  3221. if (s[i]) s[i] += bm; // coalesce with previous string
  3222. else s[++i] = bm;
  3223. } else { // interpolate non-matching numbers
  3224. s[++i] = null;
  3225. q.push({i: i, x: interpolateNumber(am, bm)});
  3226. }
  3227. bi = reB.lastIndex;
  3228. }
  3229. // Add remains of b.
  3230. if (bi < b.length) {
  3231. bs = b.slice(bi);
  3232. if (s[i]) s[i] += bs; // coalesce with previous string
  3233. else s[++i] = bs;
  3234. }
  3235. // Special optimization for only a single match.
  3236. // Otherwise, interpolate each of the numbers and rejoin the string.
  3237. return s.length < 2 ? (q[0]
  3238. ? one(q[0].x)
  3239. : zero(b))
  3240. : (b = q.length, function(t) {
  3241. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  3242. return s.join("");
  3243. });
  3244. }
  3245. function interpolate$2(a, b) {
  3246. var t = typeof b, c;
  3247. return b == null || t === "boolean" ? constant$8(b)
  3248. : (t === "number" ? interpolateNumber
  3249. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  3250. : b instanceof color ? interpolateRgb
  3251. : b instanceof Date ? date$1
  3252. : isNumberArray(b) ? numberArray
  3253. : Array.isArray(b) ? genericArray
  3254. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
  3255. : interpolateNumber)(a, b);
  3256. }
  3257. function discrete(range) {
  3258. var n = range.length;
  3259. return function(t) {
  3260. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  3261. };
  3262. }
  3263. function hue(a, b) {
  3264. var i = hue$1(+a, +b);
  3265. return function(t) {
  3266. var x = i(t);
  3267. return x - 360 * Math.floor(x / 360);
  3268. };
  3269. }
  3270. function interpolateRound(a, b) {
  3271. return a = +a, b = +b, function(t) {
  3272. return Math.round(a * (1 - t) + b * t);
  3273. };
  3274. }
  3275. var degrees$1 = 180 / Math.PI;
  3276. var identity$7 = {
  3277. translateX: 0,
  3278. translateY: 0,
  3279. rotate: 0,
  3280. skewX: 0,
  3281. scaleX: 1,
  3282. scaleY: 1
  3283. };
  3284. function decompose(a, b, c, d, e, f) {
  3285. var scaleX, scaleY, skewX;
  3286. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  3287. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  3288. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  3289. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  3290. return {
  3291. translateX: e,
  3292. translateY: f,
  3293. rotate: Math.atan2(b, a) * degrees$1,
  3294. skewX: Math.atan(skewX) * degrees$1,
  3295. scaleX: scaleX,
  3296. scaleY: scaleY
  3297. };
  3298. }
  3299. var svgNode;
  3300. /* eslint-disable no-undef */
  3301. function parseCss(value) {
  3302. const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
  3303. return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
  3304. }
  3305. function parseSvg(value) {
  3306. if (value == null) return identity$7;
  3307. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  3308. svgNode.setAttribute("transform", value);
  3309. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
  3310. value = value.matrix;
  3311. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  3312. }
  3313. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  3314. function pop(s) {
  3315. return s.length ? s.pop() + " " : "";
  3316. }
  3317. function translate(xa, ya, xb, yb, s, q) {
  3318. if (xa !== xb || ya !== yb) {
  3319. var i = s.push("translate(", null, pxComma, null, pxParen);
  3320. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3321. } else if (xb || yb) {
  3322. s.push("translate(" + xb + pxComma + yb + pxParen);
  3323. }
  3324. }
  3325. function rotate(a, b, s, q) {
  3326. if (a !== b) {
  3327. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  3328. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3329. } else if (b) {
  3330. s.push(pop(s) + "rotate(" + b + degParen);
  3331. }
  3332. }
  3333. function skewX(a, b, s, q) {
  3334. if (a !== b) {
  3335. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3336. } else if (b) {
  3337. s.push(pop(s) + "skewX(" + b + degParen);
  3338. }
  3339. }
  3340. function scale(xa, ya, xb, yb, s, q) {
  3341. if (xa !== xb || ya !== yb) {
  3342. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  3343. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3344. } else if (xb !== 1 || yb !== 1) {
  3345. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  3346. }
  3347. }
  3348. return function(a, b) {
  3349. var s = [], // string constants and placeholders
  3350. q = []; // number interpolators
  3351. a = parse(a), b = parse(b);
  3352. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  3353. rotate(a.rotate, b.rotate, s, q);
  3354. skewX(a.skewX, b.skewX, s, q);
  3355. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  3356. a = b = null; // gc
  3357. return function(t) {
  3358. var i = -1, n = q.length, o;
  3359. while (++i < n) s[(o = q[i]).i] = o.x(t);
  3360. return s.join("");
  3361. };
  3362. };
  3363. }
  3364. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  3365. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  3366. var epsilon2$1 = 1e-12;
  3367. function cosh(x) {
  3368. return ((x = Math.exp(x)) + 1 / x) / 2;
  3369. }
  3370. function sinh(x) {
  3371. return ((x = Math.exp(x)) - 1 / x) / 2;
  3372. }
  3373. function tanh(x) {
  3374. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3375. }
  3376. var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
  3377. // p0 = [ux0, uy0, w0]
  3378. // p1 = [ux1, uy1, w1]
  3379. function zoom(p0, p1) {
  3380. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3381. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3382. dx = ux1 - ux0,
  3383. dy = uy1 - uy0,
  3384. d2 = dx * dx + dy * dy,
  3385. i,
  3386. S;
  3387. // Special case for u0 ≅ u1.
  3388. if (d2 < epsilon2$1) {
  3389. S = Math.log(w1 / w0) / rho;
  3390. i = function(t) {
  3391. return [
  3392. ux0 + t * dx,
  3393. uy0 + t * dy,
  3394. w0 * Math.exp(rho * t * S)
  3395. ];
  3396. };
  3397. }
  3398. // General case.
  3399. else {
  3400. var d1 = Math.sqrt(d2),
  3401. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3402. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3403. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3404. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3405. S = (r1 - r0) / rho;
  3406. i = function(t) {
  3407. var s = t * S,
  3408. coshr0 = cosh(r0),
  3409. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3410. return [
  3411. ux0 + u * dx,
  3412. uy0 + u * dy,
  3413. w0 * coshr0 / cosh(rho * s + r0)
  3414. ];
  3415. };
  3416. }
  3417. i.duration = S * 1000 * rho / Math.SQRT2;
  3418. return i;
  3419. }
  3420. zoom.rho = function(_) {
  3421. var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
  3422. return zoomRho(_1, _2, _4);
  3423. };
  3424. return zoom;
  3425. })(Math.SQRT2, 2, 4);
  3426. function hsl(hue) {
  3427. return function(start, end) {
  3428. var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
  3429. s = nogamma(start.s, end.s),
  3430. l = nogamma(start.l, end.l),
  3431. opacity = nogamma(start.opacity, end.opacity);
  3432. return function(t) {
  3433. start.h = h(t);
  3434. start.s = s(t);
  3435. start.l = l(t);
  3436. start.opacity = opacity(t);
  3437. return start + "";
  3438. };
  3439. }
  3440. }
  3441. var hsl$1 = hsl(hue$1);
  3442. var hslLong = hsl(nogamma);
  3443. function lab(start, end) {
  3444. var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
  3445. a = nogamma(start.a, end.a),
  3446. b = nogamma(start.b, end.b),
  3447. opacity = nogamma(start.opacity, end.opacity);
  3448. return function(t) {
  3449. start.l = l(t);
  3450. start.a = a(t);
  3451. start.b = b(t);
  3452. start.opacity = opacity(t);
  3453. return start + "";
  3454. };
  3455. }
  3456. function hcl(hue) {
  3457. return function(start, end) {
  3458. var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
  3459. c = nogamma(start.c, end.c),
  3460. l = nogamma(start.l, end.l),
  3461. opacity = nogamma(start.opacity, end.opacity);
  3462. return function(t) {
  3463. start.h = h(t);
  3464. start.c = c(t);
  3465. start.l = l(t);
  3466. start.opacity = opacity(t);
  3467. return start + "";
  3468. };
  3469. }
  3470. }
  3471. var hcl$1 = hcl(hue$1);
  3472. var hclLong = hcl(nogamma);
  3473. function cubehelix$1(hue) {
  3474. return (function cubehelixGamma(y) {
  3475. y = +y;
  3476. function cubehelix(start, end) {
  3477. var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
  3478. s = nogamma(start.s, end.s),
  3479. l = nogamma(start.l, end.l),
  3480. opacity = nogamma(start.opacity, end.opacity);
  3481. return function(t) {
  3482. start.h = h(t);
  3483. start.s = s(t);
  3484. start.l = l(Math.pow(t, y));
  3485. start.opacity = opacity(t);
  3486. return start + "";
  3487. };
  3488. }
  3489. cubehelix.gamma = cubehelixGamma;
  3490. return cubehelix;
  3491. })(1);
  3492. }
  3493. var cubehelix$2 = cubehelix$1(hue$1);
  3494. var cubehelixLong = cubehelix$1(nogamma);
  3495. function piecewise(interpolate, values) {
  3496. if (values === undefined) values = interpolate, interpolate = interpolate$2;
  3497. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  3498. while (i < n) I[i] = interpolate(v, v = values[++i]);
  3499. return function(t) {
  3500. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  3501. return I[i](t - i);
  3502. };
  3503. }
  3504. function quantize$1(interpolator, n) {
  3505. var samples = new Array(n);
  3506. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  3507. return samples;
  3508. }
  3509. var frame = 0, // is an animation frame pending?
  3510. timeout$1 = 0, // is a timeout pending?
  3511. interval$1 = 0, // are any timers active?
  3512. pokeDelay = 1000, // how frequently we check for clock skew
  3513. taskHead,
  3514. taskTail,
  3515. clockLast = 0,
  3516. clockNow = 0,
  3517. clockSkew = 0,
  3518. clock = typeof performance === "object" && performance.now ? performance : Date,
  3519. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  3520. function now() {
  3521. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  3522. }
  3523. function clearNow() {
  3524. clockNow = 0;
  3525. }
  3526. function Timer() {
  3527. this._call =
  3528. this._time =
  3529. this._next = null;
  3530. }
  3531. Timer.prototype = timer.prototype = {
  3532. constructor: Timer,
  3533. restart: function(callback, delay, time) {
  3534. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  3535. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  3536. if (!this._next && taskTail !== this) {
  3537. if (taskTail) taskTail._next = this;
  3538. else taskHead = this;
  3539. taskTail = this;
  3540. }
  3541. this._call = callback;
  3542. this._time = time;
  3543. sleep();
  3544. },
  3545. stop: function() {
  3546. if (this._call) {
  3547. this._call = null;
  3548. this._time = Infinity;
  3549. sleep();
  3550. }
  3551. }
  3552. };
  3553. function timer(callback, delay, time) {
  3554. var t = new Timer;
  3555. t.restart(callback, delay, time);
  3556. return t;
  3557. }
  3558. function timerFlush() {
  3559. now(); // Get the current time, if not already set.
  3560. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  3561. var t = taskHead, e;
  3562. while (t) {
  3563. if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
  3564. t = t._next;
  3565. }
  3566. --frame;
  3567. }
  3568. function wake() {
  3569. clockNow = (clockLast = clock.now()) + clockSkew;
  3570. frame = timeout$1 = 0;
  3571. try {
  3572. timerFlush();
  3573. } finally {
  3574. frame = 0;
  3575. nap();
  3576. clockNow = 0;
  3577. }
  3578. }
  3579. function poke() {
  3580. var now = clock.now(), delay = now - clockLast;
  3581. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  3582. }
  3583. function nap() {
  3584. var t0, t1 = taskHead, t2, time = Infinity;
  3585. while (t1) {
  3586. if (t1._call) {
  3587. if (time > t1._time) time = t1._time;
  3588. t0 = t1, t1 = t1._next;
  3589. } else {
  3590. t2 = t1._next, t1._next = null;
  3591. t1 = t0 ? t0._next = t2 : taskHead = t2;
  3592. }
  3593. }
  3594. taskTail = t0;
  3595. sleep(time);
  3596. }
  3597. function sleep(time) {
  3598. if (frame) return; // Soonest alarm already set, or will be.
  3599. if (timeout$1) timeout$1 = clearTimeout(timeout$1);
  3600. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  3601. if (delay > 24) {
  3602. if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
  3603. if (interval$1) interval$1 = clearInterval(interval$1);
  3604. } else {
  3605. if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
  3606. frame = 1, setFrame(wake);
  3607. }
  3608. }
  3609. function timeout(callback, delay, time) {
  3610. var t = new Timer;
  3611. delay = delay == null ? 0 : +delay;
  3612. t.restart(elapsed => {
  3613. t.stop();
  3614. callback(elapsed + delay);
  3615. }, delay, time);
  3616. return t;
  3617. }
  3618. function interval(callback, delay, time) {
  3619. var t = new Timer, total = delay;
  3620. if (delay == null) return t.restart(callback, delay, time), t;
  3621. t._restart = t.restart;
  3622. t.restart = function(callback, delay, time) {
  3623. delay = +delay, time = time == null ? now() : +time;
  3624. t._restart(function tick(elapsed) {
  3625. elapsed += total;
  3626. t._restart(tick, total += delay, time);
  3627. callback(elapsed);
  3628. }, delay, time);
  3629. };
  3630. t.restart(callback, delay, time);
  3631. return t;
  3632. }
  3633. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  3634. var emptyTween = [];
  3635. var CREATED = 0;
  3636. var SCHEDULED = 1;
  3637. var STARTING = 2;
  3638. var STARTED = 3;
  3639. var RUNNING = 4;
  3640. var ENDING = 5;
  3641. var ENDED = 6;
  3642. function schedule(node, name, id, index, group, timing) {
  3643. var schedules = node.__transition;
  3644. if (!schedules) node.__transition = {};
  3645. else if (id in schedules) return;
  3646. create(node, id, {
  3647. name: name,
  3648. index: index, // For context during callback.
  3649. group: group, // For context during callback.
  3650. on: emptyOn,
  3651. tween: emptyTween,
  3652. time: timing.time,
  3653. delay: timing.delay,
  3654. duration: timing.duration,
  3655. ease: timing.ease,
  3656. timer: null,
  3657. state: CREATED
  3658. });
  3659. }
  3660. function init(node, id) {
  3661. var schedule = get(node, id);
  3662. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  3663. return schedule;
  3664. }
  3665. function set(node, id) {
  3666. var schedule = get(node, id);
  3667. if (schedule.state > STARTED) throw new Error("too late; already running");
  3668. return schedule;
  3669. }
  3670. function get(node, id) {
  3671. var schedule = node.__transition;
  3672. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  3673. return schedule;
  3674. }
  3675. function create(node, id, self) {
  3676. var schedules = node.__transition,
  3677. tween;
  3678. // Initialize the self timer when the transition is created.
  3679. // Note the actual delay is not known until the first callback!
  3680. schedules[id] = self;
  3681. self.timer = timer(schedule, 0, self.time);
  3682. function schedule(elapsed) {
  3683. self.state = SCHEDULED;
  3684. self.timer.restart(start, self.delay, self.time);
  3685. // If the elapsed delay is less than our first sleep, start immediately.
  3686. if (self.delay <= elapsed) start(elapsed - self.delay);
  3687. }
  3688. function start(elapsed) {
  3689. var i, j, n, o;
  3690. // If the state is not SCHEDULED, then we previously errored on start.
  3691. if (self.state !== SCHEDULED) return stop();
  3692. for (i in schedules) {
  3693. o = schedules[i];
  3694. if (o.name !== self.name) continue;
  3695. // While this element already has a starting transition during this frame,
  3696. // defer starting an interrupting transition until that transition has a
  3697. // chance to tick (and possibly end); see d3/d3-transition#54!
  3698. if (o.state === STARTED) return timeout(start);
  3699. // Interrupt the active transition, if any.
  3700. if (o.state === RUNNING) {
  3701. o.state = ENDED;
  3702. o.timer.stop();
  3703. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  3704. delete schedules[i];
  3705. }
  3706. // Cancel any pre-empted transitions.
  3707. else if (+i < id) {
  3708. o.state = ENDED;
  3709. o.timer.stop();
  3710. o.on.call("cancel", node, node.__data__, o.index, o.group);
  3711. delete schedules[i];
  3712. }
  3713. }
  3714. // Defer the first tick to end of the current frame; see d3/d3#1576.
  3715. // Note the transition may be canceled after start and before the first tick!
  3716. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  3717. // Assuming this is successful, subsequent callbacks go straight to tick.
  3718. timeout(function() {
  3719. if (self.state === STARTED) {
  3720. self.state = RUNNING;
  3721. self.timer.restart(tick, self.delay, self.time);
  3722. tick(elapsed);
  3723. }
  3724. });
  3725. // Dispatch the start event.
  3726. // Note this must be done before the tween are initialized.
  3727. self.state = STARTING;
  3728. self.on.call("start", node, node.__data__, self.index, self.group);
  3729. if (self.state !== STARTING) return; // interrupted
  3730. self.state = STARTED;
  3731. // Initialize the tween, deleting null tween.
  3732. tween = new Array(n = self.tween.length);
  3733. for (i = 0, j = -1; i < n; ++i) {
  3734. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  3735. tween[++j] = o;
  3736. }
  3737. }
  3738. tween.length = j + 1;
  3739. }
  3740. function tick(elapsed) {
  3741. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  3742. i = -1,
  3743. n = tween.length;
  3744. while (++i < n) {
  3745. tween[i].call(node, t);
  3746. }
  3747. // Dispatch the end event.
  3748. if (self.state === ENDING) {
  3749. self.on.call("end", node, node.__data__, self.index, self.group);
  3750. stop();
  3751. }
  3752. }
  3753. function stop() {
  3754. self.state = ENDED;
  3755. self.timer.stop();
  3756. delete schedules[id];
  3757. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  3758. delete node.__transition;
  3759. }
  3760. }
  3761. function interrupt(node, name) {
  3762. var schedules = node.__transition,
  3763. schedule,
  3764. active,
  3765. empty = true,
  3766. i;
  3767. if (!schedules) return;
  3768. name = name == null ? null : name + "";
  3769. for (i in schedules) {
  3770. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  3771. active = schedule.state > STARTING && schedule.state < ENDING;
  3772. schedule.state = ENDED;
  3773. schedule.timer.stop();
  3774. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  3775. delete schedules[i];
  3776. }
  3777. if (empty) delete node.__transition;
  3778. }
  3779. function selection_interrupt(name) {
  3780. return this.each(function() {
  3781. interrupt(this, name);
  3782. });
  3783. }
  3784. function tweenRemove(id, name) {
  3785. var tween0, tween1;
  3786. return function() {
  3787. var schedule = set(this, id),
  3788. tween = schedule.tween;
  3789. // If this node shared tween with the previous node,
  3790. // just assign the updated shared tween and we’re done!
  3791. // Otherwise, copy-on-write.
  3792. if (tween !== tween0) {
  3793. tween1 = tween0 = tween;
  3794. for (var i = 0, n = tween1.length; i < n; ++i) {
  3795. if (tween1[i].name === name) {
  3796. tween1 = tween1.slice();
  3797. tween1.splice(i, 1);
  3798. break;
  3799. }
  3800. }
  3801. }
  3802. schedule.tween = tween1;
  3803. };
  3804. }
  3805. function tweenFunction(id, name, value) {
  3806. var tween0, tween1;
  3807. if (typeof value !== "function") throw new Error;
  3808. return function() {
  3809. var schedule = set(this, id),
  3810. tween = schedule.tween;
  3811. // If this node shared tween with the previous node,
  3812. // just assign the updated shared tween and we’re done!
  3813. // Otherwise, copy-on-write.
  3814. if (tween !== tween0) {
  3815. tween1 = (tween0 = tween).slice();
  3816. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  3817. if (tween1[i].name === name) {
  3818. tween1[i] = t;
  3819. break;
  3820. }
  3821. }
  3822. if (i === n) tween1.push(t);
  3823. }
  3824. schedule.tween = tween1;
  3825. };
  3826. }
  3827. function transition_tween(name, value) {
  3828. var id = this._id;
  3829. name += "";
  3830. if (arguments.length < 2) {
  3831. var tween = get(this.node(), id).tween;
  3832. for (var i = 0, n = tween.length, t; i < n; ++i) {
  3833. if ((t = tween[i]).name === name) {
  3834. return t.value;
  3835. }
  3836. }
  3837. return null;
  3838. }
  3839. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  3840. }
  3841. function tweenValue(transition, name, value) {
  3842. var id = transition._id;
  3843. transition.each(function() {
  3844. var schedule = set(this, id);
  3845. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  3846. });
  3847. return function(node) {
  3848. return get(node, id).value[name];
  3849. };
  3850. }
  3851. function interpolate$1(a, b) {
  3852. var c;
  3853. return (typeof b === "number" ? interpolateNumber
  3854. : b instanceof color ? interpolateRgb
  3855. : (c = color(b)) ? (b = c, interpolateRgb)
  3856. : interpolateString)(a, b);
  3857. }
  3858. function attrRemove(name) {
  3859. return function() {
  3860. this.removeAttribute(name);
  3861. };
  3862. }
  3863. function attrRemoveNS(fullname) {
  3864. return function() {
  3865. this.removeAttributeNS(fullname.space, fullname.local);
  3866. };
  3867. }
  3868. function attrConstant(name, interpolate, value1) {
  3869. var string00,
  3870. string1 = value1 + "",
  3871. interpolate0;
  3872. return function() {
  3873. var string0 = this.getAttribute(name);
  3874. return string0 === string1 ? null
  3875. : string0 === string00 ? interpolate0
  3876. : interpolate0 = interpolate(string00 = string0, value1);
  3877. };
  3878. }
  3879. function attrConstantNS(fullname, interpolate, value1) {
  3880. var string00,
  3881. string1 = value1 + "",
  3882. interpolate0;
  3883. return function() {
  3884. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3885. return string0 === string1 ? null
  3886. : string0 === string00 ? interpolate0
  3887. : interpolate0 = interpolate(string00 = string0, value1);
  3888. };
  3889. }
  3890. function attrFunction(name, interpolate, value) {
  3891. var string00,
  3892. string10,
  3893. interpolate0;
  3894. return function() {
  3895. var string0, value1 = value(this), string1;
  3896. if (value1 == null) return void this.removeAttribute(name);
  3897. string0 = this.getAttribute(name);
  3898. string1 = value1 + "";
  3899. return string0 === string1 ? null
  3900. : string0 === string00 && string1 === string10 ? interpolate0
  3901. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3902. };
  3903. }
  3904. function attrFunctionNS(fullname, interpolate, value) {
  3905. var string00,
  3906. string10,
  3907. interpolate0;
  3908. return function() {
  3909. var string0, value1 = value(this), string1;
  3910. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3911. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3912. string1 = value1 + "";
  3913. return string0 === string1 ? null
  3914. : string0 === string00 && string1 === string10 ? interpolate0
  3915. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3916. };
  3917. }
  3918. function transition_attr(name, value) {
  3919. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
  3920. return this.attrTween(name, typeof value === "function"
  3921. ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
  3922. : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
  3923. : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
  3924. }
  3925. function attrInterpolate(name, i) {
  3926. return function(t) {
  3927. this.setAttribute(name, i.call(this, t));
  3928. };
  3929. }
  3930. function attrInterpolateNS(fullname, i) {
  3931. return function(t) {
  3932. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3933. };
  3934. }
  3935. function attrTweenNS(fullname, value) {
  3936. var t0, i0;
  3937. function tween() {
  3938. var i = value.apply(this, arguments);
  3939. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3940. return t0;
  3941. }
  3942. tween._value = value;
  3943. return tween;
  3944. }
  3945. function attrTween(name, value) {
  3946. var t0, i0;
  3947. function tween() {
  3948. var i = value.apply(this, arguments);
  3949. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3950. return t0;
  3951. }
  3952. tween._value = value;
  3953. return tween;
  3954. }
  3955. function transition_attrTween(name, value) {
  3956. var key = "attr." + name;
  3957. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3958. if (value == null) return this.tween(key, null);
  3959. if (typeof value !== "function") throw new Error;
  3960. var fullname = namespace(name);
  3961. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3962. }
  3963. function delayFunction(id, value) {
  3964. return function() {
  3965. init(this, id).delay = +value.apply(this, arguments);
  3966. };
  3967. }
  3968. function delayConstant(id, value) {
  3969. return value = +value, function() {
  3970. init(this, id).delay = value;
  3971. };
  3972. }
  3973. function transition_delay(value) {
  3974. var id = this._id;
  3975. return arguments.length
  3976. ? this.each((typeof value === "function"
  3977. ? delayFunction
  3978. : delayConstant)(id, value))
  3979. : get(this.node(), id).delay;
  3980. }
  3981. function durationFunction(id, value) {
  3982. return function() {
  3983. set(this, id).duration = +value.apply(this, arguments);
  3984. };
  3985. }
  3986. function durationConstant(id, value) {
  3987. return value = +value, function() {
  3988. set(this, id).duration = value;
  3989. };
  3990. }
  3991. function transition_duration(value) {
  3992. var id = this._id;
  3993. return arguments.length
  3994. ? this.each((typeof value === "function"
  3995. ? durationFunction
  3996. : durationConstant)(id, value))
  3997. : get(this.node(), id).duration;
  3998. }
  3999. function easeConstant(id, value) {
  4000. if (typeof value !== "function") throw new Error;
  4001. return function() {
  4002. set(this, id).ease = value;
  4003. };
  4004. }
  4005. function transition_ease(value) {
  4006. var id = this._id;
  4007. return arguments.length
  4008. ? this.each(easeConstant(id, value))
  4009. : get(this.node(), id).ease;
  4010. }
  4011. function easeVarying(id, value) {
  4012. return function() {
  4013. var v = value.apply(this, arguments);
  4014. if (typeof v !== "function") throw new Error;
  4015. set(this, id).ease = v;
  4016. };
  4017. }
  4018. function transition_easeVarying(value) {
  4019. if (typeof value !== "function") throw new Error;
  4020. return this.each(easeVarying(this._id, value));
  4021. }
  4022. function transition_filter(match) {
  4023. if (typeof match !== "function") match = matcher(match);
  4024. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4025. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  4026. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  4027. subgroup.push(node);
  4028. }
  4029. }
  4030. }
  4031. return new Transition(subgroups, this._parents, this._name, this._id);
  4032. }
  4033. function transition_merge(transition) {
  4034. if (transition._id !== this._id) throw new Error;
  4035. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  4036. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  4037. if (node = group0[i] || group1[i]) {
  4038. merge[i] = node;
  4039. }
  4040. }
  4041. }
  4042. for (; j < m0; ++j) {
  4043. merges[j] = groups0[j];
  4044. }
  4045. return new Transition(merges, this._parents, this._name, this._id);
  4046. }
  4047. function start(name) {
  4048. return (name + "").trim().split(/^|\s+/).every(function(t) {
  4049. var i = t.indexOf(".");
  4050. if (i >= 0) t = t.slice(0, i);
  4051. return !t || t === "start";
  4052. });
  4053. }
  4054. function onFunction(id, name, listener) {
  4055. var on0, on1, sit = start(name) ? init : set;
  4056. return function() {
  4057. var schedule = sit(this, id),
  4058. on = schedule.on;
  4059. // If this node shared a dispatch with the previous node,
  4060. // just assign the updated shared dispatch and we’re done!
  4061. // Otherwise, copy-on-write.
  4062. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  4063. schedule.on = on1;
  4064. };
  4065. }
  4066. function transition_on(name, listener) {
  4067. var id = this._id;
  4068. return arguments.length < 2
  4069. ? get(this.node(), id).on.on(name)
  4070. : this.each(onFunction(id, name, listener));
  4071. }
  4072. function removeFunction(id) {
  4073. return function() {
  4074. var parent = this.parentNode;
  4075. for (var i in this.__transition) if (+i !== id) return;
  4076. if (parent) parent.removeChild(this);
  4077. };
  4078. }
  4079. function transition_remove() {
  4080. return this.on("end.remove", removeFunction(this._id));
  4081. }
  4082. function transition_select(select) {
  4083. var name = this._name,
  4084. id = this._id;
  4085. if (typeof select !== "function") select = selector(select);
  4086. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4087. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  4088. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  4089. if ("__data__" in node) subnode.__data__ = node.__data__;
  4090. subgroup[i] = subnode;
  4091. schedule(subgroup[i], name, id, i, subgroup, get(node, id));
  4092. }
  4093. }
  4094. }
  4095. return new Transition(subgroups, this._parents, name, id);
  4096. }
  4097. function transition_selectAll(select) {
  4098. var name = this._name,
  4099. id = this._id;
  4100. if (typeof select !== "function") select = selectorAll(select);
  4101. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  4102. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4103. if (node = group[i]) {
  4104. for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
  4105. if (child = children[k]) {
  4106. schedule(child, name, id, k, children, inherit);
  4107. }
  4108. }
  4109. subgroups.push(children);
  4110. parents.push(node);
  4111. }
  4112. }
  4113. }
  4114. return new Transition(subgroups, parents, name, id);
  4115. }
  4116. var Selection = selection.prototype.constructor;
  4117. function transition_selection() {
  4118. return new Selection(this._groups, this._parents);
  4119. }
  4120. function styleNull(name, interpolate) {
  4121. var string00,
  4122. string10,
  4123. interpolate0;
  4124. return function() {
  4125. var string0 = styleValue(this, name),
  4126. string1 = (this.style.removeProperty(name), styleValue(this, name));
  4127. return string0 === string1 ? null
  4128. : string0 === string00 && string1 === string10 ? interpolate0
  4129. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  4130. };
  4131. }
  4132. function styleRemove(name) {
  4133. return function() {
  4134. this.style.removeProperty(name);
  4135. };
  4136. }
  4137. function styleConstant(name, interpolate, value1) {
  4138. var string00,
  4139. string1 = value1 + "",
  4140. interpolate0;
  4141. return function() {
  4142. var string0 = styleValue(this, name);
  4143. return string0 === string1 ? null
  4144. : string0 === string00 ? interpolate0
  4145. : interpolate0 = interpolate(string00 = string0, value1);
  4146. };
  4147. }
  4148. function styleFunction(name, interpolate, value) {
  4149. var string00,
  4150. string10,
  4151. interpolate0;
  4152. return function() {
  4153. var string0 = styleValue(this, name),
  4154. value1 = value(this),
  4155. string1 = value1 + "";
  4156. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  4157. return string0 === string1 ? null
  4158. : string0 === string00 && string1 === string10 ? interpolate0
  4159. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  4160. };
  4161. }
  4162. function styleMaybeRemove(id, name) {
  4163. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  4164. return function() {
  4165. var schedule = set(this, id),
  4166. on = schedule.on,
  4167. listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
  4168. // If this node shared a dispatch with the previous node,
  4169. // just assign the updated shared dispatch and we’re done!
  4170. // Otherwise, copy-on-write.
  4171. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  4172. schedule.on = on1;
  4173. };
  4174. }
  4175. function transition_style(name, value, priority) {
  4176. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
  4177. return value == null ? this
  4178. .styleTween(name, styleNull(name, i))
  4179. .on("end.style." + name, styleRemove(name))
  4180. : typeof value === "function" ? this
  4181. .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
  4182. .each(styleMaybeRemove(this._id, name))
  4183. : this
  4184. .styleTween(name, styleConstant(name, i, value), priority)
  4185. .on("end.style." + name, null);
  4186. }
  4187. function styleInterpolate(name, i, priority) {
  4188. return function(t) {
  4189. this.style.setProperty(name, i.call(this, t), priority);
  4190. };
  4191. }
  4192. function styleTween(name, value, priority) {
  4193. var t, i0;
  4194. function tween() {
  4195. var i = value.apply(this, arguments);
  4196. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  4197. return t;
  4198. }
  4199. tween._value = value;
  4200. return tween;
  4201. }
  4202. function transition_styleTween(name, value, priority) {
  4203. var key = "style." + (name += "");
  4204. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  4205. if (value == null) return this.tween(key, null);
  4206. if (typeof value !== "function") throw new Error;
  4207. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  4208. }
  4209. function textConstant(value) {
  4210. return function() {
  4211. this.textContent = value;
  4212. };
  4213. }
  4214. function textFunction(value) {
  4215. return function() {
  4216. var value1 = value(this);
  4217. this.textContent = value1 == null ? "" : value1;
  4218. };
  4219. }
  4220. function transition_text(value) {
  4221. return this.tween("text", typeof value === "function"
  4222. ? textFunction(tweenValue(this, "text", value))
  4223. : textConstant(value == null ? "" : value + ""));
  4224. }
  4225. function textInterpolate(i) {
  4226. return function(t) {
  4227. this.textContent = i.call(this, t);
  4228. };
  4229. }
  4230. function textTween(value) {
  4231. var t0, i0;
  4232. function tween() {
  4233. var i = value.apply(this, arguments);
  4234. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  4235. return t0;
  4236. }
  4237. tween._value = value;
  4238. return tween;
  4239. }
  4240. function transition_textTween(value) {
  4241. var key = "text";
  4242. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  4243. if (value == null) return this.tween(key, null);
  4244. if (typeof value !== "function") throw new Error;
  4245. return this.tween(key, textTween(value));
  4246. }
  4247. function transition_transition() {
  4248. var name = this._name,
  4249. id0 = this._id,
  4250. id1 = newId();
  4251. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4252. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4253. if (node = group[i]) {
  4254. var inherit = get(node, id0);
  4255. schedule(node, name, id1, i, group, {
  4256. time: inherit.time + inherit.delay + inherit.duration,
  4257. delay: 0,
  4258. duration: inherit.duration,
  4259. ease: inherit.ease
  4260. });
  4261. }
  4262. }
  4263. }
  4264. return new Transition(groups, this._parents, name, id1);
  4265. }
  4266. function transition_end() {
  4267. var on0, on1, that = this, id = that._id, size = that.size();
  4268. return new Promise(function(resolve, reject) {
  4269. var cancel = {value: reject},
  4270. end = {value: function() { if (--size === 0) resolve(); }};
  4271. that.each(function() {
  4272. var schedule = set(this, id),
  4273. on = schedule.on;
  4274. // If this node shared a dispatch with the previous node,
  4275. // just assign the updated shared dispatch and we’re done!
  4276. // Otherwise, copy-on-write.
  4277. if (on !== on0) {
  4278. on1 = (on0 = on).copy();
  4279. on1._.cancel.push(cancel);
  4280. on1._.interrupt.push(cancel);
  4281. on1._.end.push(end);
  4282. }
  4283. schedule.on = on1;
  4284. });
  4285. // The selection was empty, resolve end immediately
  4286. if (size === 0) resolve();
  4287. });
  4288. }
  4289. var id = 0;
  4290. function Transition(groups, parents, name, id) {
  4291. this._groups = groups;
  4292. this._parents = parents;
  4293. this._name = name;
  4294. this._id = id;
  4295. }
  4296. function transition(name) {
  4297. return selection().transition(name);
  4298. }
  4299. function newId() {
  4300. return ++id;
  4301. }
  4302. var selection_prototype = selection.prototype;
  4303. Transition.prototype = transition.prototype = {
  4304. constructor: Transition,
  4305. select: transition_select,
  4306. selectAll: transition_selectAll,
  4307. selectChild: selection_prototype.selectChild,
  4308. selectChildren: selection_prototype.selectChildren,
  4309. filter: transition_filter,
  4310. merge: transition_merge,
  4311. selection: transition_selection,
  4312. transition: transition_transition,
  4313. call: selection_prototype.call,
  4314. nodes: selection_prototype.nodes,
  4315. node: selection_prototype.node,
  4316. size: selection_prototype.size,
  4317. empty: selection_prototype.empty,
  4318. each: selection_prototype.each,
  4319. on: transition_on,
  4320. attr: transition_attr,
  4321. attrTween: transition_attrTween,
  4322. style: transition_style,
  4323. styleTween: transition_styleTween,
  4324. text: transition_text,
  4325. textTween: transition_textTween,
  4326. remove: transition_remove,
  4327. tween: transition_tween,
  4328. delay: transition_delay,
  4329. duration: transition_duration,
  4330. ease: transition_ease,
  4331. easeVarying: transition_easeVarying,
  4332. end: transition_end,
  4333. [Symbol.iterator]: selection_prototype[Symbol.iterator]
  4334. };
  4335. const linear$1 = t => +t;
  4336. function quadIn(t) {
  4337. return t * t;
  4338. }
  4339. function quadOut(t) {
  4340. return t * (2 - t);
  4341. }
  4342. function quadInOut(t) {
  4343. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  4344. }
  4345. function cubicIn(t) {
  4346. return t * t * t;
  4347. }
  4348. function cubicOut(t) {
  4349. return --t * t * t + 1;
  4350. }
  4351. function cubicInOut(t) {
  4352. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  4353. }
  4354. var exponent$1 = 3;
  4355. var polyIn = (function custom(e) {
  4356. e = +e;
  4357. function polyIn(t) {
  4358. return Math.pow(t, e);
  4359. }
  4360. polyIn.exponent = custom;
  4361. return polyIn;
  4362. })(exponent$1);
  4363. var polyOut = (function custom(e) {
  4364. e = +e;
  4365. function polyOut(t) {
  4366. return 1 - Math.pow(1 - t, e);
  4367. }
  4368. polyOut.exponent = custom;
  4369. return polyOut;
  4370. })(exponent$1);
  4371. var polyInOut = (function custom(e) {
  4372. e = +e;
  4373. function polyInOut(t) {
  4374. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  4375. }
  4376. polyInOut.exponent = custom;
  4377. return polyInOut;
  4378. })(exponent$1);
  4379. var pi$4 = Math.PI,
  4380. halfPi$3 = pi$4 / 2;
  4381. function sinIn(t) {
  4382. return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
  4383. }
  4384. function sinOut(t) {
  4385. return Math.sin(t * halfPi$3);
  4386. }
  4387. function sinInOut(t) {
  4388. return (1 - Math.cos(pi$4 * t)) / 2;
  4389. }
  4390. // tpmt is two power minus ten times t scaled to [0,1]
  4391. function tpmt(x) {
  4392. return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
  4393. }
  4394. function expIn(t) {
  4395. return tpmt(1 - +t);
  4396. }
  4397. function expOut(t) {
  4398. return 1 - tpmt(t);
  4399. }
  4400. function expInOut(t) {
  4401. return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
  4402. }
  4403. function circleIn(t) {
  4404. return 1 - Math.sqrt(1 - t * t);
  4405. }
  4406. function circleOut(t) {
  4407. return Math.sqrt(1 - --t * t);
  4408. }
  4409. function circleInOut(t) {
  4410. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  4411. }
  4412. var b1 = 4 / 11,
  4413. b2 = 6 / 11,
  4414. b3 = 8 / 11,
  4415. b4 = 3 / 4,
  4416. b5 = 9 / 11,
  4417. b6 = 10 / 11,
  4418. b7 = 15 / 16,
  4419. b8 = 21 / 22,
  4420. b9 = 63 / 64,
  4421. b0 = 1 / b1 / b1;
  4422. function bounceIn(t) {
  4423. return 1 - bounceOut(1 - t);
  4424. }
  4425. function bounceOut(t) {
  4426. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  4427. }
  4428. function bounceInOut(t) {
  4429. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  4430. }
  4431. var overshoot = 1.70158;
  4432. var backIn = (function custom(s) {
  4433. s = +s;
  4434. function backIn(t) {
  4435. return (t = +t) * t * (s * (t - 1) + t);
  4436. }
  4437. backIn.overshoot = custom;
  4438. return backIn;
  4439. })(overshoot);
  4440. var backOut = (function custom(s) {
  4441. s = +s;
  4442. function backOut(t) {
  4443. return --t * t * ((t + 1) * s + t) + 1;
  4444. }
  4445. backOut.overshoot = custom;
  4446. return backOut;
  4447. })(overshoot);
  4448. var backInOut = (function custom(s) {
  4449. s = +s;
  4450. function backInOut(t) {
  4451. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  4452. }
  4453. backInOut.overshoot = custom;
  4454. return backInOut;
  4455. })(overshoot);
  4456. var tau$5 = 2 * Math.PI,
  4457. amplitude = 1,
  4458. period = 0.3;
  4459. var elasticIn = (function custom(a, p) {
  4460. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4461. function elasticIn(t) {
  4462. return a * tpmt(-(--t)) * Math.sin((s - t) / p);
  4463. }
  4464. elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
  4465. elasticIn.period = function(p) { return custom(a, p); };
  4466. return elasticIn;
  4467. })(amplitude, period);
  4468. var elasticOut = (function custom(a, p) {
  4469. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4470. function elasticOut(t) {
  4471. return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
  4472. }
  4473. elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4474. elasticOut.period = function(p) { return custom(a, p); };
  4475. return elasticOut;
  4476. })(amplitude, period);
  4477. var elasticInOut = (function custom(a, p) {
  4478. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4479. function elasticInOut(t) {
  4480. return ((t = t * 2 - 1) < 0
  4481. ? a * tpmt(-t) * Math.sin((s - t) / p)
  4482. : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
  4483. }
  4484. elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4485. elasticInOut.period = function(p) { return custom(a, p); };
  4486. return elasticInOut;
  4487. })(amplitude, period);
  4488. var defaultTiming = {
  4489. time: null, // Set on use.
  4490. delay: 0,
  4491. duration: 250,
  4492. ease: cubicInOut
  4493. };
  4494. function inherit(node, id) {
  4495. var timing;
  4496. while (!(timing = node.__transition) || !(timing = timing[id])) {
  4497. if (!(node = node.parentNode)) {
  4498. throw new Error(`transition ${id} not found`);
  4499. }
  4500. }
  4501. return timing;
  4502. }
  4503. function selection_transition(name) {
  4504. var id,
  4505. timing;
  4506. if (name instanceof Transition) {
  4507. id = name._id, name = name._name;
  4508. } else {
  4509. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  4510. }
  4511. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4512. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4513. if (node = group[i]) {
  4514. schedule(node, name, id, i, group, timing || inherit(node, id));
  4515. }
  4516. }
  4517. }
  4518. return new Transition(groups, this._parents, name, id);
  4519. }
  4520. selection.prototype.interrupt = selection_interrupt;
  4521. selection.prototype.transition = selection_transition;
  4522. var root = [null];
  4523. function active(node, name) {
  4524. var schedules = node.__transition,
  4525. schedule,
  4526. i;
  4527. if (schedules) {
  4528. name = name == null ? null : name + "";
  4529. for (i in schedules) {
  4530. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  4531. return new Transition([[node]], root, name, +i);
  4532. }
  4533. }
  4534. }
  4535. return null;
  4536. }
  4537. var constant$7 = x => () => x;
  4538. function BrushEvent(type, {
  4539. sourceEvent,
  4540. target,
  4541. selection,
  4542. mode,
  4543. dispatch
  4544. }) {
  4545. Object.defineProperties(this, {
  4546. type: {value: type, enumerable: true, configurable: true},
  4547. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  4548. target: {value: target, enumerable: true, configurable: true},
  4549. selection: {value: selection, enumerable: true, configurable: true},
  4550. mode: {value: mode, enumerable: true, configurable: true},
  4551. _: {value: dispatch}
  4552. });
  4553. }
  4554. function nopropagation$1(event) {
  4555. event.stopImmediatePropagation();
  4556. }
  4557. function noevent$1(event) {
  4558. event.preventDefault();
  4559. event.stopImmediatePropagation();
  4560. }
  4561. var MODE_DRAG = {name: "drag"},
  4562. MODE_SPACE = {name: "space"},
  4563. MODE_HANDLE = {name: "handle"},
  4564. MODE_CENTER = {name: "center"};
  4565. const {abs: abs$3, max: max$2, min: min$1} = Math;
  4566. function number1(e) {
  4567. return [+e[0], +e[1]];
  4568. }
  4569. function number2(e) {
  4570. return [number1(e[0]), number1(e[1])];
  4571. }
  4572. var X = {
  4573. name: "x",
  4574. handles: ["w", "e"].map(type),
  4575. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  4576. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  4577. };
  4578. var Y = {
  4579. name: "y",
  4580. handles: ["n", "s"].map(type),
  4581. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  4582. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  4583. };
  4584. var XY = {
  4585. name: "xy",
  4586. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  4587. input: function(xy) { return xy == null ? null : number2(xy); },
  4588. output: function(xy) { return xy; }
  4589. };
  4590. var cursors = {
  4591. overlay: "crosshair",
  4592. selection: "move",
  4593. n: "ns-resize",
  4594. e: "ew-resize",
  4595. s: "ns-resize",
  4596. w: "ew-resize",
  4597. nw: "nwse-resize",
  4598. ne: "nesw-resize",
  4599. se: "nwse-resize",
  4600. sw: "nesw-resize"
  4601. };
  4602. var flipX = {
  4603. e: "w",
  4604. w: "e",
  4605. nw: "ne",
  4606. ne: "nw",
  4607. se: "sw",
  4608. sw: "se"
  4609. };
  4610. var flipY = {
  4611. n: "s",
  4612. s: "n",
  4613. nw: "sw",
  4614. ne: "se",
  4615. se: "ne",
  4616. sw: "nw"
  4617. };
  4618. var signsX = {
  4619. overlay: +1,
  4620. selection: +1,
  4621. n: null,
  4622. e: +1,
  4623. s: null,
  4624. w: -1,
  4625. nw: -1,
  4626. ne: +1,
  4627. se: +1,
  4628. sw: -1
  4629. };
  4630. var signsY = {
  4631. overlay: +1,
  4632. selection: +1,
  4633. n: -1,
  4634. e: null,
  4635. s: +1,
  4636. w: null,
  4637. nw: -1,
  4638. ne: -1,
  4639. se: +1,
  4640. sw: +1
  4641. };
  4642. function type(t) {
  4643. return {type: t};
  4644. }
  4645. // Ignore right-click, since that should open the context menu.
  4646. function defaultFilter$1(event) {
  4647. return !event.ctrlKey && !event.button;
  4648. }
  4649. function defaultExtent$1() {
  4650. var svg = this.ownerSVGElement || this;
  4651. if (svg.hasAttribute("viewBox")) {
  4652. svg = svg.viewBox.baseVal;
  4653. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  4654. }
  4655. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  4656. }
  4657. function defaultTouchable$1() {
  4658. return navigator.maxTouchPoints || ("ontouchstart" in this);
  4659. }
  4660. // Like d3.local, but with the name “__brush” rather than auto-generated.
  4661. function local(node) {
  4662. while (!node.__brush) if (!(node = node.parentNode)) return;
  4663. return node.__brush;
  4664. }
  4665. function empty(extent) {
  4666. return extent[0][0] === extent[1][0]
  4667. || extent[0][1] === extent[1][1];
  4668. }
  4669. function brushSelection(node) {
  4670. var state = node.__brush;
  4671. return state ? state.dim.output(state.selection) : null;
  4672. }
  4673. function brushX() {
  4674. return brush$1(X);
  4675. }
  4676. function brushY() {
  4677. return brush$1(Y);
  4678. }
  4679. function brush() {
  4680. return brush$1(XY);
  4681. }
  4682. function brush$1(dim) {
  4683. var extent = defaultExtent$1,
  4684. filter = defaultFilter$1,
  4685. touchable = defaultTouchable$1,
  4686. keys = true,
  4687. listeners = dispatch("start", "brush", "end"),
  4688. handleSize = 6,
  4689. touchending;
  4690. function brush(group) {
  4691. var overlay = group
  4692. .property("__brush", initialize)
  4693. .selectAll(".overlay")
  4694. .data([type("overlay")]);
  4695. overlay.enter().append("rect")
  4696. .attr("class", "overlay")
  4697. .attr("pointer-events", "all")
  4698. .attr("cursor", cursors.overlay)
  4699. .merge(overlay)
  4700. .each(function() {
  4701. var extent = local(this).extent;
  4702. select(this)
  4703. .attr("x", extent[0][0])
  4704. .attr("y", extent[0][1])
  4705. .attr("width", extent[1][0] - extent[0][0])
  4706. .attr("height", extent[1][1] - extent[0][1]);
  4707. });
  4708. group.selectAll(".selection")
  4709. .data([type("selection")])
  4710. .enter().append("rect")
  4711. .attr("class", "selection")
  4712. .attr("cursor", cursors.selection)
  4713. .attr("fill", "#777")
  4714. .attr("fill-opacity", 0.3)
  4715. .attr("stroke", "#fff")
  4716. .attr("shape-rendering", "crispEdges");
  4717. var handle = group.selectAll(".handle")
  4718. .data(dim.handles, function(d) { return d.type; });
  4719. handle.exit().remove();
  4720. handle.enter().append("rect")
  4721. .attr("class", function(d) { return "handle handle--" + d.type; })
  4722. .attr("cursor", function(d) { return cursors[d.type]; });
  4723. group
  4724. .each(redraw)
  4725. .attr("fill", "none")
  4726. .attr("pointer-events", "all")
  4727. .on("mousedown.brush", started)
  4728. .filter(touchable)
  4729. .on("touchstart.brush", started)
  4730. .on("touchmove.brush", touchmoved)
  4731. .on("touchend.brush touchcancel.brush", touchended)
  4732. .style("touch-action", "none")
  4733. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  4734. }
  4735. brush.move = function(group, selection, event) {
  4736. if (group.tween) {
  4737. group
  4738. .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
  4739. .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
  4740. .tween("brush", function() {
  4741. var that = this,
  4742. state = that.__brush,
  4743. emit = emitter(that, arguments),
  4744. selection0 = state.selection,
  4745. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  4746. i = interpolate$2(selection0, selection1);
  4747. function tween(t) {
  4748. state.selection = t === 1 && selection1 === null ? null : i(t);
  4749. redraw.call(that);
  4750. emit.brush();
  4751. }
  4752. return selection0 !== null && selection1 !== null ? tween : tween(1);
  4753. });
  4754. } else {
  4755. group
  4756. .each(function() {
  4757. var that = this,
  4758. args = arguments,
  4759. state = that.__brush,
  4760. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  4761. emit = emitter(that, args).beforestart();
  4762. interrupt(that);
  4763. state.selection = selection1 === null ? null : selection1;
  4764. redraw.call(that);
  4765. emit.start(event).brush(event).end(event);
  4766. });
  4767. }
  4768. };
  4769. brush.clear = function(group, event) {
  4770. brush.move(group, null, event);
  4771. };
  4772. function redraw() {
  4773. var group = select(this),
  4774. selection = local(this).selection;
  4775. if (selection) {
  4776. group.selectAll(".selection")
  4777. .style("display", null)
  4778. .attr("x", selection[0][0])
  4779. .attr("y", selection[0][1])
  4780. .attr("width", selection[1][0] - selection[0][0])
  4781. .attr("height", selection[1][1] - selection[0][1]);
  4782. group.selectAll(".handle")
  4783. .style("display", null)
  4784. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  4785. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  4786. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  4787. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  4788. }
  4789. else {
  4790. group.selectAll(".selection,.handle")
  4791. .style("display", "none")
  4792. .attr("x", null)
  4793. .attr("y", null)
  4794. .attr("width", null)
  4795. .attr("height", null);
  4796. }
  4797. }
  4798. function emitter(that, args, clean) {
  4799. var emit = that.__brush.emitter;
  4800. return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
  4801. }
  4802. function Emitter(that, args, clean) {
  4803. this.that = that;
  4804. this.args = args;
  4805. this.state = that.__brush;
  4806. this.active = 0;
  4807. this.clean = clean;
  4808. }
  4809. Emitter.prototype = {
  4810. beforestart: function() {
  4811. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  4812. return this;
  4813. },
  4814. start: function(event, mode) {
  4815. if (this.starting) this.starting = false, this.emit("start", event, mode);
  4816. else this.emit("brush", event);
  4817. return this;
  4818. },
  4819. brush: function(event, mode) {
  4820. this.emit("brush", event, mode);
  4821. return this;
  4822. },
  4823. end: function(event, mode) {
  4824. if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
  4825. return this;
  4826. },
  4827. emit: function(type, event, mode) {
  4828. var d = select(this.that).datum();
  4829. listeners.call(
  4830. type,
  4831. this.that,
  4832. new BrushEvent(type, {
  4833. sourceEvent: event,
  4834. target: brush,
  4835. selection: dim.output(this.state.selection),
  4836. mode,
  4837. dispatch: listeners
  4838. }),
  4839. d
  4840. );
  4841. }
  4842. };
  4843. function started(event) {
  4844. if (touchending && !event.touches) return;
  4845. if (!filter.apply(this, arguments)) return;
  4846. var that = this,
  4847. type = event.target.__data__.type,
  4848. mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
  4849. signX = dim === Y ? null : signsX[type],
  4850. signY = dim === X ? null : signsY[type],
  4851. state = local(that),
  4852. extent = state.extent,
  4853. selection = state.selection,
  4854. W = extent[0][0], w0, w1,
  4855. N = extent[0][1], n0, n1,
  4856. E = extent[1][0], e0, e1,
  4857. S = extent[1][1], s0, s1,
  4858. dx = 0,
  4859. dy = 0,
  4860. moving,
  4861. shifting = signX && signY && keys && event.shiftKey,
  4862. lockX,
  4863. lockY,
  4864. points = Array.from(event.touches || [event], t => {
  4865. const i = t.identifier;
  4866. t = pointer(t, that);
  4867. t.point0 = t.slice();
  4868. t.identifier = i;
  4869. return t;
  4870. });
  4871. interrupt(that);
  4872. var emit = emitter(that, arguments, true).beforestart();
  4873. if (type === "overlay") {
  4874. if (selection) moving = true;
  4875. const pts = [points[0], points[1] || points[0]];
  4876. state.selection = selection = [[
  4877. w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
  4878. n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
  4879. ], [
  4880. e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
  4881. s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
  4882. ]];
  4883. if (points.length > 1) move(event);
  4884. } else {
  4885. w0 = selection[0][0];
  4886. n0 = selection[0][1];
  4887. e0 = selection[1][0];
  4888. s0 = selection[1][1];
  4889. }
  4890. w1 = w0;
  4891. n1 = n0;
  4892. e1 = e0;
  4893. s1 = s0;
  4894. var group = select(that)
  4895. .attr("pointer-events", "none");
  4896. var overlay = group.selectAll(".overlay")
  4897. .attr("cursor", cursors[type]);
  4898. if (event.touches) {
  4899. emit.moved = moved;
  4900. emit.ended = ended;
  4901. } else {
  4902. var view = select(event.view)
  4903. .on("mousemove.brush", moved, true)
  4904. .on("mouseup.brush", ended, true);
  4905. if (keys) view
  4906. .on("keydown.brush", keydowned, true)
  4907. .on("keyup.brush", keyupped, true);
  4908. dragDisable(event.view);
  4909. }
  4910. redraw.call(that);
  4911. emit.start(event, mode.name);
  4912. function moved(event) {
  4913. for (const p of event.changedTouches || [event]) {
  4914. for (const d of points)
  4915. if (d.identifier === p.identifier) d.cur = pointer(p, that);
  4916. }
  4917. if (shifting && !lockX && !lockY && points.length === 1) {
  4918. const point = points[0];
  4919. if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
  4920. lockY = true;
  4921. else
  4922. lockX = true;
  4923. }
  4924. for (const point of points)
  4925. if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
  4926. moving = true;
  4927. noevent$1(event);
  4928. move(event);
  4929. }
  4930. function move(event) {
  4931. const point = points[0], point0 = point.point0;
  4932. var t;
  4933. dx = point[0] - point0[0];
  4934. dy = point[1] - point0[1];
  4935. switch (mode) {
  4936. case MODE_SPACE:
  4937. case MODE_DRAG: {
  4938. if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4939. if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4940. break;
  4941. }
  4942. case MODE_HANDLE: {
  4943. if (points[1]) {
  4944. if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
  4945. if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
  4946. } else {
  4947. if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4948. else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4949. if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4950. else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4951. }
  4952. break;
  4953. }
  4954. case MODE_CENTER: {
  4955. if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
  4956. if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
  4957. break;
  4958. }
  4959. }
  4960. if (e1 < w1) {
  4961. signX *= -1;
  4962. t = w0, w0 = e0, e0 = t;
  4963. t = w1, w1 = e1, e1 = t;
  4964. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4965. }
  4966. if (s1 < n1) {
  4967. signY *= -1;
  4968. t = n0, n0 = s0, s0 = t;
  4969. t = n1, n1 = s1, s1 = t;
  4970. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4971. }
  4972. if (state.selection) selection = state.selection; // May be set by brush.move!
  4973. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4974. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4975. if (selection[0][0] !== w1
  4976. || selection[0][1] !== n1
  4977. || selection[1][0] !== e1
  4978. || selection[1][1] !== s1) {
  4979. state.selection = [[w1, n1], [e1, s1]];
  4980. redraw.call(that);
  4981. emit.brush(event, mode.name);
  4982. }
  4983. }
  4984. function ended(event) {
  4985. nopropagation$1(event);
  4986. if (event.touches) {
  4987. if (event.touches.length) return;
  4988. if (touchending) clearTimeout(touchending);
  4989. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4990. } else {
  4991. yesdrag(event.view, moving);
  4992. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4993. }
  4994. group.attr("pointer-events", "all");
  4995. overlay.attr("cursor", cursors.overlay);
  4996. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4997. if (empty(selection)) state.selection = null, redraw.call(that);
  4998. emit.end(event, mode.name);
  4999. }
  5000. function keydowned(event) {
  5001. switch (event.keyCode) {
  5002. case 16: { // SHIFT
  5003. shifting = signX && signY;
  5004. break;
  5005. }
  5006. case 18: { // ALT
  5007. if (mode === MODE_HANDLE) {
  5008. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5009. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5010. mode = MODE_CENTER;
  5011. move(event);
  5012. }
  5013. break;
  5014. }
  5015. case 32: { // SPACE; takes priority over ALT
  5016. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  5017. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  5018. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  5019. mode = MODE_SPACE;
  5020. overlay.attr("cursor", cursors.selection);
  5021. move(event);
  5022. }
  5023. break;
  5024. }
  5025. default: return;
  5026. }
  5027. noevent$1(event);
  5028. }
  5029. function keyupped(event) {
  5030. switch (event.keyCode) {
  5031. case 16: { // SHIFT
  5032. if (shifting) {
  5033. lockX = lockY = shifting = false;
  5034. move(event);
  5035. }
  5036. break;
  5037. }
  5038. case 18: { // ALT
  5039. if (mode === MODE_CENTER) {
  5040. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5041. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5042. mode = MODE_HANDLE;
  5043. move(event);
  5044. }
  5045. break;
  5046. }
  5047. case 32: { // SPACE
  5048. if (mode === MODE_SPACE) {
  5049. if (event.altKey) {
  5050. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5051. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5052. mode = MODE_CENTER;
  5053. } else {
  5054. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5055. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5056. mode = MODE_HANDLE;
  5057. }
  5058. overlay.attr("cursor", cursors[type]);
  5059. move(event);
  5060. }
  5061. break;
  5062. }
  5063. default: return;
  5064. }
  5065. noevent$1(event);
  5066. }
  5067. }
  5068. function touchmoved(event) {
  5069. emitter(this, arguments).moved(event);
  5070. }
  5071. function touchended(event) {
  5072. emitter(this, arguments).ended(event);
  5073. }
  5074. function initialize() {
  5075. var state = this.__brush || {selection: null};
  5076. state.extent = number2(extent.apply(this, arguments));
  5077. state.dim = dim;
  5078. return state;
  5079. }
  5080. brush.extent = function(_) {
  5081. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
  5082. };
  5083. brush.filter = function(_) {
  5084. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
  5085. };
  5086. brush.touchable = function(_) {
  5087. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
  5088. };
  5089. brush.handleSize = function(_) {
  5090. return arguments.length ? (handleSize = +_, brush) : handleSize;
  5091. };
  5092. brush.keyModifiers = function(_) {
  5093. return arguments.length ? (keys = !!_, brush) : keys;
  5094. };
  5095. brush.on = function() {
  5096. var value = listeners.on.apply(listeners, arguments);
  5097. return value === listeners ? brush : value;
  5098. };
  5099. return brush;
  5100. }
  5101. var abs$2 = Math.abs;
  5102. var cos$2 = Math.cos;
  5103. var sin$2 = Math.sin;
  5104. var pi$3 = Math.PI;
  5105. var halfPi$2 = pi$3 / 2;
  5106. var tau$4 = pi$3 * 2;
  5107. var max$1 = Math.max;
  5108. var epsilon$5 = 1e-12;
  5109. function range$1(i, j) {
  5110. return Array.from({length: j - i}, (_, k) => i + k);
  5111. }
  5112. function compareValue(compare) {
  5113. return function(a, b) {
  5114. return compare(
  5115. a.source.value + a.target.value,
  5116. b.source.value + b.target.value
  5117. );
  5118. };
  5119. }
  5120. function chord() {
  5121. return chord$1(false, false);
  5122. }
  5123. function chordTranspose() {
  5124. return chord$1(false, true);
  5125. }
  5126. function chordDirected() {
  5127. return chord$1(true, false);
  5128. }
  5129. function chord$1(directed, transpose) {
  5130. var padAngle = 0,
  5131. sortGroups = null,
  5132. sortSubgroups = null,
  5133. sortChords = null;
  5134. function chord(matrix) {
  5135. var n = matrix.length,
  5136. groupSums = new Array(n),
  5137. groupIndex = range$1(0, n),
  5138. chords = new Array(n * n),
  5139. groups = new Array(n),
  5140. k = 0, dx;
  5141. matrix = Float64Array.from({length: n * n}, transpose
  5142. ? (_, i) => matrix[i % n][i / n | 0]
  5143. : (_, i) => matrix[i / n | 0][i % n]);
  5144. // Compute the scaling factor from value to angle in [0, 2pi].
  5145. for (let i = 0; i < n; ++i) {
  5146. let x = 0;
  5147. for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
  5148. k += groupSums[i] = x;
  5149. }
  5150. k = max$1(0, tau$4 - padAngle * n) / k;
  5151. dx = k ? padAngle : tau$4 / n;
  5152. // Compute the angles for each group and constituent chord.
  5153. {
  5154. let x = 0;
  5155. if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
  5156. for (const i of groupIndex) {
  5157. const x0 = x;
  5158. if (directed) {
  5159. const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
  5160. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b]));
  5161. for (const j of subgroupIndex) {
  5162. if (j < 0) {
  5163. const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
  5164. chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
  5165. } else {
  5166. const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5167. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5168. }
  5169. }
  5170. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5171. } else {
  5172. const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
  5173. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
  5174. for (const j of subgroupIndex) {
  5175. let chord;
  5176. if (i < j) {
  5177. chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5178. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5179. } else {
  5180. chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
  5181. chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5182. if (i === j) chord.source = chord.target;
  5183. }
  5184. if (chord.source && chord.target && chord.source.value < chord.target.value) {
  5185. const source = chord.source;
  5186. chord.source = chord.target;
  5187. chord.target = source;
  5188. }
  5189. }
  5190. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5191. }
  5192. x += dx;
  5193. }
  5194. }
  5195. // Remove empty chords.
  5196. chords = Object.values(chords);
  5197. chords.groups = groups;
  5198. return sortChords ? chords.sort(sortChords) : chords;
  5199. }
  5200. chord.padAngle = function(_) {
  5201. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  5202. };
  5203. chord.sortGroups = function(_) {
  5204. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  5205. };
  5206. chord.sortSubgroups = function(_) {
  5207. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  5208. };
  5209. chord.sortChords = function(_) {
  5210. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  5211. };
  5212. return chord;
  5213. }
  5214. const pi$2 = Math.PI,
  5215. tau$3 = 2 * pi$2,
  5216. epsilon$4 = 1e-6,
  5217. tauEpsilon = tau$3 - epsilon$4;
  5218. function append$1(strings) {
  5219. this._ += strings[0];
  5220. for (let i = 1, n = strings.length; i < n; ++i) {
  5221. this._ += arguments[i] + strings[i];
  5222. }
  5223. }
  5224. function appendRound$1(digits) {
  5225. let d = Math.floor(digits);
  5226. if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`);
  5227. if (d > 15) return append$1;
  5228. const k = 10 ** d;
  5229. return function(strings) {
  5230. this._ += strings[0];
  5231. for (let i = 1, n = strings.length; i < n; ++i) {
  5232. this._ += Math.round(arguments[i] * k) / k + strings[i];
  5233. }
  5234. };
  5235. }
  5236. let Path$1 = class Path {
  5237. constructor(digits) {
  5238. this._x0 = this._y0 = // start of current subpath
  5239. this._x1 = this._y1 = null; // end of current subpath
  5240. this._ = "";
  5241. this._append = digits == null ? append$1 : appendRound$1(digits);
  5242. }
  5243. moveTo(x, y) {
  5244. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  5245. }
  5246. closePath() {
  5247. if (this._x1 !== null) {
  5248. this._x1 = this._x0, this._y1 = this._y0;
  5249. this._append`Z`;
  5250. }
  5251. }
  5252. lineTo(x, y) {
  5253. this._append`L${this._x1 = +x},${this._y1 = +y}`;
  5254. }
  5255. quadraticCurveTo(x1, y1, x, y) {
  5256. this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`;
  5257. }
  5258. bezierCurveTo(x1, y1, x2, y2, x, y) {
  5259. this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
  5260. }
  5261. arcTo(x1, y1, x2, y2, r) {
  5262. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  5263. // Is the radius negative? Error.
  5264. if (r < 0) throw new Error(`negative radius: ${r}`);
  5265. let x0 = this._x1,
  5266. y0 = this._y1,
  5267. x21 = x2 - x1,
  5268. y21 = y2 - y1,
  5269. x01 = x0 - x1,
  5270. y01 = y0 - y1,
  5271. l01_2 = x01 * x01 + y01 * y01;
  5272. // Is this path empty? Move to (x1,y1).
  5273. if (this._x1 === null) {
  5274. this._append`M${this._x1 = x1},${this._y1 = y1}`;
  5275. }
  5276. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  5277. else if (!(l01_2 > epsilon$4));
  5278. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  5279. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  5280. // Or, is the radius zero? Line to (x1,y1).
  5281. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
  5282. this._append`L${this._x1 = x1},${this._y1 = y1}`;
  5283. }
  5284. // Otherwise, draw an arc!
  5285. else {
  5286. let x20 = x2 - x0,
  5287. y20 = y2 - y0,
  5288. l21_2 = x21 * x21 + y21 * y21,
  5289. l20_2 = x20 * x20 + y20 * y20,
  5290. l21 = Math.sqrt(l21_2),
  5291. l01 = Math.sqrt(l01_2),
  5292. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  5293. t01 = l / l01,
  5294. t21 = l / l21;
  5295. // If the start tangent is not coincident with (x0,y0), line to.
  5296. if (Math.abs(t01 - 1) > epsilon$4) {
  5297. this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
  5298. }
  5299. this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
  5300. }
  5301. }
  5302. arc(x, y, r, a0, a1, ccw) {
  5303. x = +x, y = +y, r = +r, ccw = !!ccw;
  5304. // Is the radius negative? Error.
  5305. if (r < 0) throw new Error(`negative radius: ${r}`);
  5306. let dx = r * Math.cos(a0),
  5307. dy = r * Math.sin(a0),
  5308. x0 = x + dx,
  5309. y0 = y + dy,
  5310. cw = 1 ^ ccw,
  5311. da = ccw ? a0 - a1 : a1 - a0;
  5312. // Is this path empty? Move to (x0,y0).
  5313. if (this._x1 === null) {
  5314. this._append`M${x0},${y0}`;
  5315. }
  5316. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  5317. else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) {
  5318. this._append`L${x0},${y0}`;
  5319. }
  5320. // Is this arc empty? We’re done.
  5321. if (!r) return;
  5322. // Does the angle go the wrong way? Flip the direction.
  5323. if (da < 0) da = da % tau$3 + tau$3;
  5324. // Is this a complete circle? Draw two arcs to complete the circle.
  5325. if (da > tauEpsilon) {
  5326. this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`;
  5327. }
  5328. // Is this arc non-empty? Draw an arc!
  5329. else if (da > epsilon$4) {
  5330. this._append`A${r},${r},0,${+(da >= pi$2)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`;
  5331. }
  5332. }
  5333. rect(x, y, w, h) {
  5334. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`;
  5335. }
  5336. toString() {
  5337. return this._;
  5338. }
  5339. };
  5340. function path() {
  5341. return new Path$1;
  5342. }
  5343. // Allow instanceof d3.path
  5344. path.prototype = Path$1.prototype;
  5345. function pathRound(digits = 3) {
  5346. return new Path$1(+digits);
  5347. }
  5348. var slice$2 = Array.prototype.slice;
  5349. function constant$6(x) {
  5350. return function() {
  5351. return x;
  5352. };
  5353. }
  5354. function defaultSource$1(d) {
  5355. return d.source;
  5356. }
  5357. function defaultTarget(d) {
  5358. return d.target;
  5359. }
  5360. function defaultRadius$1(d) {
  5361. return d.radius;
  5362. }
  5363. function defaultStartAngle(d) {
  5364. return d.startAngle;
  5365. }
  5366. function defaultEndAngle(d) {
  5367. return d.endAngle;
  5368. }
  5369. function defaultPadAngle() {
  5370. return 0;
  5371. }
  5372. function defaultArrowheadRadius() {
  5373. return 10;
  5374. }
  5375. function ribbon(headRadius) {
  5376. var source = defaultSource$1,
  5377. target = defaultTarget,
  5378. sourceRadius = defaultRadius$1,
  5379. targetRadius = defaultRadius$1,
  5380. startAngle = defaultStartAngle,
  5381. endAngle = defaultEndAngle,
  5382. padAngle = defaultPadAngle,
  5383. context = null;
  5384. function ribbon() {
  5385. var buffer,
  5386. s = source.apply(this, arguments),
  5387. t = target.apply(this, arguments),
  5388. ap = padAngle.apply(this, arguments) / 2,
  5389. argv = slice$2.call(arguments),
  5390. sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
  5391. sa0 = startAngle.apply(this, argv) - halfPi$2,
  5392. sa1 = endAngle.apply(this, argv) - halfPi$2,
  5393. tr = +targetRadius.apply(this, (argv[0] = t, argv)),
  5394. ta0 = startAngle.apply(this, argv) - halfPi$2,
  5395. ta1 = endAngle.apply(this, argv) - halfPi$2;
  5396. if (!context) context = buffer = path();
  5397. if (ap > epsilon$5) {
  5398. if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
  5399. else sa0 = sa1 = (sa0 + sa1) / 2;
  5400. if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
  5401. else ta0 = ta1 = (ta0 + ta1) / 2;
  5402. }
  5403. context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
  5404. context.arc(0, 0, sr, sa0, sa1);
  5405. if (sa0 !== ta0 || sa1 !== ta1) {
  5406. if (headRadius) {
  5407. var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
  5408. context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
  5409. context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
  5410. context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
  5411. } else {
  5412. context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
  5413. context.arc(0, 0, tr, ta0, ta1);
  5414. }
  5415. }
  5416. context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
  5417. context.closePath();
  5418. if (buffer) return context = null, buffer + "" || null;
  5419. }
  5420. if (headRadius) ribbon.headRadius = function(_) {
  5421. return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
  5422. };
  5423. ribbon.radius = function(_) {
  5424. return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5425. };
  5426. ribbon.sourceRadius = function(_) {
  5427. return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5428. };
  5429. ribbon.targetRadius = function(_) {
  5430. return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
  5431. };
  5432. ribbon.startAngle = function(_) {
  5433. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
  5434. };
  5435. ribbon.endAngle = function(_) {
  5436. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
  5437. };
  5438. ribbon.padAngle = function(_) {
  5439. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
  5440. };
  5441. ribbon.source = function(_) {
  5442. return arguments.length ? (source = _, ribbon) : source;
  5443. };
  5444. ribbon.target = function(_) {
  5445. return arguments.length ? (target = _, ribbon) : target;
  5446. };
  5447. ribbon.context = function(_) {
  5448. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  5449. };
  5450. return ribbon;
  5451. }
  5452. function ribbon$1() {
  5453. return ribbon();
  5454. }
  5455. function ribbonArrow() {
  5456. return ribbon(defaultArrowheadRadius);
  5457. }
  5458. var array$2 = Array.prototype;
  5459. var slice$1 = array$2.slice;
  5460. function ascending$1(a, b) {
  5461. return a - b;
  5462. }
  5463. function area$3(ring) {
  5464. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  5465. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  5466. return area;
  5467. }
  5468. var constant$5 = x => () => x;
  5469. function contains$2(ring, hole) {
  5470. var i = -1, n = hole.length, c;
  5471. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  5472. return 0;
  5473. }
  5474. function ringContains(ring, point) {
  5475. var x = point[0], y = point[1], contains = -1;
  5476. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  5477. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  5478. if (segmentContains(pi, pj, point)) return 0;
  5479. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  5480. }
  5481. return contains;
  5482. }
  5483. function segmentContains(a, b, c) {
  5484. var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  5485. }
  5486. function collinear$1(a, b, c) {
  5487. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  5488. }
  5489. function within(p, q, r) {
  5490. return p <= q && q <= r || r <= q && q <= p;
  5491. }
  5492. function noop$2() {}
  5493. var cases = [
  5494. [],
  5495. [[[1.0, 1.5], [0.5, 1.0]]],
  5496. [[[1.5, 1.0], [1.0, 1.5]]],
  5497. [[[1.5, 1.0], [0.5, 1.0]]],
  5498. [[[1.0, 0.5], [1.5, 1.0]]],
  5499. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  5500. [[[1.0, 0.5], [1.0, 1.5]]],
  5501. [[[1.0, 0.5], [0.5, 1.0]]],
  5502. [[[0.5, 1.0], [1.0, 0.5]]],
  5503. [[[1.0, 1.5], [1.0, 0.5]]],
  5504. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  5505. [[[1.5, 1.0], [1.0, 0.5]]],
  5506. [[[0.5, 1.0], [1.5, 1.0]]],
  5507. [[[1.0, 1.5], [1.5, 1.0]]],
  5508. [[[0.5, 1.0], [1.0, 1.5]]],
  5509. []
  5510. ];
  5511. function Contours() {
  5512. var dx = 1,
  5513. dy = 1,
  5514. threshold = thresholdSturges,
  5515. smooth = smoothLinear;
  5516. function contours(values) {
  5517. var tz = threshold(values);
  5518. // Convert number of thresholds into uniform thresholds.
  5519. if (!Array.isArray(tz)) {
  5520. const e = extent$1(values), ts = tickStep(e[0], e[1], tz);
  5521. tz = ticks(Math.floor(e[0] / ts) * ts, Math.floor(e[1] / ts - 1) * ts, tz);
  5522. } else {
  5523. tz = tz.slice().sort(ascending$1);
  5524. }
  5525. return tz.map(value => contour(values, value));
  5526. }
  5527. // Accumulate, smooth contour rings, assign holes to exterior rings.
  5528. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  5529. function contour(values, value) {
  5530. var polygons = [],
  5531. holes = [];
  5532. isorings(values, value, function(ring) {
  5533. smooth(ring, values, value);
  5534. if (area$3(ring) > 0) polygons.push([ring]);
  5535. else holes.push(ring);
  5536. });
  5537. holes.forEach(function(hole) {
  5538. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  5539. if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
  5540. polygon.push(hole);
  5541. return;
  5542. }
  5543. }
  5544. });
  5545. return {
  5546. type: "MultiPolygon",
  5547. value: value,
  5548. coordinates: polygons
  5549. };
  5550. }
  5551. // Marching squares with isolines stitched into rings.
  5552. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  5553. function isorings(values, value, callback) {
  5554. var fragmentByStart = new Array,
  5555. fragmentByEnd = new Array,
  5556. x, y, t0, t1, t2, t3;
  5557. // Special case for the first row (y = -1, t2 = t3 = 0).
  5558. x = y = -1;
  5559. t1 = values[0] >= value;
  5560. cases[t1 << 1].forEach(stitch);
  5561. while (++x < dx - 1) {
  5562. t0 = t1, t1 = values[x + 1] >= value;
  5563. cases[t0 | t1 << 1].forEach(stitch);
  5564. }
  5565. cases[t1 << 0].forEach(stitch);
  5566. // General case for the intermediate rows.
  5567. while (++y < dy - 1) {
  5568. x = -1;
  5569. t1 = values[y * dx + dx] >= value;
  5570. t2 = values[y * dx] >= value;
  5571. cases[t1 << 1 | t2 << 2].forEach(stitch);
  5572. while (++x < dx - 1) {
  5573. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  5574. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  5575. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  5576. }
  5577. cases[t1 | t2 << 3].forEach(stitch);
  5578. }
  5579. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  5580. x = -1;
  5581. t2 = values[y * dx] >= value;
  5582. cases[t2 << 2].forEach(stitch);
  5583. while (++x < dx - 1) {
  5584. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  5585. cases[t2 << 2 | t3 << 3].forEach(stitch);
  5586. }
  5587. cases[t2 << 3].forEach(stitch);
  5588. function stitch(line) {
  5589. var start = [line[0][0] + x, line[0][1] + y],
  5590. end = [line[1][0] + x, line[1][1] + y],
  5591. startIndex = index(start),
  5592. endIndex = index(end),
  5593. f, g;
  5594. if (f = fragmentByEnd[startIndex]) {
  5595. if (g = fragmentByStart[endIndex]) {
  5596. delete fragmentByEnd[f.end];
  5597. delete fragmentByStart[g.start];
  5598. if (f === g) {
  5599. f.ring.push(end);
  5600. callback(f.ring);
  5601. } else {
  5602. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  5603. }
  5604. } else {
  5605. delete fragmentByEnd[f.end];
  5606. f.ring.push(end);
  5607. fragmentByEnd[f.end = endIndex] = f;
  5608. }
  5609. } else if (f = fragmentByStart[endIndex]) {
  5610. if (g = fragmentByEnd[startIndex]) {
  5611. delete fragmentByStart[f.start];
  5612. delete fragmentByEnd[g.end];
  5613. if (f === g) {
  5614. f.ring.push(end);
  5615. callback(f.ring);
  5616. } else {
  5617. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  5618. }
  5619. } else {
  5620. delete fragmentByStart[f.start];
  5621. f.ring.unshift(start);
  5622. fragmentByStart[f.start = startIndex] = f;
  5623. }
  5624. } else {
  5625. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  5626. }
  5627. }
  5628. }
  5629. function index(point) {
  5630. return point[0] * 2 + point[1] * (dx + 1) * 4;
  5631. }
  5632. function smoothLinear(ring, values, value) {
  5633. ring.forEach(function(point) {
  5634. var x = point[0],
  5635. y = point[1],
  5636. xt = x | 0,
  5637. yt = y | 0,
  5638. v0,
  5639. v1 = values[yt * dx + xt];
  5640. if (x > 0 && x < dx && xt === x) {
  5641. v0 = values[yt * dx + xt - 1];
  5642. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  5643. }
  5644. if (y > 0 && y < dy && yt === y) {
  5645. v0 = values[(yt - 1) * dx + xt];
  5646. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  5647. }
  5648. });
  5649. }
  5650. contours.contour = contour;
  5651. contours.size = function(_) {
  5652. if (!arguments.length) return [dx, dy];
  5653. var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
  5654. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5655. return dx = _0, dy = _1, contours;
  5656. };
  5657. contours.thresholds = function(_) {
  5658. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
  5659. };
  5660. contours.smooth = function(_) {
  5661. return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
  5662. };
  5663. return contours;
  5664. }
  5665. function defaultX$1(d) {
  5666. return d[0];
  5667. }
  5668. function defaultY$1(d) {
  5669. return d[1];
  5670. }
  5671. function defaultWeight() {
  5672. return 1;
  5673. }
  5674. function density() {
  5675. var x = defaultX$1,
  5676. y = defaultY$1,
  5677. weight = defaultWeight,
  5678. dx = 960,
  5679. dy = 500,
  5680. r = 20, // blur radius
  5681. k = 2, // log2(grid cell size)
  5682. o = r * 3, // grid offset, to pad for blur
  5683. n = (dx + o * 2) >> k, // grid width
  5684. m = (dy + o * 2) >> k, // grid height
  5685. threshold = constant$5(20);
  5686. function grid(data) {
  5687. var values = new Float32Array(n * m),
  5688. pow2k = Math.pow(2, -k),
  5689. i = -1;
  5690. for (const d of data) {
  5691. var xi = (x(d, ++i, data) + o) * pow2k,
  5692. yi = (y(d, i, data) + o) * pow2k,
  5693. wi = +weight(d, i, data);
  5694. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  5695. var x0 = Math.floor(xi),
  5696. y0 = Math.floor(yi),
  5697. xt = xi - x0 - 0.5,
  5698. yt = yi - y0 - 0.5;
  5699. values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
  5700. values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
  5701. values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
  5702. values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
  5703. }
  5704. }
  5705. blur2({data: values, width: n, height: m}, r * pow2k);
  5706. return values;
  5707. }
  5708. function density(data) {
  5709. var values = grid(data),
  5710. tz = threshold(values),
  5711. pow4k = Math.pow(2, 2 * k);
  5712. // Convert number of thresholds into uniform thresholds.
  5713. if (!Array.isArray(tz)) {
  5714. tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
  5715. }
  5716. return Contours()
  5717. .size([n, m])
  5718. .thresholds(tz.map(d => d * pow4k))
  5719. (values)
  5720. .map((c, i) => (c.value = +tz[i], transform(c)));
  5721. }
  5722. density.contours = function(data) {
  5723. var values = grid(data),
  5724. contours = Contours().size([n, m]),
  5725. pow4k = Math.pow(2, 2 * k),
  5726. contour = value => {
  5727. value = +value;
  5728. var c = transform(contours.contour(values, value * pow4k));
  5729. c.value = value; // preserve exact threshold value
  5730. return c;
  5731. };
  5732. Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k});
  5733. return contour;
  5734. };
  5735. function transform(geometry) {
  5736. geometry.coordinates.forEach(transformPolygon);
  5737. return geometry;
  5738. }
  5739. function transformPolygon(coordinates) {
  5740. coordinates.forEach(transformRing);
  5741. }
  5742. function transformRing(coordinates) {
  5743. coordinates.forEach(transformPoint);
  5744. }
  5745. // TODO Optimize.
  5746. function transformPoint(coordinates) {
  5747. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  5748. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  5749. }
  5750. function resize() {
  5751. o = r * 3;
  5752. n = (dx + o * 2) >> k;
  5753. m = (dy + o * 2) >> k;
  5754. return density;
  5755. }
  5756. density.x = function(_) {
  5757. return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
  5758. };
  5759. density.y = function(_) {
  5760. return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
  5761. };
  5762. density.weight = function(_) {
  5763. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
  5764. };
  5765. density.size = function(_) {
  5766. if (!arguments.length) return [dx, dy];
  5767. var _0 = +_[0], _1 = +_[1];
  5768. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5769. return dx = _0, dy = _1, resize();
  5770. };
  5771. density.cellSize = function(_) {
  5772. if (!arguments.length) return 1 << k;
  5773. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5774. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5775. };
  5776. density.thresholds = function(_) {
  5777. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
  5778. };
  5779. density.bandwidth = function(_) {
  5780. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5781. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5782. return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize();
  5783. };
  5784. return density;
  5785. }
  5786. const epsilon$3 = 1.1102230246251565e-16;
  5787. const splitter = 134217729;
  5788. const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3;
  5789. // fast_expansion_sum_zeroelim routine from oritinal code
  5790. function sum$1(elen, e, flen, f, h) {
  5791. let Q, Qnew, hh, bvirt;
  5792. let enow = e[0];
  5793. let fnow = f[0];
  5794. let eindex = 0;
  5795. let findex = 0;
  5796. if ((fnow > enow) === (fnow > -enow)) {
  5797. Q = enow;
  5798. enow = e[++eindex];
  5799. } else {
  5800. Q = fnow;
  5801. fnow = f[++findex];
  5802. }
  5803. let hindex = 0;
  5804. if (eindex < elen && findex < flen) {
  5805. if ((fnow > enow) === (fnow > -enow)) {
  5806. Qnew = enow + Q;
  5807. hh = Q - (Qnew - enow);
  5808. enow = e[++eindex];
  5809. } else {
  5810. Qnew = fnow + Q;
  5811. hh = Q - (Qnew - fnow);
  5812. fnow = f[++findex];
  5813. }
  5814. Q = Qnew;
  5815. if (hh !== 0) {
  5816. h[hindex++] = hh;
  5817. }
  5818. while (eindex < elen && findex < flen) {
  5819. if ((fnow > enow) === (fnow > -enow)) {
  5820. Qnew = Q + enow;
  5821. bvirt = Qnew - Q;
  5822. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5823. enow = e[++eindex];
  5824. } else {
  5825. Qnew = Q + fnow;
  5826. bvirt = Qnew - Q;
  5827. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5828. fnow = f[++findex];
  5829. }
  5830. Q = Qnew;
  5831. if (hh !== 0) {
  5832. h[hindex++] = hh;
  5833. }
  5834. }
  5835. }
  5836. while (eindex < elen) {
  5837. Qnew = Q + enow;
  5838. bvirt = Qnew - Q;
  5839. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5840. enow = e[++eindex];
  5841. Q = Qnew;
  5842. if (hh !== 0) {
  5843. h[hindex++] = hh;
  5844. }
  5845. }
  5846. while (findex < flen) {
  5847. Qnew = Q + fnow;
  5848. bvirt = Qnew - Q;
  5849. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5850. fnow = f[++findex];
  5851. Q = Qnew;
  5852. if (hh !== 0) {
  5853. h[hindex++] = hh;
  5854. }
  5855. }
  5856. if (Q !== 0 || hindex === 0) {
  5857. h[hindex++] = Q;
  5858. }
  5859. return hindex;
  5860. }
  5861. function estimate(elen, e) {
  5862. let Q = e[0];
  5863. for (let i = 1; i < elen; i++) Q += e[i];
  5864. return Q;
  5865. }
  5866. function vec(n) {
  5867. return new Float64Array(n);
  5868. }
  5869. const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3;
  5870. const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3;
  5871. const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3;
  5872. const B = vec(4);
  5873. const C1 = vec(8);
  5874. const C2 = vec(12);
  5875. const D = vec(16);
  5876. const u = vec(4);
  5877. function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
  5878. let acxtail, acytail, bcxtail, bcytail;
  5879. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  5880. const acx = ax - cx;
  5881. const bcx = bx - cx;
  5882. const acy = ay - cy;
  5883. const bcy = by - cy;
  5884. s1 = acx * bcy;
  5885. c = splitter * acx;
  5886. ahi = c - (c - acx);
  5887. alo = acx - ahi;
  5888. c = splitter * bcy;
  5889. bhi = c - (c - bcy);
  5890. blo = bcy - bhi;
  5891. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5892. t1 = acy * bcx;
  5893. c = splitter * acy;
  5894. ahi = c - (c - acy);
  5895. alo = acy - ahi;
  5896. c = splitter * bcx;
  5897. bhi = c - (c - bcx);
  5898. blo = bcx - bhi;
  5899. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5900. _i = s0 - t0;
  5901. bvirt = s0 - _i;
  5902. B[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5903. _j = s1 + _i;
  5904. bvirt = _j - s1;
  5905. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5906. _i = _0 - t1;
  5907. bvirt = _0 - _i;
  5908. B[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5909. u3 = _j + _i;
  5910. bvirt = u3 - _j;
  5911. B[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5912. B[3] = u3;
  5913. let det = estimate(4, B);
  5914. let errbound = ccwerrboundB * detsum;
  5915. if (det >= errbound || -det >= errbound) {
  5916. return det;
  5917. }
  5918. bvirt = ax - acx;
  5919. acxtail = ax - (acx + bvirt) + (bvirt - cx);
  5920. bvirt = bx - bcx;
  5921. bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
  5922. bvirt = ay - acy;
  5923. acytail = ay - (acy + bvirt) + (bvirt - cy);
  5924. bvirt = by - bcy;
  5925. bcytail = by - (bcy + bvirt) + (bvirt - cy);
  5926. if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
  5927. return det;
  5928. }
  5929. errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
  5930. det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
  5931. if (det >= errbound || -det >= errbound) return det;
  5932. s1 = acxtail * bcy;
  5933. c = splitter * acxtail;
  5934. ahi = c - (c - acxtail);
  5935. alo = acxtail - ahi;
  5936. c = splitter * bcy;
  5937. bhi = c - (c - bcy);
  5938. blo = bcy - bhi;
  5939. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5940. t1 = acytail * bcx;
  5941. c = splitter * acytail;
  5942. ahi = c - (c - acytail);
  5943. alo = acytail - ahi;
  5944. c = splitter * bcx;
  5945. bhi = c - (c - bcx);
  5946. blo = bcx - bhi;
  5947. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5948. _i = s0 - t0;
  5949. bvirt = s0 - _i;
  5950. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5951. _j = s1 + _i;
  5952. bvirt = _j - s1;
  5953. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5954. _i = _0 - t1;
  5955. bvirt = _0 - _i;
  5956. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5957. u3 = _j + _i;
  5958. bvirt = u3 - _j;
  5959. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5960. u[3] = u3;
  5961. const C1len = sum$1(4, B, 4, u, C1);
  5962. s1 = acx * bcytail;
  5963. c = splitter * acx;
  5964. ahi = c - (c - acx);
  5965. alo = acx - ahi;
  5966. c = splitter * bcytail;
  5967. bhi = c - (c - bcytail);
  5968. blo = bcytail - bhi;
  5969. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5970. t1 = acy * bcxtail;
  5971. c = splitter * acy;
  5972. ahi = c - (c - acy);
  5973. alo = acy - ahi;
  5974. c = splitter * bcxtail;
  5975. bhi = c - (c - bcxtail);
  5976. blo = bcxtail - bhi;
  5977. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5978. _i = s0 - t0;
  5979. bvirt = s0 - _i;
  5980. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5981. _j = s1 + _i;
  5982. bvirt = _j - s1;
  5983. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5984. _i = _0 - t1;
  5985. bvirt = _0 - _i;
  5986. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5987. u3 = _j + _i;
  5988. bvirt = u3 - _j;
  5989. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5990. u[3] = u3;
  5991. const C2len = sum$1(C1len, C1, 4, u, C2);
  5992. s1 = acxtail * bcytail;
  5993. c = splitter * acxtail;
  5994. ahi = c - (c - acxtail);
  5995. alo = acxtail - ahi;
  5996. c = splitter * bcytail;
  5997. bhi = c - (c - bcytail);
  5998. blo = bcytail - bhi;
  5999. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  6000. t1 = acytail * bcxtail;
  6001. c = splitter * acytail;
  6002. ahi = c - (c - acytail);
  6003. alo = acytail - ahi;
  6004. c = splitter * bcxtail;
  6005. bhi = c - (c - bcxtail);
  6006. blo = bcxtail - bhi;
  6007. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  6008. _i = s0 - t0;
  6009. bvirt = s0 - _i;
  6010. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  6011. _j = s1 + _i;
  6012. bvirt = _j - s1;
  6013. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  6014. _i = _0 - t1;
  6015. bvirt = _0 - _i;
  6016. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  6017. u3 = _j + _i;
  6018. bvirt = u3 - _j;
  6019. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  6020. u[3] = u3;
  6021. const Dlen = sum$1(C2len, C2, 4, u, D);
  6022. return D[Dlen - 1];
  6023. }
  6024. function orient2d(ax, ay, bx, by, cx, cy) {
  6025. const detleft = (ay - cy) * (bx - cx);
  6026. const detright = (ax - cx) * (by - cy);
  6027. const det = detleft - detright;
  6028. if (detleft === 0 || detright === 0 || (detleft > 0) !== (detright > 0)) return det;
  6029. const detsum = Math.abs(detleft + detright);
  6030. if (Math.abs(det) >= ccwerrboundA * detsum) return det;
  6031. return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
  6032. }
  6033. const EPSILON = Math.pow(2, -52);
  6034. const EDGE_STACK = new Uint32Array(512);
  6035. class Delaunator {
  6036. static from(points, getX = defaultGetX, getY = defaultGetY) {
  6037. const n = points.length;
  6038. const coords = new Float64Array(n * 2);
  6039. for (let i = 0; i < n; i++) {
  6040. const p = points[i];
  6041. coords[2 * i] = getX(p);
  6042. coords[2 * i + 1] = getY(p);
  6043. }
  6044. return new Delaunator(coords);
  6045. }
  6046. constructor(coords) {
  6047. const n = coords.length >> 1;
  6048. if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
  6049. this.coords = coords;
  6050. // arrays that will store the triangulation graph
  6051. const maxTriangles = Math.max(2 * n - 5, 0);
  6052. this._triangles = new Uint32Array(maxTriangles * 3);
  6053. this._halfedges = new Int32Array(maxTriangles * 3);
  6054. // temporary arrays for tracking the edges of the advancing convex hull
  6055. this._hashSize = Math.ceil(Math.sqrt(n));
  6056. this._hullPrev = new Uint32Array(n); // edge to prev edge
  6057. this._hullNext = new Uint32Array(n); // edge to next edge
  6058. this._hullTri = new Uint32Array(n); // edge to adjacent triangle
  6059. this._hullHash = new Int32Array(this._hashSize).fill(-1); // angular edge hash
  6060. // temporary arrays for sorting points
  6061. this._ids = new Uint32Array(n);
  6062. this._dists = new Float64Array(n);
  6063. this.update();
  6064. }
  6065. update() {
  6066. const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
  6067. const n = coords.length >> 1;
  6068. // populate an array of point indices; calculate input data bbox
  6069. let minX = Infinity;
  6070. let minY = Infinity;
  6071. let maxX = -Infinity;
  6072. let maxY = -Infinity;
  6073. for (let i = 0; i < n; i++) {
  6074. const x = coords[2 * i];
  6075. const y = coords[2 * i + 1];
  6076. if (x < minX) minX = x;
  6077. if (y < minY) minY = y;
  6078. if (x > maxX) maxX = x;
  6079. if (y > maxY) maxY = y;
  6080. this._ids[i] = i;
  6081. }
  6082. const cx = (minX + maxX) / 2;
  6083. const cy = (minY + maxY) / 2;
  6084. let minDist = Infinity;
  6085. let i0, i1, i2;
  6086. // pick a seed point close to the center
  6087. for (let i = 0; i < n; i++) {
  6088. const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
  6089. if (d < minDist) {
  6090. i0 = i;
  6091. minDist = d;
  6092. }
  6093. }
  6094. const i0x = coords[2 * i0];
  6095. const i0y = coords[2 * i0 + 1];
  6096. minDist = Infinity;
  6097. // find the point closest to the seed
  6098. for (let i = 0; i < n; i++) {
  6099. if (i === i0) continue;
  6100. const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
  6101. if (d < minDist && d > 0) {
  6102. i1 = i;
  6103. minDist = d;
  6104. }
  6105. }
  6106. let i1x = coords[2 * i1];
  6107. let i1y = coords[2 * i1 + 1];
  6108. let minRadius = Infinity;
  6109. // find the third point which forms the smallest circumcircle with the first two
  6110. for (let i = 0; i < n; i++) {
  6111. if (i === i0 || i === i1) continue;
  6112. const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
  6113. if (r < minRadius) {
  6114. i2 = i;
  6115. minRadius = r;
  6116. }
  6117. }
  6118. let i2x = coords[2 * i2];
  6119. let i2y = coords[2 * i2 + 1];
  6120. if (minRadius === Infinity) {
  6121. // order collinear points by dx (or dy if all x are identical)
  6122. // and return the list as a hull
  6123. for (let i = 0; i < n; i++) {
  6124. this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
  6125. }
  6126. quicksort(this._ids, this._dists, 0, n - 1);
  6127. const hull = new Uint32Array(n);
  6128. let j = 0;
  6129. for (let i = 0, d0 = -Infinity; i < n; i++) {
  6130. const id = this._ids[i];
  6131. if (this._dists[id] > d0) {
  6132. hull[j++] = id;
  6133. d0 = this._dists[id];
  6134. }
  6135. }
  6136. this.hull = hull.subarray(0, j);
  6137. this.triangles = new Uint32Array(0);
  6138. this.halfedges = new Uint32Array(0);
  6139. return;
  6140. }
  6141. // swap the order of the seed points for counter-clockwise orientation
  6142. if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
  6143. const i = i1;
  6144. const x = i1x;
  6145. const y = i1y;
  6146. i1 = i2;
  6147. i1x = i2x;
  6148. i1y = i2y;
  6149. i2 = i;
  6150. i2x = x;
  6151. i2y = y;
  6152. }
  6153. const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
  6154. this._cx = center.x;
  6155. this._cy = center.y;
  6156. for (let i = 0; i < n; i++) {
  6157. this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
  6158. }
  6159. // sort the points by distance from the seed triangle circumcenter
  6160. quicksort(this._ids, this._dists, 0, n - 1);
  6161. // set up the seed triangle as the starting hull
  6162. this._hullStart = i0;
  6163. let hullSize = 3;
  6164. hullNext[i0] = hullPrev[i2] = i1;
  6165. hullNext[i1] = hullPrev[i0] = i2;
  6166. hullNext[i2] = hullPrev[i1] = i0;
  6167. hullTri[i0] = 0;
  6168. hullTri[i1] = 1;
  6169. hullTri[i2] = 2;
  6170. hullHash.fill(-1);
  6171. hullHash[this._hashKey(i0x, i0y)] = i0;
  6172. hullHash[this._hashKey(i1x, i1y)] = i1;
  6173. hullHash[this._hashKey(i2x, i2y)] = i2;
  6174. this.trianglesLen = 0;
  6175. this._addTriangle(i0, i1, i2, -1, -1, -1);
  6176. for (let k = 0, xp, yp; k < this._ids.length; k++) {
  6177. const i = this._ids[k];
  6178. const x = coords[2 * i];
  6179. const y = coords[2 * i + 1];
  6180. // skip near-duplicate points
  6181. if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
  6182. xp = x;
  6183. yp = y;
  6184. // skip seed triangle points
  6185. if (i === i0 || i === i1 || i === i2) continue;
  6186. // find a visible edge on the convex hull using edge hash
  6187. let start = 0;
  6188. for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
  6189. start = hullHash[(key + j) % this._hashSize];
  6190. if (start !== -1 && start !== hullNext[start]) break;
  6191. }
  6192. start = hullPrev[start];
  6193. let e = start, q;
  6194. while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
  6195. e = q;
  6196. if (e === start) {
  6197. e = -1;
  6198. break;
  6199. }
  6200. }
  6201. if (e === -1) continue; // likely a near-duplicate point; skip it
  6202. // add the first triangle from the point
  6203. let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
  6204. // recursively flip triangles from the point until they satisfy the Delaunay condition
  6205. hullTri[i] = this._legalize(t + 2);
  6206. hullTri[e] = t; // keep track of boundary triangles on the hull
  6207. hullSize++;
  6208. // walk forward through the hull, adding more triangles and flipping recursively
  6209. let n = hullNext[e];
  6210. while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
  6211. t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
  6212. hullTri[i] = this._legalize(t + 2);
  6213. hullNext[n] = n; // mark as removed
  6214. hullSize--;
  6215. n = q;
  6216. }
  6217. // walk backward from the other side, adding more triangles and flipping
  6218. if (e === start) {
  6219. while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
  6220. t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
  6221. this._legalize(t + 2);
  6222. hullTri[q] = t;
  6223. hullNext[e] = e; // mark as removed
  6224. hullSize--;
  6225. e = q;
  6226. }
  6227. }
  6228. // update the hull indices
  6229. this._hullStart = hullPrev[i] = e;
  6230. hullNext[e] = hullPrev[n] = i;
  6231. hullNext[i] = n;
  6232. // save the two new edges in the hash table
  6233. hullHash[this._hashKey(x, y)] = i;
  6234. hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
  6235. }
  6236. this.hull = new Uint32Array(hullSize);
  6237. for (let i = 0, e = this._hullStart; i < hullSize; i++) {
  6238. this.hull[i] = e;
  6239. e = hullNext[e];
  6240. }
  6241. // trim typed triangle mesh arrays
  6242. this.triangles = this._triangles.subarray(0, this.trianglesLen);
  6243. this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
  6244. }
  6245. _hashKey(x, y) {
  6246. return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
  6247. }
  6248. _legalize(a) {
  6249. const {_triangles: triangles, _halfedges: halfedges, coords} = this;
  6250. let i = 0;
  6251. let ar = 0;
  6252. // recursion eliminated with a fixed-size stack
  6253. while (true) {
  6254. const b = halfedges[a];
  6255. /* if the pair of triangles doesn't satisfy the Delaunay condition
  6256. * (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
  6257. * then do the same check/flip recursively for the new pair of triangles
  6258. *
  6259. * pl pl
  6260. * /||\ / \
  6261. * al/ || \bl al/ \a
  6262. * / || \ / \
  6263. * / a||b \ flip /___ar___\
  6264. * p0\ || /p1 => p0\---bl---/p1
  6265. * \ || / \ /
  6266. * ar\ || /br b\ /br
  6267. * \||/ \ /
  6268. * pr pr
  6269. */
  6270. const a0 = a - a % 3;
  6271. ar = a0 + (a + 2) % 3;
  6272. if (b === -1) { // convex hull edge
  6273. if (i === 0) break;
  6274. a = EDGE_STACK[--i];
  6275. continue;
  6276. }
  6277. const b0 = b - b % 3;
  6278. const al = a0 + (a + 1) % 3;
  6279. const bl = b0 + (b + 2) % 3;
  6280. const p0 = triangles[ar];
  6281. const pr = triangles[a];
  6282. const pl = triangles[al];
  6283. const p1 = triangles[bl];
  6284. const illegal = inCircle(
  6285. coords[2 * p0], coords[2 * p0 + 1],
  6286. coords[2 * pr], coords[2 * pr + 1],
  6287. coords[2 * pl], coords[2 * pl + 1],
  6288. coords[2 * p1], coords[2 * p1 + 1]);
  6289. if (illegal) {
  6290. triangles[a] = p1;
  6291. triangles[b] = p0;
  6292. const hbl = halfedges[bl];
  6293. // edge swapped on the other side of the hull (rare); fix the halfedge reference
  6294. if (hbl === -1) {
  6295. let e = this._hullStart;
  6296. do {
  6297. if (this._hullTri[e] === bl) {
  6298. this._hullTri[e] = a;
  6299. break;
  6300. }
  6301. e = this._hullPrev[e];
  6302. } while (e !== this._hullStart);
  6303. }
  6304. this._link(a, hbl);
  6305. this._link(b, halfedges[ar]);
  6306. this._link(ar, bl);
  6307. const br = b0 + (b + 1) % 3;
  6308. // don't worry about hitting the cap: it can only happen on extremely degenerate input
  6309. if (i < EDGE_STACK.length) {
  6310. EDGE_STACK[i++] = br;
  6311. }
  6312. } else {
  6313. if (i === 0) break;
  6314. a = EDGE_STACK[--i];
  6315. }
  6316. }
  6317. return ar;
  6318. }
  6319. _link(a, b) {
  6320. this._halfedges[a] = b;
  6321. if (b !== -1) this._halfedges[b] = a;
  6322. }
  6323. // add a new triangle given vertex indices and adjacent half-edge ids
  6324. _addTriangle(i0, i1, i2, a, b, c) {
  6325. const t = this.trianglesLen;
  6326. this._triangles[t] = i0;
  6327. this._triangles[t + 1] = i1;
  6328. this._triangles[t + 2] = i2;
  6329. this._link(t, a);
  6330. this._link(t + 1, b);
  6331. this._link(t + 2, c);
  6332. this.trianglesLen += 3;
  6333. return t;
  6334. }
  6335. }
  6336. // monotonically increases with real angle, but doesn't need expensive trigonometry
  6337. function pseudoAngle(dx, dy) {
  6338. const p = dx / (Math.abs(dx) + Math.abs(dy));
  6339. return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
  6340. }
  6341. function dist(ax, ay, bx, by) {
  6342. const dx = ax - bx;
  6343. const dy = ay - by;
  6344. return dx * dx + dy * dy;
  6345. }
  6346. function inCircle(ax, ay, bx, by, cx, cy, px, py) {
  6347. const dx = ax - px;
  6348. const dy = ay - py;
  6349. const ex = bx - px;
  6350. const ey = by - py;
  6351. const fx = cx - px;
  6352. const fy = cy - py;
  6353. const ap = dx * dx + dy * dy;
  6354. const bp = ex * ex + ey * ey;
  6355. const cp = fx * fx + fy * fy;
  6356. return dx * (ey * cp - bp * fy) -
  6357. dy * (ex * cp - bp * fx) +
  6358. ap * (ex * fy - ey * fx) < 0;
  6359. }
  6360. function circumradius(ax, ay, bx, by, cx, cy) {
  6361. const dx = bx - ax;
  6362. const dy = by - ay;
  6363. const ex = cx - ax;
  6364. const ey = cy - ay;
  6365. const bl = dx * dx + dy * dy;
  6366. const cl = ex * ex + ey * ey;
  6367. const d = 0.5 / (dx * ey - dy * ex);
  6368. const x = (ey * bl - dy * cl) * d;
  6369. const y = (dx * cl - ex * bl) * d;
  6370. return x * x + y * y;
  6371. }
  6372. function circumcenter(ax, ay, bx, by, cx, cy) {
  6373. const dx = bx - ax;
  6374. const dy = by - ay;
  6375. const ex = cx - ax;
  6376. const ey = cy - ay;
  6377. const bl = dx * dx + dy * dy;
  6378. const cl = ex * ex + ey * ey;
  6379. const d = 0.5 / (dx * ey - dy * ex);
  6380. const x = ax + (ey * bl - dy * cl) * d;
  6381. const y = ay + (dx * cl - ex * bl) * d;
  6382. return {x, y};
  6383. }
  6384. function quicksort(ids, dists, left, right) {
  6385. if (right - left <= 20) {
  6386. for (let i = left + 1; i <= right; i++) {
  6387. const temp = ids[i];
  6388. const tempDist = dists[temp];
  6389. let j = i - 1;
  6390. while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
  6391. ids[j + 1] = temp;
  6392. }
  6393. } else {
  6394. const median = (left + right) >> 1;
  6395. let i = left + 1;
  6396. let j = right;
  6397. swap(ids, median, i);
  6398. if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
  6399. if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
  6400. if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
  6401. const temp = ids[i];
  6402. const tempDist = dists[temp];
  6403. while (true) {
  6404. do i++; while (dists[ids[i]] < tempDist);
  6405. do j--; while (dists[ids[j]] > tempDist);
  6406. if (j < i) break;
  6407. swap(ids, i, j);
  6408. }
  6409. ids[left + 1] = ids[j];
  6410. ids[j] = temp;
  6411. if (right - i + 1 >= j - left) {
  6412. quicksort(ids, dists, i, right);
  6413. quicksort(ids, dists, left, j - 1);
  6414. } else {
  6415. quicksort(ids, dists, left, j - 1);
  6416. quicksort(ids, dists, i, right);
  6417. }
  6418. }
  6419. }
  6420. function swap(arr, i, j) {
  6421. const tmp = arr[i];
  6422. arr[i] = arr[j];
  6423. arr[j] = tmp;
  6424. }
  6425. function defaultGetX(p) {
  6426. return p[0];
  6427. }
  6428. function defaultGetY(p) {
  6429. return p[1];
  6430. }
  6431. const epsilon$2 = 1e-6;
  6432. class Path {
  6433. constructor() {
  6434. this._x0 = this._y0 = // start of current subpath
  6435. this._x1 = this._y1 = null; // end of current subpath
  6436. this._ = "";
  6437. }
  6438. moveTo(x, y) {
  6439. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  6440. }
  6441. closePath() {
  6442. if (this._x1 !== null) {
  6443. this._x1 = this._x0, this._y1 = this._y0;
  6444. this._ += "Z";
  6445. }
  6446. }
  6447. lineTo(x, y) {
  6448. this._ += `L${this._x1 = +x},${this._y1 = +y}`;
  6449. }
  6450. arc(x, y, r) {
  6451. x = +x, y = +y, r = +r;
  6452. const x0 = x + r;
  6453. const y0 = y;
  6454. if (r < 0) throw new Error("negative radius");
  6455. if (this._x1 === null) this._ += `M${x0},${y0}`;
  6456. else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
  6457. if (!r) return;
  6458. this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
  6459. }
  6460. rect(x, y, w, h) {
  6461. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
  6462. }
  6463. value() {
  6464. return this._ || null;
  6465. }
  6466. }
  6467. class Polygon {
  6468. constructor() {
  6469. this._ = [];
  6470. }
  6471. moveTo(x, y) {
  6472. this._.push([x, y]);
  6473. }
  6474. closePath() {
  6475. this._.push(this._[0].slice());
  6476. }
  6477. lineTo(x, y) {
  6478. this._.push([x, y]);
  6479. }
  6480. value() {
  6481. return this._.length ? this._ : null;
  6482. }
  6483. }
  6484. class Voronoi {
  6485. constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
  6486. if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
  6487. this.delaunay = delaunay;
  6488. this._circumcenters = new Float64Array(delaunay.points.length * 2);
  6489. this.vectors = new Float64Array(delaunay.points.length * 2);
  6490. this.xmax = xmax, this.xmin = xmin;
  6491. this.ymax = ymax, this.ymin = ymin;
  6492. this._init();
  6493. }
  6494. update() {
  6495. this.delaunay.update();
  6496. this._init();
  6497. return this;
  6498. }
  6499. _init() {
  6500. const {delaunay: {points, hull, triangles}, vectors} = this;
  6501. // Compute circumcenters.
  6502. const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
  6503. for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
  6504. const t1 = triangles[i] * 2;
  6505. const t2 = triangles[i + 1] * 2;
  6506. const t3 = triangles[i + 2] * 2;
  6507. const x1 = points[t1];
  6508. const y1 = points[t1 + 1];
  6509. const x2 = points[t2];
  6510. const y2 = points[t2 + 1];
  6511. const x3 = points[t3];
  6512. const y3 = points[t3 + 1];
  6513. const dx = x2 - x1;
  6514. const dy = y2 - y1;
  6515. const ex = x3 - x1;
  6516. const ey = y3 - y1;
  6517. const ab = (dx * ey - dy * ex) * 2;
  6518. if (Math.abs(ab) < 1e-9) {
  6519. // degenerate case (collinear diagram)
  6520. // almost equal points (degenerate triangle)
  6521. // the circumcenter is at the infinity, in a
  6522. // direction that is:
  6523. // 1. orthogonal to the halfedge.
  6524. let a = 1e9;
  6525. // 2. points away from the center; since the list of triangles starts
  6526. // in the center, the first point of the first triangle
  6527. // will be our reference
  6528. const r = triangles[0] * 2;
  6529. a *= Math.sign((points[r] - x1) * ey - (points[r + 1] - y1) * ex);
  6530. x = (x1 + x3) / 2 - a * ey;
  6531. y = (y1 + y3) / 2 + a * ex;
  6532. } else {
  6533. const d = 1 / ab;
  6534. const bl = dx * dx + dy * dy;
  6535. const cl = ex * ex + ey * ey;
  6536. x = x1 + (ey * bl - dy * cl) * d;
  6537. y = y1 + (dx * cl - ex * bl) * d;
  6538. }
  6539. circumcenters[j] = x;
  6540. circumcenters[j + 1] = y;
  6541. }
  6542. // Compute exterior cell rays.
  6543. let h = hull[hull.length - 1];
  6544. let p0, p1 = h * 4;
  6545. let x0, x1 = points[2 * h];
  6546. let y0, y1 = points[2 * h + 1];
  6547. vectors.fill(0);
  6548. for (let i = 0; i < hull.length; ++i) {
  6549. h = hull[i];
  6550. p0 = p1, x0 = x1, y0 = y1;
  6551. p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
  6552. vectors[p0 + 2] = vectors[p1] = y0 - y1;
  6553. vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
  6554. }
  6555. }
  6556. render(context) {
  6557. const buffer = context == null ? context = new Path : undefined;
  6558. const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
  6559. if (hull.length <= 1) return null;
  6560. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6561. const j = halfedges[i];
  6562. if (j < i) continue;
  6563. const ti = Math.floor(i / 3) * 2;
  6564. const tj = Math.floor(j / 3) * 2;
  6565. const xi = circumcenters[ti];
  6566. const yi = circumcenters[ti + 1];
  6567. const xj = circumcenters[tj];
  6568. const yj = circumcenters[tj + 1];
  6569. this._renderSegment(xi, yi, xj, yj, context);
  6570. }
  6571. let h0, h1 = hull[hull.length - 1];
  6572. for (let i = 0; i < hull.length; ++i) {
  6573. h0 = h1, h1 = hull[i];
  6574. const t = Math.floor(inedges[h1] / 3) * 2;
  6575. const x = circumcenters[t];
  6576. const y = circumcenters[t + 1];
  6577. const v = h0 * 4;
  6578. const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
  6579. if (p) this._renderSegment(x, y, p[0], p[1], context);
  6580. }
  6581. return buffer && buffer.value();
  6582. }
  6583. renderBounds(context) {
  6584. const buffer = context == null ? context = new Path : undefined;
  6585. context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
  6586. return buffer && buffer.value();
  6587. }
  6588. renderCell(i, context) {
  6589. const buffer = context == null ? context = new Path : undefined;
  6590. const points = this._clip(i);
  6591. if (points === null || !points.length) return;
  6592. context.moveTo(points[0], points[1]);
  6593. let n = points.length;
  6594. while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
  6595. for (let i = 2; i < n; i += 2) {
  6596. if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
  6597. context.lineTo(points[i], points[i + 1]);
  6598. }
  6599. context.closePath();
  6600. return buffer && buffer.value();
  6601. }
  6602. *cellPolygons() {
  6603. const {delaunay: {points}} = this;
  6604. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6605. const cell = this.cellPolygon(i);
  6606. if (cell) cell.index = i, yield cell;
  6607. }
  6608. }
  6609. cellPolygon(i) {
  6610. const polygon = new Polygon;
  6611. this.renderCell(i, polygon);
  6612. return polygon.value();
  6613. }
  6614. _renderSegment(x0, y0, x1, y1, context) {
  6615. let S;
  6616. const c0 = this._regioncode(x0, y0);
  6617. const c1 = this._regioncode(x1, y1);
  6618. if (c0 === 0 && c1 === 0) {
  6619. context.moveTo(x0, y0);
  6620. context.lineTo(x1, y1);
  6621. } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
  6622. context.moveTo(S[0], S[1]);
  6623. context.lineTo(S[2], S[3]);
  6624. }
  6625. }
  6626. contains(i, x, y) {
  6627. if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
  6628. return this.delaunay._step(i, x, y) === i;
  6629. }
  6630. *neighbors(i) {
  6631. const ci = this._clip(i);
  6632. if (ci) for (const j of this.delaunay.neighbors(i)) {
  6633. const cj = this._clip(j);
  6634. // find the common edge
  6635. if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
  6636. for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
  6637. if (ci[ai] == cj[aj]
  6638. && ci[ai + 1] == cj[aj + 1]
  6639. && ci[(ai + 2) % li] == cj[(aj + lj - 2) % lj]
  6640. && ci[(ai + 3) % li] == cj[(aj + lj - 1) % lj]
  6641. ) {
  6642. yield j;
  6643. break loop;
  6644. }
  6645. }
  6646. }
  6647. }
  6648. }
  6649. _cell(i) {
  6650. const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
  6651. const e0 = inedges[i];
  6652. if (e0 === -1) return null; // coincident point
  6653. const points = [];
  6654. let e = e0;
  6655. do {
  6656. const t = Math.floor(e / 3);
  6657. points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
  6658. e = e % 3 === 2 ? e - 2 : e + 1;
  6659. if (triangles[e] !== i) break; // bad triangulation
  6660. e = halfedges[e];
  6661. } while (e !== e0 && e !== -1);
  6662. return points;
  6663. }
  6664. _clip(i) {
  6665. // degenerate case (1 valid point: return the box)
  6666. if (i === 0 && this.delaunay.hull.length === 1) {
  6667. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6668. }
  6669. const points = this._cell(i);
  6670. if (points === null) return null;
  6671. const {vectors: V} = this;
  6672. const v = i * 4;
  6673. return V[v] || V[v + 1]
  6674. ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
  6675. : this._clipFinite(i, points);
  6676. }
  6677. _clipFinite(i, points) {
  6678. const n = points.length;
  6679. let P = null;
  6680. let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
  6681. let c0, c1 = this._regioncode(x1, y1);
  6682. let e0, e1 = 0;
  6683. for (let j = 0; j < n; j += 2) {
  6684. x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
  6685. c0 = c1, c1 = this._regioncode(x1, y1);
  6686. if (c0 === 0 && c1 === 0) {
  6687. e0 = e1, e1 = 0;
  6688. if (P) P.push(x1, y1);
  6689. else P = [x1, y1];
  6690. } else {
  6691. let S, sx0, sy0, sx1, sy1;
  6692. if (c0 === 0) {
  6693. if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
  6694. [sx0, sy0, sx1, sy1] = S;
  6695. } else {
  6696. if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
  6697. [sx1, sy1, sx0, sy0] = S;
  6698. e0 = e1, e1 = this._edgecode(sx0, sy0);
  6699. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6700. if (P) P.push(sx0, sy0);
  6701. else P = [sx0, sy0];
  6702. }
  6703. e0 = e1, e1 = this._edgecode(sx1, sy1);
  6704. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6705. if (P) P.push(sx1, sy1);
  6706. else P = [sx1, sy1];
  6707. }
  6708. }
  6709. if (P) {
  6710. e0 = e1, e1 = this._edgecode(P[0], P[1]);
  6711. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6712. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6713. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6714. }
  6715. return P;
  6716. }
  6717. _clipSegment(x0, y0, x1, y1, c0, c1) {
  6718. while (true) {
  6719. if (c0 === 0 && c1 === 0) return [x0, y0, x1, y1];
  6720. if (c0 & c1) return null;
  6721. let x, y, c = c0 || c1;
  6722. if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
  6723. else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
  6724. else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
  6725. else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
  6726. if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
  6727. else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
  6728. }
  6729. }
  6730. _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
  6731. let P = Array.from(points), p;
  6732. if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
  6733. if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
  6734. if (P = this._clipFinite(i, P)) {
  6735. for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
  6736. c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
  6737. if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
  6738. }
  6739. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6740. P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
  6741. }
  6742. return P;
  6743. }
  6744. _edge(i, e0, e1, P, j) {
  6745. while (e0 !== e1) {
  6746. let x, y;
  6747. switch (e0) {
  6748. case 0b0101: e0 = 0b0100; continue; // top-left
  6749. case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
  6750. case 0b0110: e0 = 0b0010; continue; // top-right
  6751. case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
  6752. case 0b1010: e0 = 0b1000; continue; // bottom-right
  6753. case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
  6754. case 0b1001: e0 = 0b0001; continue; // bottom-left
  6755. case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
  6756. }
  6757. // Note: this implicitly checks for out of bounds: if P[j] or P[j+1] are
  6758. // undefined, the conditional statement will be executed.
  6759. if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
  6760. P.splice(j, 0, x, y), j += 2;
  6761. }
  6762. }
  6763. if (P.length > 4) {
  6764. for (let i = 0; i < P.length; i+= 2) {
  6765. const j = (i + 2) % P.length, k = (i + 4) % P.length;
  6766. if (P[i] === P[j] && P[j] === P[k]
  6767. || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1])
  6768. P.splice(j, 2), i -= 2;
  6769. }
  6770. }
  6771. return j;
  6772. }
  6773. _project(x0, y0, vx, vy) {
  6774. let t = Infinity, c, x, y;
  6775. if (vy < 0) { // top
  6776. if (y0 <= this.ymin) return null;
  6777. if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
  6778. } else if (vy > 0) { // bottom
  6779. if (y0 >= this.ymax) return null;
  6780. if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
  6781. }
  6782. if (vx > 0) { // right
  6783. if (x0 >= this.xmax) return null;
  6784. if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
  6785. } else if (vx < 0) { // left
  6786. if (x0 <= this.xmin) return null;
  6787. if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
  6788. }
  6789. return [x, y];
  6790. }
  6791. _edgecode(x, y) {
  6792. return (x === this.xmin ? 0b0001
  6793. : x === this.xmax ? 0b0010 : 0b0000)
  6794. | (y === this.ymin ? 0b0100
  6795. : y === this.ymax ? 0b1000 : 0b0000);
  6796. }
  6797. _regioncode(x, y) {
  6798. return (x < this.xmin ? 0b0001
  6799. : x > this.xmax ? 0b0010 : 0b0000)
  6800. | (y < this.ymin ? 0b0100
  6801. : y > this.ymax ? 0b1000 : 0b0000);
  6802. }
  6803. }
  6804. const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
  6805. function pointX(p) {
  6806. return p[0];
  6807. }
  6808. function pointY(p) {
  6809. return p[1];
  6810. }
  6811. // A triangulation is collinear if all its triangles have a non-null area
  6812. function collinear(d) {
  6813. const {triangles, coords} = d;
  6814. for (let i = 0; i < triangles.length; i += 3) {
  6815. const a = 2 * triangles[i],
  6816. b = 2 * triangles[i + 1],
  6817. c = 2 * triangles[i + 2],
  6818. cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
  6819. - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
  6820. if (cross > 1e-10) return false;
  6821. }
  6822. return true;
  6823. }
  6824. function jitter(x, y, r) {
  6825. return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
  6826. }
  6827. class Delaunay {
  6828. static from(points, fx = pointX, fy = pointY, that) {
  6829. return new Delaunay("length" in points
  6830. ? flatArray(points, fx, fy, that)
  6831. : Float64Array.from(flatIterable(points, fx, fy, that)));
  6832. }
  6833. constructor(points) {
  6834. this._delaunator = new Delaunator(points);
  6835. this.inedges = new Int32Array(points.length / 2);
  6836. this._hullIndex = new Int32Array(points.length / 2);
  6837. this.points = this._delaunator.coords;
  6838. this._init();
  6839. }
  6840. update() {
  6841. this._delaunator.update();
  6842. this._init();
  6843. return this;
  6844. }
  6845. _init() {
  6846. const d = this._delaunator, points = this.points;
  6847. // check for collinear
  6848. if (d.hull && d.hull.length > 2 && collinear(d)) {
  6849. this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
  6850. .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
  6851. const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
  6852. bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
  6853. r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
  6854. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6855. const p = jitter(points[2 * i], points[2 * i + 1], r);
  6856. points[2 * i] = p[0];
  6857. points[2 * i + 1] = p[1];
  6858. }
  6859. this._delaunator = new Delaunator(points);
  6860. } else {
  6861. delete this.collinear;
  6862. }
  6863. const halfedges = this.halfedges = this._delaunator.halfedges;
  6864. const hull = this.hull = this._delaunator.hull;
  6865. const triangles = this.triangles = this._delaunator.triangles;
  6866. const inedges = this.inedges.fill(-1);
  6867. const hullIndex = this._hullIndex.fill(-1);
  6868. // Compute an index from each point to an (arbitrary) incoming halfedge
  6869. // Used to give the first neighbor of each point; for this reason,
  6870. // on the hull we give priority to exterior halfedges
  6871. for (let e = 0, n = halfedges.length; e < n; ++e) {
  6872. const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
  6873. if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
  6874. }
  6875. for (let i = 0, n = hull.length; i < n; ++i) {
  6876. hullIndex[hull[i]] = i;
  6877. }
  6878. // degenerate case: 1 or 2 (distinct) points
  6879. if (hull.length <= 2 && hull.length > 0) {
  6880. this.triangles = new Int32Array(3).fill(-1);
  6881. this.halfedges = new Int32Array(3).fill(-1);
  6882. this.triangles[0] = hull[0];
  6883. inedges[hull[0]] = 1;
  6884. if (hull.length === 2) {
  6885. inedges[hull[1]] = 0;
  6886. this.triangles[1] = hull[1];
  6887. this.triangles[2] = hull[1];
  6888. }
  6889. }
  6890. }
  6891. voronoi(bounds) {
  6892. return new Voronoi(this, bounds);
  6893. }
  6894. *neighbors(i) {
  6895. const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
  6896. // degenerate case with several collinear points
  6897. if (collinear) {
  6898. const l = collinear.indexOf(i);
  6899. if (l > 0) yield collinear[l - 1];
  6900. if (l < collinear.length - 1) yield collinear[l + 1];
  6901. return;
  6902. }
  6903. const e0 = inedges[i];
  6904. if (e0 === -1) return; // coincident point
  6905. let e = e0, p0 = -1;
  6906. do {
  6907. yield p0 = triangles[e];
  6908. e = e % 3 === 2 ? e - 2 : e + 1;
  6909. if (triangles[e] !== i) return; // bad triangulation
  6910. e = halfedges[e];
  6911. if (e === -1) {
  6912. const p = hull[(_hullIndex[i] + 1) % hull.length];
  6913. if (p !== p0) yield p;
  6914. return;
  6915. }
  6916. } while (e !== e0);
  6917. }
  6918. find(x, y, i = 0) {
  6919. if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
  6920. const i0 = i;
  6921. let c;
  6922. while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
  6923. return c;
  6924. }
  6925. _step(i, x, y) {
  6926. const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
  6927. if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
  6928. let c = i;
  6929. let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
  6930. const e0 = inedges[i];
  6931. let e = e0;
  6932. do {
  6933. let t = triangles[e];
  6934. const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
  6935. if (dt < dc) dc = dt, c = t;
  6936. e = e % 3 === 2 ? e - 2 : e + 1;
  6937. if (triangles[e] !== i) break; // bad triangulation
  6938. e = halfedges[e];
  6939. if (e === -1) {
  6940. e = hull[(_hullIndex[i] + 1) % hull.length];
  6941. if (e !== t) {
  6942. if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
  6943. }
  6944. break;
  6945. }
  6946. } while (e !== e0);
  6947. return c;
  6948. }
  6949. render(context) {
  6950. const buffer = context == null ? context = new Path : undefined;
  6951. const {points, halfedges, triangles} = this;
  6952. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6953. const j = halfedges[i];
  6954. if (j < i) continue;
  6955. const ti = triangles[i] * 2;
  6956. const tj = triangles[j] * 2;
  6957. context.moveTo(points[ti], points[ti + 1]);
  6958. context.lineTo(points[tj], points[tj + 1]);
  6959. }
  6960. this.renderHull(context);
  6961. return buffer && buffer.value();
  6962. }
  6963. renderPoints(context, r) {
  6964. if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null;
  6965. r = r == undefined ? 2 : +r;
  6966. const buffer = context == null ? context = new Path : undefined;
  6967. const {points} = this;
  6968. for (let i = 0, n = points.length; i < n; i += 2) {
  6969. const x = points[i], y = points[i + 1];
  6970. context.moveTo(x + r, y);
  6971. context.arc(x, y, r, 0, tau$2);
  6972. }
  6973. return buffer && buffer.value();
  6974. }
  6975. renderHull(context) {
  6976. const buffer = context == null ? context = new Path : undefined;
  6977. const {hull, points} = this;
  6978. const h = hull[0] * 2, n = hull.length;
  6979. context.moveTo(points[h], points[h + 1]);
  6980. for (let i = 1; i < n; ++i) {
  6981. const h = 2 * hull[i];
  6982. context.lineTo(points[h], points[h + 1]);
  6983. }
  6984. context.closePath();
  6985. return buffer && buffer.value();
  6986. }
  6987. hullPolygon() {
  6988. const polygon = new Polygon;
  6989. this.renderHull(polygon);
  6990. return polygon.value();
  6991. }
  6992. renderTriangle(i, context) {
  6993. const buffer = context == null ? context = new Path : undefined;
  6994. const {points, triangles} = this;
  6995. const t0 = triangles[i *= 3] * 2;
  6996. const t1 = triangles[i + 1] * 2;
  6997. const t2 = triangles[i + 2] * 2;
  6998. context.moveTo(points[t0], points[t0 + 1]);
  6999. context.lineTo(points[t1], points[t1 + 1]);
  7000. context.lineTo(points[t2], points[t2 + 1]);
  7001. context.closePath();
  7002. return buffer && buffer.value();
  7003. }
  7004. *trianglePolygons() {
  7005. const {triangles} = this;
  7006. for (let i = 0, n = triangles.length / 3; i < n; ++i) {
  7007. yield this.trianglePolygon(i);
  7008. }
  7009. }
  7010. trianglePolygon(i) {
  7011. const polygon = new Polygon;
  7012. this.renderTriangle(i, polygon);
  7013. return polygon.value();
  7014. }
  7015. }
  7016. function flatArray(points, fx, fy, that) {
  7017. const n = points.length;
  7018. const array = new Float64Array(n * 2);
  7019. for (let i = 0; i < n; ++i) {
  7020. const p = points[i];
  7021. array[i * 2] = fx.call(that, p, i, points);
  7022. array[i * 2 + 1] = fy.call(that, p, i, points);
  7023. }
  7024. return array;
  7025. }
  7026. function* flatIterable(points, fx, fy, that) {
  7027. let i = 0;
  7028. for (const p of points) {
  7029. yield fx.call(that, p, i, points);
  7030. yield fy.call(that, p, i, points);
  7031. ++i;
  7032. }
  7033. }
  7034. var EOL = {},
  7035. EOF = {},
  7036. QUOTE = 34,
  7037. NEWLINE = 10,
  7038. RETURN = 13;
  7039. function objectConverter(columns) {
  7040. return new Function("d", "return {" + columns.map(function(name, i) {
  7041. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  7042. }).join(",") + "}");
  7043. }
  7044. function customConverter(columns, f) {
  7045. var object = objectConverter(columns);
  7046. return function(row, i) {
  7047. return f(object(row), i, columns);
  7048. };
  7049. }
  7050. // Compute unique columns in order of discovery.
  7051. function inferColumns(rows) {
  7052. var columnSet = Object.create(null),
  7053. columns = [];
  7054. rows.forEach(function(row) {
  7055. for (var column in row) {
  7056. if (!(column in columnSet)) {
  7057. columns.push(columnSet[column] = column);
  7058. }
  7059. }
  7060. });
  7061. return columns;
  7062. }
  7063. function pad$1(value, width) {
  7064. var s = value + "", length = s.length;
  7065. return length < width ? new Array(width - length + 1).join(0) + s : s;
  7066. }
  7067. function formatYear$1(year) {
  7068. return year < 0 ? "-" + pad$1(-year, 6)
  7069. : year > 9999 ? "+" + pad$1(year, 6)
  7070. : pad$1(year, 4);
  7071. }
  7072. function formatDate(date) {
  7073. var hours = date.getUTCHours(),
  7074. minutes = date.getUTCMinutes(),
  7075. seconds = date.getUTCSeconds(),
  7076. milliseconds = date.getUTCMilliseconds();
  7077. return isNaN(date) ? "Invalid Date"
  7078. : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
  7079. + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
  7080. : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
  7081. : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
  7082. : "");
  7083. }
  7084. function dsvFormat(delimiter) {
  7085. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  7086. DELIMITER = delimiter.charCodeAt(0);
  7087. function parse(text, f) {
  7088. var convert, columns, rows = parseRows(text, function(row, i) {
  7089. if (convert) return convert(row, i - 1);
  7090. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  7091. });
  7092. rows.columns = columns || [];
  7093. return rows;
  7094. }
  7095. function parseRows(text, f) {
  7096. var rows = [], // output rows
  7097. N = text.length,
  7098. I = 0, // current character index
  7099. n = 0, // current line number
  7100. t, // current token
  7101. eof = N <= 0, // current token followed by EOF?
  7102. eol = false; // current token followed by EOL?
  7103. // Strip the trailing newline.
  7104. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  7105. if (text.charCodeAt(N - 1) === RETURN) --N;
  7106. function token() {
  7107. if (eof) return EOF;
  7108. if (eol) return eol = false, EOL;
  7109. // Unescape quotes.
  7110. var i, j = I, c;
  7111. if (text.charCodeAt(j) === QUOTE) {
  7112. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  7113. if ((i = I) >= N) eof = true;
  7114. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  7115. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7116. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  7117. }
  7118. // Find next delimiter or newline.
  7119. while (I < N) {
  7120. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  7121. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7122. else if (c !== DELIMITER) continue;
  7123. return text.slice(j, i);
  7124. }
  7125. // Return last token before EOF.
  7126. return eof = true, text.slice(j, N);
  7127. }
  7128. while ((t = token()) !== EOF) {
  7129. var row = [];
  7130. while (t !== EOL && t !== EOF) row.push(t), t = token();
  7131. if (f && (row = f(row, n++)) == null) continue;
  7132. rows.push(row);
  7133. }
  7134. return rows;
  7135. }
  7136. function preformatBody(rows, columns) {
  7137. return rows.map(function(row) {
  7138. return columns.map(function(column) {
  7139. return formatValue(row[column]);
  7140. }).join(delimiter);
  7141. });
  7142. }
  7143. function format(rows, columns) {
  7144. if (columns == null) columns = inferColumns(rows);
  7145. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  7146. }
  7147. function formatBody(rows, columns) {
  7148. if (columns == null) columns = inferColumns(rows);
  7149. return preformatBody(rows, columns).join("\n");
  7150. }
  7151. function formatRows(rows) {
  7152. return rows.map(formatRow).join("\n");
  7153. }
  7154. function formatRow(row) {
  7155. return row.map(formatValue).join(delimiter);
  7156. }
  7157. function formatValue(value) {
  7158. return value == null ? ""
  7159. : value instanceof Date ? formatDate(value)
  7160. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  7161. : value;
  7162. }
  7163. return {
  7164. parse: parse,
  7165. parseRows: parseRows,
  7166. format: format,
  7167. formatBody: formatBody,
  7168. formatRows: formatRows,
  7169. formatRow: formatRow,
  7170. formatValue: formatValue
  7171. };
  7172. }
  7173. var csv$1 = dsvFormat(",");
  7174. var csvParse = csv$1.parse;
  7175. var csvParseRows = csv$1.parseRows;
  7176. var csvFormat = csv$1.format;
  7177. var csvFormatBody = csv$1.formatBody;
  7178. var csvFormatRows = csv$1.formatRows;
  7179. var csvFormatRow = csv$1.formatRow;
  7180. var csvFormatValue = csv$1.formatValue;
  7181. var tsv$1 = dsvFormat("\t");
  7182. var tsvParse = tsv$1.parse;
  7183. var tsvParseRows = tsv$1.parseRows;
  7184. var tsvFormat = tsv$1.format;
  7185. var tsvFormatBody = tsv$1.formatBody;
  7186. var tsvFormatRows = tsv$1.formatRows;
  7187. var tsvFormatRow = tsv$1.formatRow;
  7188. var tsvFormatValue = tsv$1.formatValue;
  7189. function autoType(object) {
  7190. for (var key in object) {
  7191. var value = object[key].trim(), number, m;
  7192. if (!value) value = null;
  7193. else if (value === "true") value = true;
  7194. else if (value === "false") value = false;
  7195. else if (value === "NaN") value = NaN;
  7196. else if (!isNaN(number = +value)) value = number;
  7197. else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
  7198. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  7199. value = new Date(value);
  7200. }
  7201. else continue;
  7202. object[key] = value;
  7203. }
  7204. return object;
  7205. }
  7206. // https://github.com/d3/d3-dsv/issues/45
  7207. const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  7208. function responseBlob(response) {
  7209. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7210. return response.blob();
  7211. }
  7212. function blob(input, init) {
  7213. return fetch(input, init).then(responseBlob);
  7214. }
  7215. function responseArrayBuffer(response) {
  7216. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7217. return response.arrayBuffer();
  7218. }
  7219. function buffer(input, init) {
  7220. return fetch(input, init).then(responseArrayBuffer);
  7221. }
  7222. function responseText(response) {
  7223. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7224. return response.text();
  7225. }
  7226. function text(input, init) {
  7227. return fetch(input, init).then(responseText);
  7228. }
  7229. function dsvParse(parse) {
  7230. return function(input, init, row) {
  7231. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  7232. return text(input, init).then(function(response) {
  7233. return parse(response, row);
  7234. });
  7235. };
  7236. }
  7237. function dsv(delimiter, input, init, row) {
  7238. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  7239. var format = dsvFormat(delimiter);
  7240. return text(input, init).then(function(response) {
  7241. return format.parse(response, row);
  7242. });
  7243. }
  7244. var csv = dsvParse(csvParse);
  7245. var tsv = dsvParse(tsvParse);
  7246. function image(input, init) {
  7247. return new Promise(function(resolve, reject) {
  7248. var image = new Image;
  7249. for (var key in init) image[key] = init[key];
  7250. image.onerror = reject;
  7251. image.onload = function() { resolve(image); };
  7252. image.src = input;
  7253. });
  7254. }
  7255. function responseJson(response) {
  7256. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7257. if (response.status === 204 || response.status === 205) return;
  7258. return response.json();
  7259. }
  7260. function json(input, init) {
  7261. return fetch(input, init).then(responseJson);
  7262. }
  7263. function parser(type) {
  7264. return (input, init) => text(input, init)
  7265. .then(text => (new DOMParser).parseFromString(text, type));
  7266. }
  7267. var xml = parser("application/xml");
  7268. var html = parser("text/html");
  7269. var svg = parser("image/svg+xml");
  7270. function center(x, y) {
  7271. var nodes, strength = 1;
  7272. if (x == null) x = 0;
  7273. if (y == null) y = 0;
  7274. function force() {
  7275. var i,
  7276. n = nodes.length,
  7277. node,
  7278. sx = 0,
  7279. sy = 0;
  7280. for (i = 0; i < n; ++i) {
  7281. node = nodes[i], sx += node.x, sy += node.y;
  7282. }
  7283. for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
  7284. node = nodes[i], node.x -= sx, node.y -= sy;
  7285. }
  7286. }
  7287. force.initialize = function(_) {
  7288. nodes = _;
  7289. };
  7290. force.x = function(_) {
  7291. return arguments.length ? (x = +_, force) : x;
  7292. };
  7293. force.y = function(_) {
  7294. return arguments.length ? (y = +_, force) : y;
  7295. };
  7296. force.strength = function(_) {
  7297. return arguments.length ? (strength = +_, force) : strength;
  7298. };
  7299. return force;
  7300. }
  7301. function tree_add(d) {
  7302. const x = +this._x.call(null, d),
  7303. y = +this._y.call(null, d);
  7304. return add(this.cover(x, y), x, y, d);
  7305. }
  7306. function add(tree, x, y, d) {
  7307. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  7308. var parent,
  7309. node = tree._root,
  7310. leaf = {data: d},
  7311. x0 = tree._x0,
  7312. y0 = tree._y0,
  7313. x1 = tree._x1,
  7314. y1 = tree._y1,
  7315. xm,
  7316. ym,
  7317. xp,
  7318. yp,
  7319. right,
  7320. bottom,
  7321. i,
  7322. j;
  7323. // If the tree is empty, initialize the root as a leaf.
  7324. if (!node) return tree._root = leaf, tree;
  7325. // Find the existing leaf for the new point, or add it.
  7326. while (node.length) {
  7327. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7328. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7329. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  7330. }
  7331. // Is the new point is exactly coincident with the existing point?
  7332. xp = +tree._x.call(null, node.data);
  7333. yp = +tree._y.call(null, node.data);
  7334. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  7335. // Otherwise, split the leaf node until the old and new point are separated.
  7336. do {
  7337. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  7338. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7339. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7340. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  7341. return parent[j] = node, parent[i] = leaf, tree;
  7342. }
  7343. function addAll(data) {
  7344. var d, i, n = data.length,
  7345. x,
  7346. y,
  7347. xz = new Array(n),
  7348. yz = new Array(n),
  7349. x0 = Infinity,
  7350. y0 = Infinity,
  7351. x1 = -Infinity,
  7352. y1 = -Infinity;
  7353. // Compute the points and their extent.
  7354. for (i = 0; i < n; ++i) {
  7355. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  7356. xz[i] = x;
  7357. yz[i] = y;
  7358. if (x < x0) x0 = x;
  7359. if (x > x1) x1 = x;
  7360. if (y < y0) y0 = y;
  7361. if (y > y1) y1 = y;
  7362. }
  7363. // If there were no (valid) points, abort.
  7364. if (x0 > x1 || y0 > y1) return this;
  7365. // Expand the tree to cover the new points.
  7366. this.cover(x0, y0).cover(x1, y1);
  7367. // Add the new points.
  7368. for (i = 0; i < n; ++i) {
  7369. add(this, xz[i], yz[i], data[i]);
  7370. }
  7371. return this;
  7372. }
  7373. function tree_cover(x, y) {
  7374. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  7375. var x0 = this._x0,
  7376. y0 = this._y0,
  7377. x1 = this._x1,
  7378. y1 = this._y1;
  7379. // If the quadtree has no extent, initialize them.
  7380. // Integer extent are necessary so that if we later double the extent,
  7381. // the existing quadrant boundaries don’t change due to floating point error!
  7382. if (isNaN(x0)) {
  7383. x1 = (x0 = Math.floor(x)) + 1;
  7384. y1 = (y0 = Math.floor(y)) + 1;
  7385. }
  7386. // Otherwise, double repeatedly to cover.
  7387. else {
  7388. var z = x1 - x0 || 1,
  7389. node = this._root,
  7390. parent,
  7391. i;
  7392. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  7393. i = (y < y0) << 1 | (x < x0);
  7394. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  7395. switch (i) {
  7396. case 0: x1 = x0 + z, y1 = y0 + z; break;
  7397. case 1: x0 = x1 - z, y1 = y0 + z; break;
  7398. case 2: x1 = x0 + z, y0 = y1 - z; break;
  7399. case 3: x0 = x1 - z, y0 = y1 - z; break;
  7400. }
  7401. }
  7402. if (this._root && this._root.length) this._root = node;
  7403. }
  7404. this._x0 = x0;
  7405. this._y0 = y0;
  7406. this._x1 = x1;
  7407. this._y1 = y1;
  7408. return this;
  7409. }
  7410. function tree_data() {
  7411. var data = [];
  7412. this.visit(function(node) {
  7413. if (!node.length) do data.push(node.data); while (node = node.next)
  7414. });
  7415. return data;
  7416. }
  7417. function tree_extent(_) {
  7418. return arguments.length
  7419. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  7420. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  7421. }
  7422. function Quad(node, x0, y0, x1, y1) {
  7423. this.node = node;
  7424. this.x0 = x0;
  7425. this.y0 = y0;
  7426. this.x1 = x1;
  7427. this.y1 = y1;
  7428. }
  7429. function tree_find(x, y, radius) {
  7430. var data,
  7431. x0 = this._x0,
  7432. y0 = this._y0,
  7433. x1,
  7434. y1,
  7435. x2,
  7436. y2,
  7437. x3 = this._x1,
  7438. y3 = this._y1,
  7439. quads = [],
  7440. node = this._root,
  7441. q,
  7442. i;
  7443. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  7444. if (radius == null) radius = Infinity;
  7445. else {
  7446. x0 = x - radius, y0 = y - radius;
  7447. x3 = x + radius, y3 = y + radius;
  7448. radius *= radius;
  7449. }
  7450. while (q = quads.pop()) {
  7451. // Stop searching if this quadrant can’t contain a closer node.
  7452. if (!(node = q.node)
  7453. || (x1 = q.x0) > x3
  7454. || (y1 = q.y0) > y3
  7455. || (x2 = q.x1) < x0
  7456. || (y2 = q.y1) < y0) continue;
  7457. // Bisect the current quadrant.
  7458. if (node.length) {
  7459. var xm = (x1 + x2) / 2,
  7460. ym = (y1 + y2) / 2;
  7461. quads.push(
  7462. new Quad(node[3], xm, ym, x2, y2),
  7463. new Quad(node[2], x1, ym, xm, y2),
  7464. new Quad(node[1], xm, y1, x2, ym),
  7465. new Quad(node[0], x1, y1, xm, ym)
  7466. );
  7467. // Visit the closest quadrant first.
  7468. if (i = (y >= ym) << 1 | (x >= xm)) {
  7469. q = quads[quads.length - 1];
  7470. quads[quads.length - 1] = quads[quads.length - 1 - i];
  7471. quads[quads.length - 1 - i] = q;
  7472. }
  7473. }
  7474. // Visit this point. (Visiting coincident points isn’t necessary!)
  7475. else {
  7476. var dx = x - +this._x.call(null, node.data),
  7477. dy = y - +this._y.call(null, node.data),
  7478. d2 = dx * dx + dy * dy;
  7479. if (d2 < radius) {
  7480. var d = Math.sqrt(radius = d2);
  7481. x0 = x - d, y0 = y - d;
  7482. x3 = x + d, y3 = y + d;
  7483. data = node.data;
  7484. }
  7485. }
  7486. }
  7487. return data;
  7488. }
  7489. function tree_remove(d) {
  7490. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  7491. var parent,
  7492. node = this._root,
  7493. retainer,
  7494. previous,
  7495. next,
  7496. x0 = this._x0,
  7497. y0 = this._y0,
  7498. x1 = this._x1,
  7499. y1 = this._y1,
  7500. x,
  7501. y,
  7502. xm,
  7503. ym,
  7504. right,
  7505. bottom,
  7506. i,
  7507. j;
  7508. // If the tree is empty, initialize the root as a leaf.
  7509. if (!node) return this;
  7510. // Find the leaf node for the point.
  7511. // While descending, also retain the deepest parent with a non-removed sibling.
  7512. if (node.length) while (true) {
  7513. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7514. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7515. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  7516. if (!node.length) break;
  7517. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  7518. }
  7519. // Find the point to remove.
  7520. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  7521. if (next = node.next) delete node.next;
  7522. // If there are multiple coincident points, remove just the point.
  7523. if (previous) return (next ? previous.next = next : delete previous.next), this;
  7524. // If this is the root point, remove it.
  7525. if (!parent) return this._root = next, this;
  7526. // Remove this leaf.
  7527. next ? parent[i] = next : delete parent[i];
  7528. // If the parent now contains exactly one leaf, collapse superfluous parents.
  7529. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  7530. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  7531. && !node.length) {
  7532. if (retainer) retainer[j] = node;
  7533. else this._root = node;
  7534. }
  7535. return this;
  7536. }
  7537. function removeAll(data) {
  7538. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  7539. return this;
  7540. }
  7541. function tree_root() {
  7542. return this._root;
  7543. }
  7544. function tree_size() {
  7545. var size = 0;
  7546. this.visit(function(node) {
  7547. if (!node.length) do ++size; while (node = node.next)
  7548. });
  7549. return size;
  7550. }
  7551. function tree_visit(callback) {
  7552. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  7553. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  7554. while (q = quads.pop()) {
  7555. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  7556. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7557. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7558. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7559. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7560. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7561. }
  7562. }
  7563. return this;
  7564. }
  7565. function tree_visitAfter(callback) {
  7566. var quads = [], next = [], q;
  7567. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  7568. while (q = quads.pop()) {
  7569. var node = q.node;
  7570. if (node.length) {
  7571. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7572. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7573. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7574. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7575. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7576. }
  7577. next.push(q);
  7578. }
  7579. while (q = next.pop()) {
  7580. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  7581. }
  7582. return this;
  7583. }
  7584. function defaultX(d) {
  7585. return d[0];
  7586. }
  7587. function tree_x(_) {
  7588. return arguments.length ? (this._x = _, this) : this._x;
  7589. }
  7590. function defaultY(d) {
  7591. return d[1];
  7592. }
  7593. function tree_y(_) {
  7594. return arguments.length ? (this._y = _, this) : this._y;
  7595. }
  7596. function quadtree(nodes, x, y) {
  7597. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  7598. return nodes == null ? tree : tree.addAll(nodes);
  7599. }
  7600. function Quadtree(x, y, x0, y0, x1, y1) {
  7601. this._x = x;
  7602. this._y = y;
  7603. this._x0 = x0;
  7604. this._y0 = y0;
  7605. this._x1 = x1;
  7606. this._y1 = y1;
  7607. this._root = undefined;
  7608. }
  7609. function leaf_copy(leaf) {
  7610. var copy = {data: leaf.data}, next = copy;
  7611. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  7612. return copy;
  7613. }
  7614. var treeProto = quadtree.prototype = Quadtree.prototype;
  7615. treeProto.copy = function() {
  7616. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  7617. node = this._root,
  7618. nodes,
  7619. child;
  7620. if (!node) return copy;
  7621. if (!node.length) return copy._root = leaf_copy(node), copy;
  7622. nodes = [{source: node, target: copy._root = new Array(4)}];
  7623. while (node = nodes.pop()) {
  7624. for (var i = 0; i < 4; ++i) {
  7625. if (child = node.source[i]) {
  7626. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  7627. else node.target[i] = leaf_copy(child);
  7628. }
  7629. }
  7630. }
  7631. return copy;
  7632. };
  7633. treeProto.add = tree_add;
  7634. treeProto.addAll = addAll;
  7635. treeProto.cover = tree_cover;
  7636. treeProto.data = tree_data;
  7637. treeProto.extent = tree_extent;
  7638. treeProto.find = tree_find;
  7639. treeProto.remove = tree_remove;
  7640. treeProto.removeAll = removeAll;
  7641. treeProto.root = tree_root;
  7642. treeProto.size = tree_size;
  7643. treeProto.visit = tree_visit;
  7644. treeProto.visitAfter = tree_visitAfter;
  7645. treeProto.x = tree_x;
  7646. treeProto.y = tree_y;
  7647. function constant$4(x) {
  7648. return function() {
  7649. return x;
  7650. };
  7651. }
  7652. function jiggle(random) {
  7653. return (random() - 0.5) * 1e-6;
  7654. }
  7655. function x$3(d) {
  7656. return d.x + d.vx;
  7657. }
  7658. function y$3(d) {
  7659. return d.y + d.vy;
  7660. }
  7661. function collide(radius) {
  7662. var nodes,
  7663. radii,
  7664. random,
  7665. strength = 1,
  7666. iterations = 1;
  7667. if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
  7668. function force() {
  7669. var i, n = nodes.length,
  7670. tree,
  7671. node,
  7672. xi,
  7673. yi,
  7674. ri,
  7675. ri2;
  7676. for (var k = 0; k < iterations; ++k) {
  7677. tree = quadtree(nodes, x$3, y$3).visitAfter(prepare);
  7678. for (i = 0; i < n; ++i) {
  7679. node = nodes[i];
  7680. ri = radii[node.index], ri2 = ri * ri;
  7681. xi = node.x + node.vx;
  7682. yi = node.y + node.vy;
  7683. tree.visit(apply);
  7684. }
  7685. }
  7686. function apply(quad, x0, y0, x1, y1) {
  7687. var data = quad.data, rj = quad.r, r = ri + rj;
  7688. if (data) {
  7689. if (data.index > node.index) {
  7690. var x = xi - data.x - data.vx,
  7691. y = yi - data.y - data.vy,
  7692. l = x * x + y * y;
  7693. if (l < r * r) {
  7694. if (x === 0) x = jiggle(random), l += x * x;
  7695. if (y === 0) y = jiggle(random), l += y * y;
  7696. l = (r - (l = Math.sqrt(l))) / l * strength;
  7697. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  7698. node.vy += (y *= l) * r;
  7699. data.vx -= x * (r = 1 - r);
  7700. data.vy -= y * r;
  7701. }
  7702. }
  7703. return;
  7704. }
  7705. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  7706. }
  7707. }
  7708. function prepare(quad) {
  7709. if (quad.data) return quad.r = radii[quad.data.index];
  7710. for (var i = quad.r = 0; i < 4; ++i) {
  7711. if (quad[i] && quad[i].r > quad.r) {
  7712. quad.r = quad[i].r;
  7713. }
  7714. }
  7715. }
  7716. function initialize() {
  7717. if (!nodes) return;
  7718. var i, n = nodes.length, node;
  7719. radii = new Array(n);
  7720. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  7721. }
  7722. force.initialize = function(_nodes, _random) {
  7723. nodes = _nodes;
  7724. random = _random;
  7725. initialize();
  7726. };
  7727. force.iterations = function(_) {
  7728. return arguments.length ? (iterations = +_, force) : iterations;
  7729. };
  7730. force.strength = function(_) {
  7731. return arguments.length ? (strength = +_, force) : strength;
  7732. };
  7733. force.radius = function(_) {
  7734. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  7735. };
  7736. return force;
  7737. }
  7738. function index$3(d) {
  7739. return d.index;
  7740. }
  7741. function find(nodeById, nodeId) {
  7742. var node = nodeById.get(nodeId);
  7743. if (!node) throw new Error("node not found: " + nodeId);
  7744. return node;
  7745. }
  7746. function link$2(links) {
  7747. var id = index$3,
  7748. strength = defaultStrength,
  7749. strengths,
  7750. distance = constant$4(30),
  7751. distances,
  7752. nodes,
  7753. count,
  7754. bias,
  7755. random,
  7756. iterations = 1;
  7757. if (links == null) links = [];
  7758. function defaultStrength(link) {
  7759. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  7760. }
  7761. function force(alpha) {
  7762. for (var k = 0, n = links.length; k < iterations; ++k) {
  7763. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  7764. link = links[i], source = link.source, target = link.target;
  7765. x = target.x + target.vx - source.x - source.vx || jiggle(random);
  7766. y = target.y + target.vy - source.y - source.vy || jiggle(random);
  7767. l = Math.sqrt(x * x + y * y);
  7768. l = (l - distances[i]) / l * alpha * strengths[i];
  7769. x *= l, y *= l;
  7770. target.vx -= x * (b = bias[i]);
  7771. target.vy -= y * b;
  7772. source.vx += x * (b = 1 - b);
  7773. source.vy += y * b;
  7774. }
  7775. }
  7776. }
  7777. function initialize() {
  7778. if (!nodes) return;
  7779. var i,
  7780. n = nodes.length,
  7781. m = links.length,
  7782. nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
  7783. link;
  7784. for (i = 0, count = new Array(n); i < m; ++i) {
  7785. link = links[i], link.index = i;
  7786. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  7787. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  7788. count[link.source.index] = (count[link.source.index] || 0) + 1;
  7789. count[link.target.index] = (count[link.target.index] || 0) + 1;
  7790. }
  7791. for (i = 0, bias = new Array(m); i < m; ++i) {
  7792. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  7793. }
  7794. strengths = new Array(m), initializeStrength();
  7795. distances = new Array(m), initializeDistance();
  7796. }
  7797. function initializeStrength() {
  7798. if (!nodes) return;
  7799. for (var i = 0, n = links.length; i < n; ++i) {
  7800. strengths[i] = +strength(links[i], i, links);
  7801. }
  7802. }
  7803. function initializeDistance() {
  7804. if (!nodes) return;
  7805. for (var i = 0, n = links.length; i < n; ++i) {
  7806. distances[i] = +distance(links[i], i, links);
  7807. }
  7808. }
  7809. force.initialize = function(_nodes, _random) {
  7810. nodes = _nodes;
  7811. random = _random;
  7812. initialize();
  7813. };
  7814. force.links = function(_) {
  7815. return arguments.length ? (links = _, initialize(), force) : links;
  7816. };
  7817. force.id = function(_) {
  7818. return arguments.length ? (id = _, force) : id;
  7819. };
  7820. force.iterations = function(_) {
  7821. return arguments.length ? (iterations = +_, force) : iterations;
  7822. };
  7823. force.strength = function(_) {
  7824. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
  7825. };
  7826. force.distance = function(_) {
  7827. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
  7828. };
  7829. return force;
  7830. }
  7831. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  7832. const a$2 = 1664525;
  7833. const c$4 = 1013904223;
  7834. const m$1 = 4294967296; // 2^32
  7835. function lcg$2() {
  7836. let s = 1;
  7837. return () => (s = (a$2 * s + c$4) % m$1) / m$1;
  7838. }
  7839. function x$2(d) {
  7840. return d.x;
  7841. }
  7842. function y$2(d) {
  7843. return d.y;
  7844. }
  7845. var initialRadius = 10,
  7846. initialAngle = Math.PI * (3 - Math.sqrt(5));
  7847. function simulation(nodes) {
  7848. var simulation,
  7849. alpha = 1,
  7850. alphaMin = 0.001,
  7851. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  7852. alphaTarget = 0,
  7853. velocityDecay = 0.6,
  7854. forces = new Map(),
  7855. stepper = timer(step),
  7856. event = dispatch("tick", "end"),
  7857. random = lcg$2();
  7858. if (nodes == null) nodes = [];
  7859. function step() {
  7860. tick();
  7861. event.call("tick", simulation);
  7862. if (alpha < alphaMin) {
  7863. stepper.stop();
  7864. event.call("end", simulation);
  7865. }
  7866. }
  7867. function tick(iterations) {
  7868. var i, n = nodes.length, node;
  7869. if (iterations === undefined) iterations = 1;
  7870. for (var k = 0; k < iterations; ++k) {
  7871. alpha += (alphaTarget - alpha) * alphaDecay;
  7872. forces.forEach(function(force) {
  7873. force(alpha);
  7874. });
  7875. for (i = 0; i < n; ++i) {
  7876. node = nodes[i];
  7877. if (node.fx == null) node.x += node.vx *= velocityDecay;
  7878. else node.x = node.fx, node.vx = 0;
  7879. if (node.fy == null) node.y += node.vy *= velocityDecay;
  7880. else node.y = node.fy, node.vy = 0;
  7881. }
  7882. }
  7883. return simulation;
  7884. }
  7885. function initializeNodes() {
  7886. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7887. node = nodes[i], node.index = i;
  7888. if (node.fx != null) node.x = node.fx;
  7889. if (node.fy != null) node.y = node.fy;
  7890. if (isNaN(node.x) || isNaN(node.y)) {
  7891. var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
  7892. node.x = radius * Math.cos(angle);
  7893. node.y = radius * Math.sin(angle);
  7894. }
  7895. if (isNaN(node.vx) || isNaN(node.vy)) {
  7896. node.vx = node.vy = 0;
  7897. }
  7898. }
  7899. }
  7900. function initializeForce(force) {
  7901. if (force.initialize) force.initialize(nodes, random);
  7902. return force;
  7903. }
  7904. initializeNodes();
  7905. return simulation = {
  7906. tick: tick,
  7907. restart: function() {
  7908. return stepper.restart(step), simulation;
  7909. },
  7910. stop: function() {
  7911. return stepper.stop(), simulation;
  7912. },
  7913. nodes: function(_) {
  7914. return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
  7915. },
  7916. alpha: function(_) {
  7917. return arguments.length ? (alpha = +_, simulation) : alpha;
  7918. },
  7919. alphaMin: function(_) {
  7920. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  7921. },
  7922. alphaDecay: function(_) {
  7923. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  7924. },
  7925. alphaTarget: function(_) {
  7926. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  7927. },
  7928. velocityDecay: function(_) {
  7929. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  7930. },
  7931. randomSource: function(_) {
  7932. return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
  7933. },
  7934. force: function(name, _) {
  7935. return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  7936. },
  7937. find: function(x, y, radius) {
  7938. var i = 0,
  7939. n = nodes.length,
  7940. dx,
  7941. dy,
  7942. d2,
  7943. node,
  7944. closest;
  7945. if (radius == null) radius = Infinity;
  7946. else radius *= radius;
  7947. for (i = 0; i < n; ++i) {
  7948. node = nodes[i];
  7949. dx = x - node.x;
  7950. dy = y - node.y;
  7951. d2 = dx * dx + dy * dy;
  7952. if (d2 < radius) closest = node, radius = d2;
  7953. }
  7954. return closest;
  7955. },
  7956. on: function(name, _) {
  7957. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  7958. }
  7959. };
  7960. }
  7961. function manyBody() {
  7962. var nodes,
  7963. node,
  7964. random,
  7965. alpha,
  7966. strength = constant$4(-30),
  7967. strengths,
  7968. distanceMin2 = 1,
  7969. distanceMax2 = Infinity,
  7970. theta2 = 0.81;
  7971. function force(_) {
  7972. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
  7973. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  7974. }
  7975. function initialize() {
  7976. if (!nodes) return;
  7977. var i, n = nodes.length, node;
  7978. strengths = new Array(n);
  7979. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  7980. }
  7981. function accumulate(quad) {
  7982. var strength = 0, q, c, weight = 0, x, y, i;
  7983. // For internal nodes, accumulate forces from child quadrants.
  7984. if (quad.length) {
  7985. for (x = y = i = 0; i < 4; ++i) {
  7986. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  7987. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  7988. }
  7989. }
  7990. quad.x = x / weight;
  7991. quad.y = y / weight;
  7992. }
  7993. // For leaf nodes, accumulate forces from coincident quadrants.
  7994. else {
  7995. q = quad;
  7996. q.x = q.data.x;
  7997. q.y = q.data.y;
  7998. do strength += strengths[q.data.index];
  7999. while (q = q.next);
  8000. }
  8001. quad.value = strength;
  8002. }
  8003. function apply(quad, x1, _, x2) {
  8004. if (!quad.value) return true;
  8005. var x = quad.x - node.x,
  8006. y = quad.y - node.y,
  8007. w = x2 - x1,
  8008. l = x * x + y * y;
  8009. // Apply the Barnes-Hut approximation if possible.
  8010. // Limit forces for very close nodes; randomize direction if coincident.
  8011. if (w * w / theta2 < l) {
  8012. if (l < distanceMax2) {
  8013. if (x === 0) x = jiggle(random), l += x * x;
  8014. if (y === 0) y = jiggle(random), l += y * y;
  8015. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8016. node.vx += x * quad.value * alpha / l;
  8017. node.vy += y * quad.value * alpha / l;
  8018. }
  8019. return true;
  8020. }
  8021. // Otherwise, process points directly.
  8022. else if (quad.length || l >= distanceMax2) return;
  8023. // Limit forces for very close nodes; randomize direction if coincident.
  8024. if (quad.data !== node || quad.next) {
  8025. if (x === 0) x = jiggle(random), l += x * x;
  8026. if (y === 0) y = jiggle(random), l += y * y;
  8027. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8028. }
  8029. do if (quad.data !== node) {
  8030. w = strengths[quad.data.index] * alpha / l;
  8031. node.vx += x * w;
  8032. node.vy += y * w;
  8033. } while (quad = quad.next);
  8034. }
  8035. force.initialize = function(_nodes, _random) {
  8036. nodes = _nodes;
  8037. random = _random;
  8038. initialize();
  8039. };
  8040. force.strength = function(_) {
  8041. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8042. };
  8043. force.distanceMin = function(_) {
  8044. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  8045. };
  8046. force.distanceMax = function(_) {
  8047. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  8048. };
  8049. force.theta = function(_) {
  8050. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  8051. };
  8052. return force;
  8053. }
  8054. function radial$1(radius, x, y) {
  8055. var nodes,
  8056. strength = constant$4(0.1),
  8057. strengths,
  8058. radiuses;
  8059. if (typeof radius !== "function") radius = constant$4(+radius);
  8060. if (x == null) x = 0;
  8061. if (y == null) y = 0;
  8062. function force(alpha) {
  8063. for (var i = 0, n = nodes.length; i < n; ++i) {
  8064. var node = nodes[i],
  8065. dx = node.x - x || 1e-6,
  8066. dy = node.y - y || 1e-6,
  8067. r = Math.sqrt(dx * dx + dy * dy),
  8068. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  8069. node.vx += dx * k;
  8070. node.vy += dy * k;
  8071. }
  8072. }
  8073. function initialize() {
  8074. if (!nodes) return;
  8075. var i, n = nodes.length;
  8076. strengths = new Array(n);
  8077. radiuses = new Array(n);
  8078. for (i = 0; i < n; ++i) {
  8079. radiuses[i] = +radius(nodes[i], i, nodes);
  8080. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  8081. }
  8082. }
  8083. force.initialize = function(_) {
  8084. nodes = _, initialize();
  8085. };
  8086. force.strength = function(_) {
  8087. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8088. };
  8089. force.radius = function(_) {
  8090. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  8091. };
  8092. force.x = function(_) {
  8093. return arguments.length ? (x = +_, force) : x;
  8094. };
  8095. force.y = function(_) {
  8096. return arguments.length ? (y = +_, force) : y;
  8097. };
  8098. return force;
  8099. }
  8100. function x$1(x) {
  8101. var strength = constant$4(0.1),
  8102. nodes,
  8103. strengths,
  8104. xz;
  8105. if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
  8106. function force(alpha) {
  8107. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8108. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  8109. }
  8110. }
  8111. function initialize() {
  8112. if (!nodes) return;
  8113. var i, n = nodes.length;
  8114. strengths = new Array(n);
  8115. xz = new Array(n);
  8116. for (i = 0; i < n; ++i) {
  8117. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8118. }
  8119. }
  8120. force.initialize = function(_) {
  8121. nodes = _;
  8122. initialize();
  8123. };
  8124. force.strength = function(_) {
  8125. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8126. };
  8127. force.x = function(_) {
  8128. return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
  8129. };
  8130. return force;
  8131. }
  8132. function y$1(y) {
  8133. var strength = constant$4(0.1),
  8134. nodes,
  8135. strengths,
  8136. yz;
  8137. if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
  8138. function force(alpha) {
  8139. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8140. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  8141. }
  8142. }
  8143. function initialize() {
  8144. if (!nodes) return;
  8145. var i, n = nodes.length;
  8146. strengths = new Array(n);
  8147. yz = new Array(n);
  8148. for (i = 0; i < n; ++i) {
  8149. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8150. }
  8151. }
  8152. force.initialize = function(_) {
  8153. nodes = _;
  8154. initialize();
  8155. };
  8156. force.strength = function(_) {
  8157. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8158. };
  8159. force.y = function(_) {
  8160. return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
  8161. };
  8162. return force;
  8163. }
  8164. function formatDecimal(x) {
  8165. return Math.abs(x = Math.round(x)) >= 1e21
  8166. ? x.toLocaleString("en").replace(/,/g, "")
  8167. : x.toString(10);
  8168. }
  8169. // Computes the decimal coefficient and exponent of the specified number x with
  8170. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  8171. // For example, formatDecimalParts(1.23) returns ["123", 0].
  8172. function formatDecimalParts(x, p) {
  8173. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  8174. var i, coefficient = x.slice(0, i);
  8175. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  8176. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  8177. return [
  8178. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  8179. +x.slice(i + 1)
  8180. ];
  8181. }
  8182. function exponent(x) {
  8183. return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
  8184. }
  8185. function formatGroup(grouping, thousands) {
  8186. return function(value, width) {
  8187. var i = value.length,
  8188. t = [],
  8189. j = 0,
  8190. g = grouping[0],
  8191. length = 0;
  8192. while (i > 0 && g > 0) {
  8193. if (length + g + 1 > width) g = Math.max(1, width - length);
  8194. t.push(value.substring(i -= g, i + g));
  8195. if ((length += g + 1) > width) break;
  8196. g = grouping[j = (j + 1) % grouping.length];
  8197. }
  8198. return t.reverse().join(thousands);
  8199. };
  8200. }
  8201. function formatNumerals(numerals) {
  8202. return function(value) {
  8203. return value.replace(/[0-9]/g, function(i) {
  8204. return numerals[+i];
  8205. });
  8206. };
  8207. }
  8208. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  8209. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  8210. function formatSpecifier(specifier) {
  8211. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  8212. var match;
  8213. return new FormatSpecifier({
  8214. fill: match[1],
  8215. align: match[2],
  8216. sign: match[3],
  8217. symbol: match[4],
  8218. zero: match[5],
  8219. width: match[6],
  8220. comma: match[7],
  8221. precision: match[8] && match[8].slice(1),
  8222. trim: match[9],
  8223. type: match[10]
  8224. });
  8225. }
  8226. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  8227. function FormatSpecifier(specifier) {
  8228. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  8229. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  8230. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  8231. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  8232. this.zero = !!specifier.zero;
  8233. this.width = specifier.width === undefined ? undefined : +specifier.width;
  8234. this.comma = !!specifier.comma;
  8235. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  8236. this.trim = !!specifier.trim;
  8237. this.type = specifier.type === undefined ? "" : specifier.type + "";
  8238. }
  8239. FormatSpecifier.prototype.toString = function() {
  8240. return this.fill
  8241. + this.align
  8242. + this.sign
  8243. + this.symbol
  8244. + (this.zero ? "0" : "")
  8245. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  8246. + (this.comma ? "," : "")
  8247. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  8248. + (this.trim ? "~" : "")
  8249. + this.type;
  8250. };
  8251. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  8252. function formatTrim(s) {
  8253. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  8254. switch (s[i]) {
  8255. case ".": i0 = i1 = i; break;
  8256. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  8257. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  8258. }
  8259. }
  8260. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  8261. }
  8262. var prefixExponent;
  8263. function formatPrefixAuto(x, p) {
  8264. var d = formatDecimalParts(x, p);
  8265. if (!d) return x + "";
  8266. var coefficient = d[0],
  8267. exponent = d[1],
  8268. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  8269. n = coefficient.length;
  8270. return i === n ? coefficient
  8271. : i > n ? coefficient + new Array(i - n + 1).join("0")
  8272. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  8273. : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  8274. }
  8275. function formatRounded(x, p) {
  8276. var d = formatDecimalParts(x, p);
  8277. if (!d) return x + "";
  8278. var coefficient = d[0],
  8279. exponent = d[1];
  8280. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  8281. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  8282. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  8283. }
  8284. var formatTypes = {
  8285. "%": (x, p) => (x * 100).toFixed(p),
  8286. "b": (x) => Math.round(x).toString(2),
  8287. "c": (x) => x + "",
  8288. "d": formatDecimal,
  8289. "e": (x, p) => x.toExponential(p),
  8290. "f": (x, p) => x.toFixed(p),
  8291. "g": (x, p) => x.toPrecision(p),
  8292. "o": (x) => Math.round(x).toString(8),
  8293. "p": (x, p) => formatRounded(x * 100, p),
  8294. "r": formatRounded,
  8295. "s": formatPrefixAuto,
  8296. "X": (x) => Math.round(x).toString(16).toUpperCase(),
  8297. "x": (x) => Math.round(x).toString(16)
  8298. };
  8299. function identity$6(x) {
  8300. return x;
  8301. }
  8302. var map = Array.prototype.map,
  8303. prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
  8304. function formatLocale$1(locale) {
  8305. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
  8306. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  8307. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  8308. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  8309. numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
  8310. percent = locale.percent === undefined ? "%" : locale.percent + "",
  8311. minus = locale.minus === undefined ? "−" : locale.minus + "",
  8312. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  8313. function newFormat(specifier) {
  8314. specifier = formatSpecifier(specifier);
  8315. var fill = specifier.fill,
  8316. align = specifier.align,
  8317. sign = specifier.sign,
  8318. symbol = specifier.symbol,
  8319. zero = specifier.zero,
  8320. width = specifier.width,
  8321. comma = specifier.comma,
  8322. precision = specifier.precision,
  8323. trim = specifier.trim,
  8324. type = specifier.type;
  8325. // The "n" type is an alias for ",g".
  8326. if (type === "n") comma = true, type = "g";
  8327. // The "" type, and any invalid type, is an alias for ".12~g".
  8328. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  8329. // If zero fill is specified, padding goes after sign and before digits.
  8330. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  8331. // Compute the prefix and suffix.
  8332. // For SI-prefix, the suffix is lazily computed.
  8333. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  8334. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  8335. // What format function should we use?
  8336. // Is this an integer type?
  8337. // Can this type generate exponential notation?
  8338. var formatType = formatTypes[type],
  8339. maybeSuffix = /[defgprs%]/.test(type);
  8340. // Set the default precision if not specified,
  8341. // or clamp the specified precision to the supported range.
  8342. // For significant precision, it must be in [1, 21].
  8343. // For fixed precision, it must be in [0, 20].
  8344. precision = precision === undefined ? 6
  8345. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  8346. : Math.max(0, Math.min(20, precision));
  8347. function format(value) {
  8348. var valuePrefix = prefix,
  8349. valueSuffix = suffix,
  8350. i, n, c;
  8351. if (type === "c") {
  8352. valueSuffix = formatType(value) + valueSuffix;
  8353. value = "";
  8354. } else {
  8355. value = +value;
  8356. // Determine the sign. -0 is not less than 0, but 1 / -0 is!
  8357. var valueNegative = value < 0 || 1 / value < 0;
  8358. // Perform the initial formatting.
  8359. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  8360. // Trim insignificant zeros.
  8361. if (trim) value = formatTrim(value);
  8362. // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
  8363. if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
  8364. // Compute the prefix and suffix.
  8365. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  8366. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  8367. // Break the formatted value into the integer “value” part that can be
  8368. // grouped, and fractional or exponential “suffix” part that is not.
  8369. if (maybeSuffix) {
  8370. i = -1, n = value.length;
  8371. while (++i < n) {
  8372. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  8373. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  8374. value = value.slice(0, i);
  8375. break;
  8376. }
  8377. }
  8378. }
  8379. }
  8380. // If the fill character is not "0", grouping is applied before padding.
  8381. if (comma && !zero) value = group(value, Infinity);
  8382. // Compute the padding.
  8383. var length = valuePrefix.length + value.length + valueSuffix.length,
  8384. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  8385. // If the fill character is "0", grouping is applied after padding.
  8386. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  8387. // Reconstruct the final output based on the desired alignment.
  8388. switch (align) {
  8389. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  8390. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  8391. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  8392. default: value = padding + valuePrefix + value + valueSuffix; break;
  8393. }
  8394. return numerals(value);
  8395. }
  8396. format.toString = function() {
  8397. return specifier + "";
  8398. };
  8399. return format;
  8400. }
  8401. function formatPrefix(specifier, value) {
  8402. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  8403. e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
  8404. k = Math.pow(10, -e),
  8405. prefix = prefixes[8 + e / 3];
  8406. return function(value) {
  8407. return f(k * value) + prefix;
  8408. };
  8409. }
  8410. return {
  8411. format: newFormat,
  8412. formatPrefix: formatPrefix
  8413. };
  8414. }
  8415. var locale$1;
  8416. exports.format = void 0;
  8417. exports.formatPrefix = void 0;
  8418. defaultLocale$1({
  8419. thousands: ",",
  8420. grouping: [3],
  8421. currency: ["$", ""]
  8422. });
  8423. function defaultLocale$1(definition) {
  8424. locale$1 = formatLocale$1(definition);
  8425. exports.format = locale$1.format;
  8426. exports.formatPrefix = locale$1.formatPrefix;
  8427. return locale$1;
  8428. }
  8429. function precisionFixed(step) {
  8430. return Math.max(0, -exponent(Math.abs(step)));
  8431. }
  8432. function precisionPrefix(step, value) {
  8433. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
  8434. }
  8435. function precisionRound(step, max) {
  8436. step = Math.abs(step), max = Math.abs(max) - step;
  8437. return Math.max(0, exponent(max) - exponent(step)) + 1;
  8438. }
  8439. var epsilon$1 = 1e-6;
  8440. var epsilon2 = 1e-12;
  8441. var pi$1 = Math.PI;
  8442. var halfPi$1 = pi$1 / 2;
  8443. var quarterPi = pi$1 / 4;
  8444. var tau$1 = pi$1 * 2;
  8445. var degrees = 180 / pi$1;
  8446. var radians = pi$1 / 180;
  8447. var abs$1 = Math.abs;
  8448. var atan = Math.atan;
  8449. var atan2$1 = Math.atan2;
  8450. var cos$1 = Math.cos;
  8451. var ceil = Math.ceil;
  8452. var exp = Math.exp;
  8453. var hypot = Math.hypot;
  8454. var log$1 = Math.log;
  8455. var pow$1 = Math.pow;
  8456. var sin$1 = Math.sin;
  8457. var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  8458. var sqrt$2 = Math.sqrt;
  8459. var tan = Math.tan;
  8460. function acos$1(x) {
  8461. return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
  8462. }
  8463. function asin$1(x) {
  8464. return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
  8465. }
  8466. function haversin(x) {
  8467. return (x = sin$1(x / 2)) * x;
  8468. }
  8469. function noop$1() {}
  8470. function streamGeometry(geometry, stream) {
  8471. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  8472. streamGeometryType[geometry.type](geometry, stream);
  8473. }
  8474. }
  8475. var streamObjectType = {
  8476. Feature: function(object, stream) {
  8477. streamGeometry(object.geometry, stream);
  8478. },
  8479. FeatureCollection: function(object, stream) {
  8480. var features = object.features, i = -1, n = features.length;
  8481. while (++i < n) streamGeometry(features[i].geometry, stream);
  8482. }
  8483. };
  8484. var streamGeometryType = {
  8485. Sphere: function(object, stream) {
  8486. stream.sphere();
  8487. },
  8488. Point: function(object, stream) {
  8489. object = object.coordinates;
  8490. stream.point(object[0], object[1], object[2]);
  8491. },
  8492. MultiPoint: function(object, stream) {
  8493. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8494. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  8495. },
  8496. LineString: function(object, stream) {
  8497. streamLine(object.coordinates, stream, 0);
  8498. },
  8499. MultiLineString: function(object, stream) {
  8500. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8501. while (++i < n) streamLine(coordinates[i], stream, 0);
  8502. },
  8503. Polygon: function(object, stream) {
  8504. streamPolygon(object.coordinates, stream);
  8505. },
  8506. MultiPolygon: function(object, stream) {
  8507. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8508. while (++i < n) streamPolygon(coordinates[i], stream);
  8509. },
  8510. GeometryCollection: function(object, stream) {
  8511. var geometries = object.geometries, i = -1, n = geometries.length;
  8512. while (++i < n) streamGeometry(geometries[i], stream);
  8513. }
  8514. };
  8515. function streamLine(coordinates, stream, closed) {
  8516. var i = -1, n = coordinates.length - closed, coordinate;
  8517. stream.lineStart();
  8518. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  8519. stream.lineEnd();
  8520. }
  8521. function streamPolygon(coordinates, stream) {
  8522. var i = -1, n = coordinates.length;
  8523. stream.polygonStart();
  8524. while (++i < n) streamLine(coordinates[i], stream, 1);
  8525. stream.polygonEnd();
  8526. }
  8527. function geoStream(object, stream) {
  8528. if (object && streamObjectType.hasOwnProperty(object.type)) {
  8529. streamObjectType[object.type](object, stream);
  8530. } else {
  8531. streamGeometry(object, stream);
  8532. }
  8533. }
  8534. var areaRingSum$1 = new Adder();
  8535. // hello?
  8536. var areaSum$1 = new Adder(),
  8537. lambda00$2,
  8538. phi00$2,
  8539. lambda0$2,
  8540. cosPhi0$1,
  8541. sinPhi0$1;
  8542. var areaStream$1 = {
  8543. point: noop$1,
  8544. lineStart: noop$1,
  8545. lineEnd: noop$1,
  8546. polygonStart: function() {
  8547. areaRingSum$1 = new Adder();
  8548. areaStream$1.lineStart = areaRingStart$1;
  8549. areaStream$1.lineEnd = areaRingEnd$1;
  8550. },
  8551. polygonEnd: function() {
  8552. var areaRing = +areaRingSum$1;
  8553. areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
  8554. this.lineStart = this.lineEnd = this.point = noop$1;
  8555. },
  8556. sphere: function() {
  8557. areaSum$1.add(tau$1);
  8558. }
  8559. };
  8560. function areaRingStart$1() {
  8561. areaStream$1.point = areaPointFirst$1;
  8562. }
  8563. function areaRingEnd$1() {
  8564. areaPoint$1(lambda00$2, phi00$2);
  8565. }
  8566. function areaPointFirst$1(lambda, phi) {
  8567. areaStream$1.point = areaPoint$1;
  8568. lambda00$2 = lambda, phi00$2 = phi;
  8569. lambda *= radians, phi *= radians;
  8570. lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
  8571. }
  8572. function areaPoint$1(lambda, phi) {
  8573. lambda *= radians, phi *= radians;
  8574. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  8575. // Spherical excess E for a spherical triangle with vertices: south pole,
  8576. // previous point, current point. Uses a formula derived from Cagnoli’s
  8577. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  8578. var dLambda = lambda - lambda0$2,
  8579. sdLambda = dLambda >= 0 ? 1 : -1,
  8580. adLambda = sdLambda * dLambda,
  8581. cosPhi = cos$1(phi),
  8582. sinPhi = sin$1(phi),
  8583. k = sinPhi0$1 * sinPhi,
  8584. u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
  8585. v = k * sdLambda * sin$1(adLambda);
  8586. areaRingSum$1.add(atan2$1(v, u));
  8587. // Advance the previous points.
  8588. lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
  8589. }
  8590. function area$2(object) {
  8591. areaSum$1 = new Adder();
  8592. geoStream(object, areaStream$1);
  8593. return areaSum$1 * 2;
  8594. }
  8595. function spherical(cartesian) {
  8596. return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
  8597. }
  8598. function cartesian(spherical) {
  8599. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  8600. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  8601. }
  8602. function cartesianDot(a, b) {
  8603. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  8604. }
  8605. function cartesianCross(a, b) {
  8606. return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
  8607. }
  8608. // TODO return a
  8609. function cartesianAddInPlace(a, b) {
  8610. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  8611. }
  8612. function cartesianScale(vector, k) {
  8613. return [vector[0] * k, vector[1] * k, vector[2] * k];
  8614. }
  8615. // TODO return d
  8616. function cartesianNormalizeInPlace(d) {
  8617. var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  8618. d[0] /= l, d[1] /= l, d[2] /= l;
  8619. }
  8620. var lambda0$1, phi0, lambda1, phi1, // bounds
  8621. lambda2, // previous lambda-coordinate
  8622. lambda00$1, phi00$1, // first point
  8623. p0, // previous 3D point
  8624. deltaSum,
  8625. ranges,
  8626. range;
  8627. var boundsStream$2 = {
  8628. point: boundsPoint$1,
  8629. lineStart: boundsLineStart,
  8630. lineEnd: boundsLineEnd,
  8631. polygonStart: function() {
  8632. boundsStream$2.point = boundsRingPoint;
  8633. boundsStream$2.lineStart = boundsRingStart;
  8634. boundsStream$2.lineEnd = boundsRingEnd;
  8635. deltaSum = new Adder();
  8636. areaStream$1.polygonStart();
  8637. },
  8638. polygonEnd: function() {
  8639. areaStream$1.polygonEnd();
  8640. boundsStream$2.point = boundsPoint$1;
  8641. boundsStream$2.lineStart = boundsLineStart;
  8642. boundsStream$2.lineEnd = boundsLineEnd;
  8643. if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8644. else if (deltaSum > epsilon$1) phi1 = 90;
  8645. else if (deltaSum < -epsilon$1) phi0 = -90;
  8646. range[0] = lambda0$1, range[1] = lambda1;
  8647. },
  8648. sphere: function() {
  8649. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8650. }
  8651. };
  8652. function boundsPoint$1(lambda, phi) {
  8653. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8654. if (phi < phi0) phi0 = phi;
  8655. if (phi > phi1) phi1 = phi;
  8656. }
  8657. function linePoint(lambda, phi) {
  8658. var p = cartesian([lambda * radians, phi * radians]);
  8659. if (p0) {
  8660. var normal = cartesianCross(p0, p),
  8661. equatorial = [normal[1], -normal[0], 0],
  8662. inflection = cartesianCross(equatorial, normal);
  8663. cartesianNormalizeInPlace(inflection);
  8664. inflection = spherical(inflection);
  8665. var delta = lambda - lambda2,
  8666. sign = delta > 0 ? 1 : -1,
  8667. lambdai = inflection[0] * degrees * sign,
  8668. phii,
  8669. antimeridian = abs$1(delta) > 180;
  8670. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8671. phii = inflection[1] * degrees;
  8672. if (phii > phi1) phi1 = phii;
  8673. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8674. phii = -inflection[1] * degrees;
  8675. if (phii < phi0) phi0 = phii;
  8676. } else {
  8677. if (phi < phi0) phi0 = phi;
  8678. if (phi > phi1) phi1 = phi;
  8679. }
  8680. if (antimeridian) {
  8681. if (lambda < lambda2) {
  8682. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8683. } else {
  8684. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8685. }
  8686. } else {
  8687. if (lambda1 >= lambda0$1) {
  8688. if (lambda < lambda0$1) lambda0$1 = lambda;
  8689. if (lambda > lambda1) lambda1 = lambda;
  8690. } else {
  8691. if (lambda > lambda2) {
  8692. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8693. } else {
  8694. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8695. }
  8696. }
  8697. }
  8698. } else {
  8699. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8700. }
  8701. if (phi < phi0) phi0 = phi;
  8702. if (phi > phi1) phi1 = phi;
  8703. p0 = p, lambda2 = lambda;
  8704. }
  8705. function boundsLineStart() {
  8706. boundsStream$2.point = linePoint;
  8707. }
  8708. function boundsLineEnd() {
  8709. range[0] = lambda0$1, range[1] = lambda1;
  8710. boundsStream$2.point = boundsPoint$1;
  8711. p0 = null;
  8712. }
  8713. function boundsRingPoint(lambda, phi) {
  8714. if (p0) {
  8715. var delta = lambda - lambda2;
  8716. deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  8717. } else {
  8718. lambda00$1 = lambda, phi00$1 = phi;
  8719. }
  8720. areaStream$1.point(lambda, phi);
  8721. linePoint(lambda, phi);
  8722. }
  8723. function boundsRingStart() {
  8724. areaStream$1.lineStart();
  8725. }
  8726. function boundsRingEnd() {
  8727. boundsRingPoint(lambda00$1, phi00$1);
  8728. areaStream$1.lineEnd();
  8729. if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
  8730. range[0] = lambda0$1, range[1] = lambda1;
  8731. p0 = null;
  8732. }
  8733. // Finds the left-right distance between two longitudes.
  8734. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  8735. // the distance between ±180° to be 360°.
  8736. function angle(lambda0, lambda1) {
  8737. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  8738. }
  8739. function rangeCompare(a, b) {
  8740. return a[0] - b[0];
  8741. }
  8742. function rangeContains(range, x) {
  8743. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  8744. }
  8745. function bounds(feature) {
  8746. var i, n, a, b, merged, deltaMax, delta;
  8747. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  8748. ranges = [];
  8749. geoStream(feature, boundsStream$2);
  8750. // First, sort ranges by their minimum longitudes.
  8751. if (n = ranges.length) {
  8752. ranges.sort(rangeCompare);
  8753. // Then, merge any ranges that overlap.
  8754. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  8755. b = ranges[i];
  8756. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  8757. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  8758. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  8759. } else {
  8760. merged.push(a = b);
  8761. }
  8762. }
  8763. // Finally, find the largest gap between the merged ranges.
  8764. // The final bounding box will be the inverse of this gap.
  8765. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  8766. b = merged[i];
  8767. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  8768. }
  8769. }
  8770. ranges = range = null;
  8771. return lambda0$1 === Infinity || phi0 === Infinity
  8772. ? [[NaN, NaN], [NaN, NaN]]
  8773. : [[lambda0$1, phi0], [lambda1, phi1]];
  8774. }
  8775. var W0, W1,
  8776. X0$1, Y0$1, Z0$1,
  8777. X1$1, Y1$1, Z1$1,
  8778. X2$1, Y2$1, Z2$1,
  8779. lambda00, phi00, // first point
  8780. x0$4, y0$4, z0; // previous point
  8781. var centroidStream$1 = {
  8782. sphere: noop$1,
  8783. point: centroidPoint$1,
  8784. lineStart: centroidLineStart$1,
  8785. lineEnd: centroidLineEnd$1,
  8786. polygonStart: function() {
  8787. centroidStream$1.lineStart = centroidRingStart$1;
  8788. centroidStream$1.lineEnd = centroidRingEnd$1;
  8789. },
  8790. polygonEnd: function() {
  8791. centroidStream$1.lineStart = centroidLineStart$1;
  8792. centroidStream$1.lineEnd = centroidLineEnd$1;
  8793. }
  8794. };
  8795. // Arithmetic mean of Cartesian vectors.
  8796. function centroidPoint$1(lambda, phi) {
  8797. lambda *= radians, phi *= radians;
  8798. var cosPhi = cos$1(phi);
  8799. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  8800. }
  8801. function centroidPointCartesian(x, y, z) {
  8802. ++W0;
  8803. X0$1 += (x - X0$1) / W0;
  8804. Y0$1 += (y - Y0$1) / W0;
  8805. Z0$1 += (z - Z0$1) / W0;
  8806. }
  8807. function centroidLineStart$1() {
  8808. centroidStream$1.point = centroidLinePointFirst;
  8809. }
  8810. function centroidLinePointFirst(lambda, phi) {
  8811. lambda *= radians, phi *= radians;
  8812. var cosPhi = cos$1(phi);
  8813. x0$4 = cosPhi * cos$1(lambda);
  8814. y0$4 = cosPhi * sin$1(lambda);
  8815. z0 = sin$1(phi);
  8816. centroidStream$1.point = centroidLinePoint;
  8817. centroidPointCartesian(x0$4, y0$4, z0);
  8818. }
  8819. function centroidLinePoint(lambda, phi) {
  8820. lambda *= radians, phi *= radians;
  8821. var cosPhi = cos$1(phi),
  8822. x = cosPhi * cos$1(lambda),
  8823. y = cosPhi * sin$1(lambda),
  8824. z = sin$1(phi),
  8825. w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
  8826. W1 += w;
  8827. X1$1 += w * (x0$4 + (x0$4 = x));
  8828. Y1$1 += w * (y0$4 + (y0$4 = y));
  8829. Z1$1 += w * (z0 + (z0 = z));
  8830. centroidPointCartesian(x0$4, y0$4, z0);
  8831. }
  8832. function centroidLineEnd$1() {
  8833. centroidStream$1.point = centroidPoint$1;
  8834. }
  8835. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  8836. // J. Applied Mechanics 42, 239 (1975).
  8837. function centroidRingStart$1() {
  8838. centroidStream$1.point = centroidRingPointFirst;
  8839. }
  8840. function centroidRingEnd$1() {
  8841. centroidRingPoint(lambda00, phi00);
  8842. centroidStream$1.point = centroidPoint$1;
  8843. }
  8844. function centroidRingPointFirst(lambda, phi) {
  8845. lambda00 = lambda, phi00 = phi;
  8846. lambda *= radians, phi *= radians;
  8847. centroidStream$1.point = centroidRingPoint;
  8848. var cosPhi = cos$1(phi);
  8849. x0$4 = cosPhi * cos$1(lambda);
  8850. y0$4 = cosPhi * sin$1(lambda);
  8851. z0 = sin$1(phi);
  8852. centroidPointCartesian(x0$4, y0$4, z0);
  8853. }
  8854. function centroidRingPoint(lambda, phi) {
  8855. lambda *= radians, phi *= radians;
  8856. var cosPhi = cos$1(phi),
  8857. x = cosPhi * cos$1(lambda),
  8858. y = cosPhi * sin$1(lambda),
  8859. z = sin$1(phi),
  8860. cx = y0$4 * z - z0 * y,
  8861. cy = z0 * x - x0$4 * z,
  8862. cz = x0$4 * y - y0$4 * x,
  8863. m = hypot(cx, cy, cz),
  8864. w = asin$1(m), // line weight = angle
  8865. v = m && -w / m; // area weight multiplier
  8866. X2$1.add(v * cx);
  8867. Y2$1.add(v * cy);
  8868. Z2$1.add(v * cz);
  8869. W1 += w;
  8870. X1$1 += w * (x0$4 + (x0$4 = x));
  8871. Y1$1 += w * (y0$4 + (y0$4 = y));
  8872. Z1$1 += w * (z0 + (z0 = z));
  8873. centroidPointCartesian(x0$4, y0$4, z0);
  8874. }
  8875. function centroid$1(object) {
  8876. W0 = W1 =
  8877. X0$1 = Y0$1 = Z0$1 =
  8878. X1$1 = Y1$1 = Z1$1 = 0;
  8879. X2$1 = new Adder();
  8880. Y2$1 = new Adder();
  8881. Z2$1 = new Adder();
  8882. geoStream(object, centroidStream$1);
  8883. var x = +X2$1,
  8884. y = +Y2$1,
  8885. z = +Z2$1,
  8886. m = hypot(x, y, z);
  8887. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  8888. if (m < epsilon2) {
  8889. x = X1$1, y = Y1$1, z = Z1$1;
  8890. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  8891. if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
  8892. m = hypot(x, y, z);
  8893. // If the feature still has an undefined ccentroid, then return.
  8894. if (m < epsilon2) return [NaN, NaN];
  8895. }
  8896. return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
  8897. }
  8898. function constant$3(x) {
  8899. return function() {
  8900. return x;
  8901. };
  8902. }
  8903. function compose(a, b) {
  8904. function compose(x, y) {
  8905. return x = a(x, y), b(x[0], x[1]);
  8906. }
  8907. if (a.invert && b.invert) compose.invert = function(x, y) {
  8908. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  8909. };
  8910. return compose;
  8911. }
  8912. function rotationIdentity(lambda, phi) {
  8913. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8914. return [lambda, phi];
  8915. }
  8916. rotationIdentity.invert = rotationIdentity;
  8917. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  8918. return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  8919. : rotationLambda(deltaLambda))
  8920. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  8921. : rotationIdentity);
  8922. }
  8923. function forwardRotationLambda(deltaLambda) {
  8924. return function(lambda, phi) {
  8925. lambda += deltaLambda;
  8926. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8927. return [lambda, phi];
  8928. };
  8929. }
  8930. function rotationLambda(deltaLambda) {
  8931. var rotation = forwardRotationLambda(deltaLambda);
  8932. rotation.invert = forwardRotationLambda(-deltaLambda);
  8933. return rotation;
  8934. }
  8935. function rotationPhiGamma(deltaPhi, deltaGamma) {
  8936. var cosDeltaPhi = cos$1(deltaPhi),
  8937. sinDeltaPhi = sin$1(deltaPhi),
  8938. cosDeltaGamma = cos$1(deltaGamma),
  8939. sinDeltaGamma = sin$1(deltaGamma);
  8940. function rotation(lambda, phi) {
  8941. var cosPhi = cos$1(phi),
  8942. x = cos$1(lambda) * cosPhi,
  8943. y = sin$1(lambda) * cosPhi,
  8944. z = sin$1(phi),
  8945. k = z * cosDeltaPhi + x * sinDeltaPhi;
  8946. return [
  8947. atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  8948. asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
  8949. ];
  8950. }
  8951. rotation.invert = function(lambda, phi) {
  8952. var cosPhi = cos$1(phi),
  8953. x = cos$1(lambda) * cosPhi,
  8954. y = sin$1(lambda) * cosPhi,
  8955. z = sin$1(phi),
  8956. k = z * cosDeltaGamma - y * sinDeltaGamma;
  8957. return [
  8958. atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  8959. asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
  8960. ];
  8961. };
  8962. return rotation;
  8963. }
  8964. function rotation(rotate) {
  8965. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  8966. function forward(coordinates) {
  8967. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  8968. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  8969. }
  8970. forward.invert = function(coordinates) {
  8971. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  8972. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  8973. };
  8974. return forward;
  8975. }
  8976. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  8977. function circleStream(stream, radius, delta, direction, t0, t1) {
  8978. if (!delta) return;
  8979. var cosRadius = cos$1(radius),
  8980. sinRadius = sin$1(radius),
  8981. step = direction * delta;
  8982. if (t0 == null) {
  8983. t0 = radius + direction * tau$1;
  8984. t1 = radius - step / 2;
  8985. } else {
  8986. t0 = circleRadius(cosRadius, t0);
  8987. t1 = circleRadius(cosRadius, t1);
  8988. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
  8989. }
  8990. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  8991. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  8992. stream.point(point[0], point[1]);
  8993. }
  8994. }
  8995. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  8996. function circleRadius(cosRadius, point) {
  8997. point = cartesian(point), point[0] -= cosRadius;
  8998. cartesianNormalizeInPlace(point);
  8999. var radius = acos$1(-point[1]);
  9000. return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
  9001. }
  9002. function circle$1() {
  9003. var center = constant$3([0, 0]),
  9004. radius = constant$3(90),
  9005. precision = constant$3(6),
  9006. ring,
  9007. rotate,
  9008. stream = {point: point};
  9009. function point(x, y) {
  9010. ring.push(x = rotate(x, y));
  9011. x[0] *= degrees, x[1] *= degrees;
  9012. }
  9013. function circle() {
  9014. var c = center.apply(this, arguments),
  9015. r = radius.apply(this, arguments) * radians,
  9016. p = precision.apply(this, arguments) * radians;
  9017. ring = [];
  9018. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  9019. circleStream(stream, r, p, 1);
  9020. c = {type: "Polygon", coordinates: [ring]};
  9021. ring = rotate = null;
  9022. return c;
  9023. }
  9024. circle.center = function(_) {
  9025. return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
  9026. };
  9027. circle.radius = function(_) {
  9028. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
  9029. };
  9030. circle.precision = function(_) {
  9031. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
  9032. };
  9033. return circle;
  9034. }
  9035. function clipBuffer() {
  9036. var lines = [],
  9037. line;
  9038. return {
  9039. point: function(x, y, m) {
  9040. line.push([x, y, m]);
  9041. },
  9042. lineStart: function() {
  9043. lines.push(line = []);
  9044. },
  9045. lineEnd: noop$1,
  9046. rejoin: function() {
  9047. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  9048. },
  9049. result: function() {
  9050. var result = lines;
  9051. lines = [];
  9052. line = null;
  9053. return result;
  9054. }
  9055. };
  9056. }
  9057. function pointEqual(a, b) {
  9058. return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
  9059. }
  9060. function Intersection(point, points, other, entry) {
  9061. this.x = point;
  9062. this.z = points;
  9063. this.o = other; // another intersection
  9064. this.e = entry; // is an entry?
  9065. this.v = false; // visited
  9066. this.n = this.p = null; // next & previous
  9067. }
  9068. // A generalized polygon clipping algorithm: given a polygon that has been cut
  9069. // into its visible line segments, and rejoins the segments by interpolating
  9070. // along the clip edge.
  9071. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  9072. var subject = [],
  9073. clip = [],
  9074. i,
  9075. n;
  9076. segments.forEach(function(segment) {
  9077. if ((n = segment.length - 1) <= 0) return;
  9078. var n, p0 = segment[0], p1 = segment[n], x;
  9079. if (pointEqual(p0, p1)) {
  9080. if (!p0[2] && !p1[2]) {
  9081. stream.lineStart();
  9082. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  9083. stream.lineEnd();
  9084. return;
  9085. }
  9086. // handle degenerate cases by moving the point
  9087. p1[0] += 2 * epsilon$1;
  9088. }
  9089. subject.push(x = new Intersection(p0, segment, null, true));
  9090. clip.push(x.o = new Intersection(p0, null, x, false));
  9091. subject.push(x = new Intersection(p1, segment, null, false));
  9092. clip.push(x.o = new Intersection(p1, null, x, true));
  9093. });
  9094. if (!subject.length) return;
  9095. clip.sort(compareIntersection);
  9096. link$1(subject);
  9097. link$1(clip);
  9098. for (i = 0, n = clip.length; i < n; ++i) {
  9099. clip[i].e = startInside = !startInside;
  9100. }
  9101. var start = subject[0],
  9102. points,
  9103. point;
  9104. while (1) {
  9105. // Find first unvisited intersection.
  9106. var current = start,
  9107. isSubject = true;
  9108. while (current.v) if ((current = current.n) === start) return;
  9109. points = current.z;
  9110. stream.lineStart();
  9111. do {
  9112. current.v = current.o.v = true;
  9113. if (current.e) {
  9114. if (isSubject) {
  9115. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  9116. } else {
  9117. interpolate(current.x, current.n.x, 1, stream);
  9118. }
  9119. current = current.n;
  9120. } else {
  9121. if (isSubject) {
  9122. points = current.p.z;
  9123. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  9124. } else {
  9125. interpolate(current.x, current.p.x, -1, stream);
  9126. }
  9127. current = current.p;
  9128. }
  9129. current = current.o;
  9130. points = current.z;
  9131. isSubject = !isSubject;
  9132. } while (!current.v);
  9133. stream.lineEnd();
  9134. }
  9135. }
  9136. function link$1(array) {
  9137. if (!(n = array.length)) return;
  9138. var n,
  9139. i = 0,
  9140. a = array[0],
  9141. b;
  9142. while (++i < n) {
  9143. a.n = b = array[i];
  9144. b.p = a;
  9145. a = b;
  9146. }
  9147. a.n = b = array[0];
  9148. b.p = a;
  9149. }
  9150. function longitude(point) {
  9151. return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
  9152. }
  9153. function polygonContains(polygon, point) {
  9154. var lambda = longitude(point),
  9155. phi = point[1],
  9156. sinPhi = sin$1(phi),
  9157. normal = [sin$1(lambda), -cos$1(lambda), 0],
  9158. angle = 0,
  9159. winding = 0;
  9160. var sum = new Adder();
  9161. if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
  9162. else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
  9163. for (var i = 0, n = polygon.length; i < n; ++i) {
  9164. if (!(m = (ring = polygon[i]).length)) continue;
  9165. var ring,
  9166. m,
  9167. point0 = ring[m - 1],
  9168. lambda0 = longitude(point0),
  9169. phi0 = point0[1] / 2 + quarterPi,
  9170. sinPhi0 = sin$1(phi0),
  9171. cosPhi0 = cos$1(phi0);
  9172. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  9173. var point1 = ring[j],
  9174. lambda1 = longitude(point1),
  9175. phi1 = point1[1] / 2 + quarterPi,
  9176. sinPhi1 = sin$1(phi1),
  9177. cosPhi1 = cos$1(phi1),
  9178. delta = lambda1 - lambda0,
  9179. sign = delta >= 0 ? 1 : -1,
  9180. absDelta = sign * delta,
  9181. antimeridian = absDelta > pi$1,
  9182. k = sinPhi0 * sinPhi1;
  9183. sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  9184. angle += antimeridian ? delta + sign * tau$1 : delta;
  9185. // Are the longitudes either side of the point’s meridian (lambda),
  9186. // and are the latitudes smaller than the parallel (phi)?
  9187. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  9188. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  9189. cartesianNormalizeInPlace(arc);
  9190. var intersection = cartesianCross(normal, arc);
  9191. cartesianNormalizeInPlace(intersection);
  9192. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
  9193. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  9194. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  9195. }
  9196. }
  9197. }
  9198. }
  9199. // First, determine whether the South pole is inside or outside:
  9200. //
  9201. // It is inside if:
  9202. // * the polygon winds around it in a clockwise direction.
  9203. // * the polygon does not (cumulatively) wind around it, but has a negative
  9204. // (counter-clockwise) area.
  9205. //
  9206. // Second, count the (signed) number of times a segment crosses a lambda
  9207. // from the point to the South pole. If it is zero, then the point is the
  9208. // same side as the South pole.
  9209. return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
  9210. }
  9211. function clip(pointVisible, clipLine, interpolate, start) {
  9212. return function(sink) {
  9213. var line = clipLine(sink),
  9214. ringBuffer = clipBuffer(),
  9215. ringSink = clipLine(ringBuffer),
  9216. polygonStarted = false,
  9217. polygon,
  9218. segments,
  9219. ring;
  9220. var clip = {
  9221. point: point,
  9222. lineStart: lineStart,
  9223. lineEnd: lineEnd,
  9224. polygonStart: function() {
  9225. clip.point = pointRing;
  9226. clip.lineStart = ringStart;
  9227. clip.lineEnd = ringEnd;
  9228. segments = [];
  9229. polygon = [];
  9230. },
  9231. polygonEnd: function() {
  9232. clip.point = point;
  9233. clip.lineStart = lineStart;
  9234. clip.lineEnd = lineEnd;
  9235. segments = merge(segments);
  9236. var startInside = polygonContains(polygon, start);
  9237. if (segments.length) {
  9238. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9239. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  9240. } else if (startInside) {
  9241. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9242. sink.lineStart();
  9243. interpolate(null, null, 1, sink);
  9244. sink.lineEnd();
  9245. }
  9246. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  9247. segments = polygon = null;
  9248. },
  9249. sphere: function() {
  9250. sink.polygonStart();
  9251. sink.lineStart();
  9252. interpolate(null, null, 1, sink);
  9253. sink.lineEnd();
  9254. sink.polygonEnd();
  9255. }
  9256. };
  9257. function point(lambda, phi) {
  9258. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  9259. }
  9260. function pointLine(lambda, phi) {
  9261. line.point(lambda, phi);
  9262. }
  9263. function lineStart() {
  9264. clip.point = pointLine;
  9265. line.lineStart();
  9266. }
  9267. function lineEnd() {
  9268. clip.point = point;
  9269. line.lineEnd();
  9270. }
  9271. function pointRing(lambda, phi) {
  9272. ring.push([lambda, phi]);
  9273. ringSink.point(lambda, phi);
  9274. }
  9275. function ringStart() {
  9276. ringSink.lineStart();
  9277. ring = [];
  9278. }
  9279. function ringEnd() {
  9280. pointRing(ring[0][0], ring[0][1]);
  9281. ringSink.lineEnd();
  9282. var clean = ringSink.clean(),
  9283. ringSegments = ringBuffer.result(),
  9284. i, n = ringSegments.length, m,
  9285. segment,
  9286. point;
  9287. ring.pop();
  9288. polygon.push(ring);
  9289. ring = null;
  9290. if (!n) return;
  9291. // No intersections.
  9292. if (clean & 1) {
  9293. segment = ringSegments[0];
  9294. if ((m = segment.length - 1) > 0) {
  9295. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9296. sink.lineStart();
  9297. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  9298. sink.lineEnd();
  9299. }
  9300. return;
  9301. }
  9302. // Rejoin connected segments.
  9303. // TODO reuse ringBuffer.rejoin()?
  9304. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  9305. segments.push(ringSegments.filter(validSegment));
  9306. }
  9307. return clip;
  9308. };
  9309. }
  9310. function validSegment(segment) {
  9311. return segment.length > 1;
  9312. }
  9313. // Intersections are sorted along the clip edge. For both antimeridian cutting
  9314. // and circle clipping, the same comparison is used.
  9315. function compareIntersection(a, b) {
  9316. return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
  9317. - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
  9318. }
  9319. var clipAntimeridian = clip(
  9320. function() { return true; },
  9321. clipAntimeridianLine,
  9322. clipAntimeridianInterpolate,
  9323. [-pi$1, -halfPi$1]
  9324. );
  9325. // Takes a line and cuts into visible segments. Return values: 0 - there were
  9326. // intersections or the line was empty; 1 - no intersections; 2 - there were
  9327. // intersections, and the first and last segments should be rejoined.
  9328. function clipAntimeridianLine(stream) {
  9329. var lambda0 = NaN,
  9330. phi0 = NaN,
  9331. sign0 = NaN,
  9332. clean; // no intersections
  9333. return {
  9334. lineStart: function() {
  9335. stream.lineStart();
  9336. clean = 1;
  9337. },
  9338. point: function(lambda1, phi1) {
  9339. var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
  9340. delta = abs$1(lambda1 - lambda0);
  9341. if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
  9342. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
  9343. stream.point(sign0, phi0);
  9344. stream.lineEnd();
  9345. stream.lineStart();
  9346. stream.point(sign1, phi0);
  9347. stream.point(lambda1, phi0);
  9348. clean = 0;
  9349. } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
  9350. if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
  9351. if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
  9352. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  9353. stream.point(sign0, phi0);
  9354. stream.lineEnd();
  9355. stream.lineStart();
  9356. stream.point(sign1, phi0);
  9357. clean = 0;
  9358. }
  9359. stream.point(lambda0 = lambda1, phi0 = phi1);
  9360. sign0 = sign1;
  9361. },
  9362. lineEnd: function() {
  9363. stream.lineEnd();
  9364. lambda0 = phi0 = NaN;
  9365. },
  9366. clean: function() {
  9367. return 2 - clean; // if intersections, rejoin first and last segments
  9368. }
  9369. };
  9370. }
  9371. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  9372. var cosPhi0,
  9373. cosPhi1,
  9374. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  9375. return abs$1(sinLambda0Lambda1) > epsilon$1
  9376. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  9377. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  9378. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  9379. : (phi0 + phi1) / 2;
  9380. }
  9381. function clipAntimeridianInterpolate(from, to, direction, stream) {
  9382. var phi;
  9383. if (from == null) {
  9384. phi = direction * halfPi$1;
  9385. stream.point(-pi$1, phi);
  9386. stream.point(0, phi);
  9387. stream.point(pi$1, phi);
  9388. stream.point(pi$1, 0);
  9389. stream.point(pi$1, -phi);
  9390. stream.point(0, -phi);
  9391. stream.point(-pi$1, -phi);
  9392. stream.point(-pi$1, 0);
  9393. stream.point(-pi$1, phi);
  9394. } else if (abs$1(from[0] - to[0]) > epsilon$1) {
  9395. var lambda = from[0] < to[0] ? pi$1 : -pi$1;
  9396. phi = direction * lambda / 2;
  9397. stream.point(-lambda, phi);
  9398. stream.point(0, phi);
  9399. stream.point(lambda, phi);
  9400. } else {
  9401. stream.point(to[0], to[1]);
  9402. }
  9403. }
  9404. function clipCircle(radius) {
  9405. var cr = cos$1(radius),
  9406. delta = 6 * radians,
  9407. smallRadius = cr > 0,
  9408. notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
  9409. function interpolate(from, to, direction, stream) {
  9410. circleStream(stream, radius, delta, direction, from, to);
  9411. }
  9412. function visible(lambda, phi) {
  9413. return cos$1(lambda) * cos$1(phi) > cr;
  9414. }
  9415. // Takes a line and cuts into visible segments. Return values used for polygon
  9416. // clipping: 0 - there were intersections or the line was empty; 1 - no
  9417. // intersections 2 - there were intersections, and the first and last segments
  9418. // should be rejoined.
  9419. function clipLine(stream) {
  9420. var point0, // previous point
  9421. c0, // code for previous point
  9422. v0, // visibility of previous point
  9423. v00, // visibility of first point
  9424. clean; // no intersections
  9425. return {
  9426. lineStart: function() {
  9427. v00 = v0 = false;
  9428. clean = 1;
  9429. },
  9430. point: function(lambda, phi) {
  9431. var point1 = [lambda, phi],
  9432. point2,
  9433. v = visible(lambda, phi),
  9434. c = smallRadius
  9435. ? v ? 0 : code(lambda, phi)
  9436. : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
  9437. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  9438. if (v !== v0) {
  9439. point2 = intersect(point0, point1);
  9440. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
  9441. point1[2] = 1;
  9442. }
  9443. if (v !== v0) {
  9444. clean = 0;
  9445. if (v) {
  9446. // outside going in
  9447. stream.lineStart();
  9448. point2 = intersect(point1, point0);
  9449. stream.point(point2[0], point2[1]);
  9450. } else {
  9451. // inside going out
  9452. point2 = intersect(point0, point1);
  9453. stream.point(point2[0], point2[1], 2);
  9454. stream.lineEnd();
  9455. }
  9456. point0 = point2;
  9457. } else if (notHemisphere && point0 && smallRadius ^ v) {
  9458. var t;
  9459. // If the codes for two points are different, or are both zero,
  9460. // and there this segment intersects with the small circle.
  9461. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  9462. clean = 0;
  9463. if (smallRadius) {
  9464. stream.lineStart();
  9465. stream.point(t[0][0], t[0][1]);
  9466. stream.point(t[1][0], t[1][1]);
  9467. stream.lineEnd();
  9468. } else {
  9469. stream.point(t[1][0], t[1][1]);
  9470. stream.lineEnd();
  9471. stream.lineStart();
  9472. stream.point(t[0][0], t[0][1], 3);
  9473. }
  9474. }
  9475. }
  9476. if (v && (!point0 || !pointEqual(point0, point1))) {
  9477. stream.point(point1[0], point1[1]);
  9478. }
  9479. point0 = point1, v0 = v, c0 = c;
  9480. },
  9481. lineEnd: function() {
  9482. if (v0) stream.lineEnd();
  9483. point0 = null;
  9484. },
  9485. // Rejoin first and last segments if there were intersections and the first
  9486. // and last points were visible.
  9487. clean: function() {
  9488. return clean | ((v00 && v0) << 1);
  9489. }
  9490. };
  9491. }
  9492. // Intersects the great circle between a and b with the clip circle.
  9493. function intersect(a, b, two) {
  9494. var pa = cartesian(a),
  9495. pb = cartesian(b);
  9496. // We have two planes, n1.p = d1 and n2.p = d2.
  9497. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  9498. var n1 = [1, 0, 0], // normal
  9499. n2 = cartesianCross(pa, pb),
  9500. n2n2 = cartesianDot(n2, n2),
  9501. n1n2 = n2[0], // cartesianDot(n1, n2),
  9502. determinant = n2n2 - n1n2 * n1n2;
  9503. // Two polar points.
  9504. if (!determinant) return !two && a;
  9505. var c1 = cr * n2n2 / determinant,
  9506. c2 = -cr * n1n2 / determinant,
  9507. n1xn2 = cartesianCross(n1, n2),
  9508. A = cartesianScale(n1, c1),
  9509. B = cartesianScale(n2, c2);
  9510. cartesianAddInPlace(A, B);
  9511. // Solve |p(t)|^2 = 1.
  9512. var u = n1xn2,
  9513. w = cartesianDot(A, u),
  9514. uu = cartesianDot(u, u),
  9515. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  9516. if (t2 < 0) return;
  9517. var t = sqrt$2(t2),
  9518. q = cartesianScale(u, (-w - t) / uu);
  9519. cartesianAddInPlace(q, A);
  9520. q = spherical(q);
  9521. if (!two) return q;
  9522. // Two intersection points.
  9523. var lambda0 = a[0],
  9524. lambda1 = b[0],
  9525. phi0 = a[1],
  9526. phi1 = b[1],
  9527. z;
  9528. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  9529. var delta = lambda1 - lambda0,
  9530. polar = abs$1(delta - pi$1) < epsilon$1,
  9531. meridian = polar || delta < epsilon$1;
  9532. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  9533. // Check that the first point is between a and b.
  9534. if (meridian
  9535. ? polar
  9536. ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
  9537. : phi0 <= q[1] && q[1] <= phi1
  9538. : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  9539. var q1 = cartesianScale(u, (-w + t) / uu);
  9540. cartesianAddInPlace(q1, A);
  9541. return [q, spherical(q1)];
  9542. }
  9543. }
  9544. // Generates a 4-bit vector representing the location of a point relative to
  9545. // the small circle's bounding box.
  9546. function code(lambda, phi) {
  9547. var r = smallRadius ? radius : pi$1 - radius,
  9548. code = 0;
  9549. if (lambda < -r) code |= 1; // left
  9550. else if (lambda > r) code |= 2; // right
  9551. if (phi < -r) code |= 4; // below
  9552. else if (phi > r) code |= 8; // above
  9553. return code;
  9554. }
  9555. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
  9556. }
  9557. function clipLine(a, b, x0, y0, x1, y1) {
  9558. var ax = a[0],
  9559. ay = a[1],
  9560. bx = b[0],
  9561. by = b[1],
  9562. t0 = 0,
  9563. t1 = 1,
  9564. dx = bx - ax,
  9565. dy = by - ay,
  9566. r;
  9567. r = x0 - ax;
  9568. if (!dx && r > 0) return;
  9569. r /= dx;
  9570. if (dx < 0) {
  9571. if (r < t0) return;
  9572. if (r < t1) t1 = r;
  9573. } else if (dx > 0) {
  9574. if (r > t1) return;
  9575. if (r > t0) t0 = r;
  9576. }
  9577. r = x1 - ax;
  9578. if (!dx && r < 0) return;
  9579. r /= dx;
  9580. if (dx < 0) {
  9581. if (r > t1) return;
  9582. if (r > t0) t0 = r;
  9583. } else if (dx > 0) {
  9584. if (r < t0) return;
  9585. if (r < t1) t1 = r;
  9586. }
  9587. r = y0 - ay;
  9588. if (!dy && r > 0) return;
  9589. r /= dy;
  9590. if (dy < 0) {
  9591. if (r < t0) return;
  9592. if (r < t1) t1 = r;
  9593. } else if (dy > 0) {
  9594. if (r > t1) return;
  9595. if (r > t0) t0 = r;
  9596. }
  9597. r = y1 - ay;
  9598. if (!dy && r < 0) return;
  9599. r /= dy;
  9600. if (dy < 0) {
  9601. if (r > t1) return;
  9602. if (r > t0) t0 = r;
  9603. } else if (dy > 0) {
  9604. if (r < t0) return;
  9605. if (r < t1) t1 = r;
  9606. }
  9607. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  9608. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  9609. return true;
  9610. }
  9611. var clipMax = 1e9, clipMin = -clipMax;
  9612. // TODO Use d3-polygon’s polygonContains here for the ring check?
  9613. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  9614. function clipRectangle(x0, y0, x1, y1) {
  9615. function visible(x, y) {
  9616. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  9617. }
  9618. function interpolate(from, to, direction, stream) {
  9619. var a = 0, a1 = 0;
  9620. if (from == null
  9621. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  9622. || comparePoint(from, to) < 0 ^ direction > 0) {
  9623. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  9624. while ((a = (a + direction + 4) % 4) !== a1);
  9625. } else {
  9626. stream.point(to[0], to[1]);
  9627. }
  9628. }
  9629. function corner(p, direction) {
  9630. return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
  9631. : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
  9632. : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
  9633. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  9634. }
  9635. function compareIntersection(a, b) {
  9636. return comparePoint(a.x, b.x);
  9637. }
  9638. function comparePoint(a, b) {
  9639. var ca = corner(a, 1),
  9640. cb = corner(b, 1);
  9641. return ca !== cb ? ca - cb
  9642. : ca === 0 ? b[1] - a[1]
  9643. : ca === 1 ? a[0] - b[0]
  9644. : ca === 2 ? a[1] - b[1]
  9645. : b[0] - a[0];
  9646. }
  9647. return function(stream) {
  9648. var activeStream = stream,
  9649. bufferStream = clipBuffer(),
  9650. segments,
  9651. polygon,
  9652. ring,
  9653. x__, y__, v__, // first point
  9654. x_, y_, v_, // previous point
  9655. first,
  9656. clean;
  9657. var clipStream = {
  9658. point: point,
  9659. lineStart: lineStart,
  9660. lineEnd: lineEnd,
  9661. polygonStart: polygonStart,
  9662. polygonEnd: polygonEnd
  9663. };
  9664. function point(x, y) {
  9665. if (visible(x, y)) activeStream.point(x, y);
  9666. }
  9667. function polygonInside() {
  9668. var winding = 0;
  9669. for (var i = 0, n = polygon.length; i < n; ++i) {
  9670. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  9671. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  9672. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  9673. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  9674. }
  9675. }
  9676. return winding;
  9677. }
  9678. // Buffer geometry within a polygon and then clip it en masse.
  9679. function polygonStart() {
  9680. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  9681. }
  9682. function polygonEnd() {
  9683. var startInside = polygonInside(),
  9684. cleanInside = clean && startInside,
  9685. visible = (segments = merge(segments)).length;
  9686. if (cleanInside || visible) {
  9687. stream.polygonStart();
  9688. if (cleanInside) {
  9689. stream.lineStart();
  9690. interpolate(null, null, 1, stream);
  9691. stream.lineEnd();
  9692. }
  9693. if (visible) {
  9694. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  9695. }
  9696. stream.polygonEnd();
  9697. }
  9698. activeStream = stream, segments = polygon = ring = null;
  9699. }
  9700. function lineStart() {
  9701. clipStream.point = linePoint;
  9702. if (polygon) polygon.push(ring = []);
  9703. first = true;
  9704. v_ = false;
  9705. x_ = y_ = NaN;
  9706. }
  9707. // TODO rather than special-case polygons, simply handle them separately.
  9708. // Ideally, coincident intersection points should be jittered to avoid
  9709. // clipping issues.
  9710. function lineEnd() {
  9711. if (segments) {
  9712. linePoint(x__, y__);
  9713. if (v__ && v_) bufferStream.rejoin();
  9714. segments.push(bufferStream.result());
  9715. }
  9716. clipStream.point = point;
  9717. if (v_) activeStream.lineEnd();
  9718. }
  9719. function linePoint(x, y) {
  9720. var v = visible(x, y);
  9721. if (polygon) ring.push([x, y]);
  9722. if (first) {
  9723. x__ = x, y__ = y, v__ = v;
  9724. first = false;
  9725. if (v) {
  9726. activeStream.lineStart();
  9727. activeStream.point(x, y);
  9728. }
  9729. } else {
  9730. if (v && v_) activeStream.point(x, y);
  9731. else {
  9732. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  9733. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  9734. if (clipLine(a, b, x0, y0, x1, y1)) {
  9735. if (!v_) {
  9736. activeStream.lineStart();
  9737. activeStream.point(a[0], a[1]);
  9738. }
  9739. activeStream.point(b[0], b[1]);
  9740. if (!v) activeStream.lineEnd();
  9741. clean = false;
  9742. } else if (v) {
  9743. activeStream.lineStart();
  9744. activeStream.point(x, y);
  9745. clean = false;
  9746. }
  9747. }
  9748. }
  9749. x_ = x, y_ = y, v_ = v;
  9750. }
  9751. return clipStream;
  9752. };
  9753. }
  9754. function extent() {
  9755. var x0 = 0,
  9756. y0 = 0,
  9757. x1 = 960,
  9758. y1 = 500,
  9759. cache,
  9760. cacheStream,
  9761. clip;
  9762. return clip = {
  9763. stream: function(stream) {
  9764. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  9765. },
  9766. extent: function(_) {
  9767. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  9768. }
  9769. };
  9770. }
  9771. var lengthSum$1,
  9772. lambda0,
  9773. sinPhi0,
  9774. cosPhi0;
  9775. var lengthStream$1 = {
  9776. sphere: noop$1,
  9777. point: noop$1,
  9778. lineStart: lengthLineStart,
  9779. lineEnd: noop$1,
  9780. polygonStart: noop$1,
  9781. polygonEnd: noop$1
  9782. };
  9783. function lengthLineStart() {
  9784. lengthStream$1.point = lengthPointFirst$1;
  9785. lengthStream$1.lineEnd = lengthLineEnd;
  9786. }
  9787. function lengthLineEnd() {
  9788. lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
  9789. }
  9790. function lengthPointFirst$1(lambda, phi) {
  9791. lambda *= radians, phi *= radians;
  9792. lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
  9793. lengthStream$1.point = lengthPoint$1;
  9794. }
  9795. function lengthPoint$1(lambda, phi) {
  9796. lambda *= radians, phi *= radians;
  9797. var sinPhi = sin$1(phi),
  9798. cosPhi = cos$1(phi),
  9799. delta = abs$1(lambda - lambda0),
  9800. cosDelta = cos$1(delta),
  9801. sinDelta = sin$1(delta),
  9802. x = cosPhi * sinDelta,
  9803. y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
  9804. z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
  9805. lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
  9806. lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
  9807. }
  9808. function length$1(object) {
  9809. lengthSum$1 = new Adder();
  9810. geoStream(object, lengthStream$1);
  9811. return +lengthSum$1;
  9812. }
  9813. var coordinates = [null, null],
  9814. object = {type: "LineString", coordinates: coordinates};
  9815. function distance(a, b) {
  9816. coordinates[0] = a;
  9817. coordinates[1] = b;
  9818. return length$1(object);
  9819. }
  9820. var containsObjectType = {
  9821. Feature: function(object, point) {
  9822. return containsGeometry(object.geometry, point);
  9823. },
  9824. FeatureCollection: function(object, point) {
  9825. var features = object.features, i = -1, n = features.length;
  9826. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  9827. return false;
  9828. }
  9829. };
  9830. var containsGeometryType = {
  9831. Sphere: function() {
  9832. return true;
  9833. },
  9834. Point: function(object, point) {
  9835. return containsPoint(object.coordinates, point);
  9836. },
  9837. MultiPoint: function(object, point) {
  9838. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9839. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  9840. return false;
  9841. },
  9842. LineString: function(object, point) {
  9843. return containsLine(object.coordinates, point);
  9844. },
  9845. MultiLineString: function(object, point) {
  9846. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9847. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  9848. return false;
  9849. },
  9850. Polygon: function(object, point) {
  9851. return containsPolygon(object.coordinates, point);
  9852. },
  9853. MultiPolygon: function(object, point) {
  9854. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9855. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  9856. return false;
  9857. },
  9858. GeometryCollection: function(object, point) {
  9859. var geometries = object.geometries, i = -1, n = geometries.length;
  9860. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  9861. return false;
  9862. }
  9863. };
  9864. function containsGeometry(geometry, point) {
  9865. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  9866. ? containsGeometryType[geometry.type](geometry, point)
  9867. : false;
  9868. }
  9869. function containsPoint(coordinates, point) {
  9870. return distance(coordinates, point) === 0;
  9871. }
  9872. function containsLine(coordinates, point) {
  9873. var ao, bo, ab;
  9874. for (var i = 0, n = coordinates.length; i < n; i++) {
  9875. bo = distance(coordinates[i], point);
  9876. if (bo === 0) return true;
  9877. if (i > 0) {
  9878. ab = distance(coordinates[i], coordinates[i - 1]);
  9879. if (
  9880. ab > 0 &&
  9881. ao <= ab &&
  9882. bo <= ab &&
  9883. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
  9884. )
  9885. return true;
  9886. }
  9887. ao = bo;
  9888. }
  9889. return false;
  9890. }
  9891. function containsPolygon(coordinates, point) {
  9892. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  9893. }
  9894. function ringRadians(ring) {
  9895. return ring = ring.map(pointRadians), ring.pop(), ring;
  9896. }
  9897. function pointRadians(point) {
  9898. return [point[0] * radians, point[1] * radians];
  9899. }
  9900. function contains$1(object, point) {
  9901. return (object && containsObjectType.hasOwnProperty(object.type)
  9902. ? containsObjectType[object.type]
  9903. : containsGeometry)(object, point);
  9904. }
  9905. function graticuleX(y0, y1, dy) {
  9906. var y = range$2(y0, y1 - epsilon$1, dy).concat(y1);
  9907. return function(x) { return y.map(function(y) { return [x, y]; }); };
  9908. }
  9909. function graticuleY(x0, x1, dx) {
  9910. var x = range$2(x0, x1 - epsilon$1, dx).concat(x1);
  9911. return function(y) { return x.map(function(x) { return [x, y]; }); };
  9912. }
  9913. function graticule() {
  9914. var x1, x0, X1, X0,
  9915. y1, y0, Y1, Y0,
  9916. dx = 10, dy = dx, DX = 90, DY = 360,
  9917. x, y, X, Y,
  9918. precision = 2.5;
  9919. function graticule() {
  9920. return {type: "MultiLineString", coordinates: lines()};
  9921. }
  9922. function lines() {
  9923. return range$2(ceil(X0 / DX) * DX, X1, DX).map(X)
  9924. .concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  9925. .concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
  9926. .concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
  9927. }
  9928. graticule.lines = function() {
  9929. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  9930. };
  9931. graticule.outline = function() {
  9932. return {
  9933. type: "Polygon",
  9934. coordinates: [
  9935. X(X0).concat(
  9936. Y(Y1).slice(1),
  9937. X(X1).reverse().slice(1),
  9938. Y(Y0).reverse().slice(1))
  9939. ]
  9940. };
  9941. };
  9942. graticule.extent = function(_) {
  9943. if (!arguments.length) return graticule.extentMinor();
  9944. return graticule.extentMajor(_).extentMinor(_);
  9945. };
  9946. graticule.extentMajor = function(_) {
  9947. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  9948. X0 = +_[0][0], X1 = +_[1][0];
  9949. Y0 = +_[0][1], Y1 = +_[1][1];
  9950. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  9951. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  9952. return graticule.precision(precision);
  9953. };
  9954. graticule.extentMinor = function(_) {
  9955. if (!arguments.length) return [[x0, y0], [x1, y1]];
  9956. x0 = +_[0][0], x1 = +_[1][0];
  9957. y0 = +_[0][1], y1 = +_[1][1];
  9958. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  9959. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  9960. return graticule.precision(precision);
  9961. };
  9962. graticule.step = function(_) {
  9963. if (!arguments.length) return graticule.stepMinor();
  9964. return graticule.stepMajor(_).stepMinor(_);
  9965. };
  9966. graticule.stepMajor = function(_) {
  9967. if (!arguments.length) return [DX, DY];
  9968. DX = +_[0], DY = +_[1];
  9969. return graticule;
  9970. };
  9971. graticule.stepMinor = function(_) {
  9972. if (!arguments.length) return [dx, dy];
  9973. dx = +_[0], dy = +_[1];
  9974. return graticule;
  9975. };
  9976. graticule.precision = function(_) {
  9977. if (!arguments.length) return precision;
  9978. precision = +_;
  9979. x = graticuleX(y0, y1, 90);
  9980. y = graticuleY(x0, x1, precision);
  9981. X = graticuleX(Y0, Y1, 90);
  9982. Y = graticuleY(X0, X1, precision);
  9983. return graticule;
  9984. };
  9985. return graticule
  9986. .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
  9987. .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
  9988. }
  9989. function graticule10() {
  9990. return graticule()();
  9991. }
  9992. function interpolate(a, b) {
  9993. var x0 = a[0] * radians,
  9994. y0 = a[1] * radians,
  9995. x1 = b[0] * radians,
  9996. y1 = b[1] * radians,
  9997. cy0 = cos$1(y0),
  9998. sy0 = sin$1(y0),
  9999. cy1 = cos$1(y1),
  10000. sy1 = sin$1(y1),
  10001. kx0 = cy0 * cos$1(x0),
  10002. ky0 = cy0 * sin$1(x0),
  10003. kx1 = cy1 * cos$1(x1),
  10004. ky1 = cy1 * sin$1(x1),
  10005. d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  10006. k = sin$1(d);
  10007. var interpolate = d ? function(t) {
  10008. var B = sin$1(t *= d) / k,
  10009. A = sin$1(d - t) / k,
  10010. x = A * kx0 + B * kx1,
  10011. y = A * ky0 + B * ky1,
  10012. z = A * sy0 + B * sy1;
  10013. return [
  10014. atan2$1(y, x) * degrees,
  10015. atan2$1(z, sqrt$2(x * x + y * y)) * degrees
  10016. ];
  10017. } : function() {
  10018. return [x0 * degrees, y0 * degrees];
  10019. };
  10020. interpolate.distance = d;
  10021. return interpolate;
  10022. }
  10023. var identity$5 = x => x;
  10024. var areaSum = new Adder(),
  10025. areaRingSum = new Adder(),
  10026. x00$2,
  10027. y00$2,
  10028. x0$3,
  10029. y0$3;
  10030. var areaStream = {
  10031. point: noop$1,
  10032. lineStart: noop$1,
  10033. lineEnd: noop$1,
  10034. polygonStart: function() {
  10035. areaStream.lineStart = areaRingStart;
  10036. areaStream.lineEnd = areaRingEnd;
  10037. },
  10038. polygonEnd: function() {
  10039. areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
  10040. areaSum.add(abs$1(areaRingSum));
  10041. areaRingSum = new Adder();
  10042. },
  10043. result: function() {
  10044. var area = areaSum / 2;
  10045. areaSum = new Adder();
  10046. return area;
  10047. }
  10048. };
  10049. function areaRingStart() {
  10050. areaStream.point = areaPointFirst;
  10051. }
  10052. function areaPointFirst(x, y) {
  10053. areaStream.point = areaPoint;
  10054. x00$2 = x0$3 = x, y00$2 = y0$3 = y;
  10055. }
  10056. function areaPoint(x, y) {
  10057. areaRingSum.add(y0$3 * x - x0$3 * y);
  10058. x0$3 = x, y0$3 = y;
  10059. }
  10060. function areaRingEnd() {
  10061. areaPoint(x00$2, y00$2);
  10062. }
  10063. var pathArea = areaStream;
  10064. var x0$2 = Infinity,
  10065. y0$2 = x0$2,
  10066. x1 = -x0$2,
  10067. y1 = x1;
  10068. var boundsStream = {
  10069. point: boundsPoint,
  10070. lineStart: noop$1,
  10071. lineEnd: noop$1,
  10072. polygonStart: noop$1,
  10073. polygonEnd: noop$1,
  10074. result: function() {
  10075. var bounds = [[x0$2, y0$2], [x1, y1]];
  10076. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  10077. return bounds;
  10078. }
  10079. };
  10080. function boundsPoint(x, y) {
  10081. if (x < x0$2) x0$2 = x;
  10082. if (x > x1) x1 = x;
  10083. if (y < y0$2) y0$2 = y;
  10084. if (y > y1) y1 = y;
  10085. }
  10086. var boundsStream$1 = boundsStream;
  10087. // TODO Enforce positive area for exterior, negative area for interior?
  10088. var X0 = 0,
  10089. Y0 = 0,
  10090. Z0 = 0,
  10091. X1 = 0,
  10092. Y1 = 0,
  10093. Z1 = 0,
  10094. X2 = 0,
  10095. Y2 = 0,
  10096. Z2 = 0,
  10097. x00$1,
  10098. y00$1,
  10099. x0$1,
  10100. y0$1;
  10101. var centroidStream = {
  10102. point: centroidPoint,
  10103. lineStart: centroidLineStart,
  10104. lineEnd: centroidLineEnd,
  10105. polygonStart: function() {
  10106. centroidStream.lineStart = centroidRingStart;
  10107. centroidStream.lineEnd = centroidRingEnd;
  10108. },
  10109. polygonEnd: function() {
  10110. centroidStream.point = centroidPoint;
  10111. centroidStream.lineStart = centroidLineStart;
  10112. centroidStream.lineEnd = centroidLineEnd;
  10113. },
  10114. result: function() {
  10115. var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
  10116. : Z1 ? [X1 / Z1, Y1 / Z1]
  10117. : Z0 ? [X0 / Z0, Y0 / Z0]
  10118. : [NaN, NaN];
  10119. X0 = Y0 = Z0 =
  10120. X1 = Y1 = Z1 =
  10121. X2 = Y2 = Z2 = 0;
  10122. return centroid;
  10123. }
  10124. };
  10125. function centroidPoint(x, y) {
  10126. X0 += x;
  10127. Y0 += y;
  10128. ++Z0;
  10129. }
  10130. function centroidLineStart() {
  10131. centroidStream.point = centroidPointFirstLine;
  10132. }
  10133. function centroidPointFirstLine(x, y) {
  10134. centroidStream.point = centroidPointLine;
  10135. centroidPoint(x0$1 = x, y0$1 = y);
  10136. }
  10137. function centroidPointLine(x, y) {
  10138. var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
  10139. X1 += z * (x0$1 + x) / 2;
  10140. Y1 += z * (y0$1 + y) / 2;
  10141. Z1 += z;
  10142. centroidPoint(x0$1 = x, y0$1 = y);
  10143. }
  10144. function centroidLineEnd() {
  10145. centroidStream.point = centroidPoint;
  10146. }
  10147. function centroidRingStart() {
  10148. centroidStream.point = centroidPointFirstRing;
  10149. }
  10150. function centroidRingEnd() {
  10151. centroidPointRing(x00$1, y00$1);
  10152. }
  10153. function centroidPointFirstRing(x, y) {
  10154. centroidStream.point = centroidPointRing;
  10155. centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
  10156. }
  10157. function centroidPointRing(x, y) {
  10158. var dx = x - x0$1,
  10159. dy = y - y0$1,
  10160. z = sqrt$2(dx * dx + dy * dy);
  10161. X1 += z * (x0$1 + x) / 2;
  10162. Y1 += z * (y0$1 + y) / 2;
  10163. Z1 += z;
  10164. z = y0$1 * x - x0$1 * y;
  10165. X2 += z * (x0$1 + x);
  10166. Y2 += z * (y0$1 + y);
  10167. Z2 += z * 3;
  10168. centroidPoint(x0$1 = x, y0$1 = y);
  10169. }
  10170. var pathCentroid = centroidStream;
  10171. function PathContext(context) {
  10172. this._context = context;
  10173. }
  10174. PathContext.prototype = {
  10175. _radius: 4.5,
  10176. pointRadius: function(_) {
  10177. return this._radius = _, this;
  10178. },
  10179. polygonStart: function() {
  10180. this._line = 0;
  10181. },
  10182. polygonEnd: function() {
  10183. this._line = NaN;
  10184. },
  10185. lineStart: function() {
  10186. this._point = 0;
  10187. },
  10188. lineEnd: function() {
  10189. if (this._line === 0) this._context.closePath();
  10190. this._point = NaN;
  10191. },
  10192. point: function(x, y) {
  10193. switch (this._point) {
  10194. case 0: {
  10195. this._context.moveTo(x, y);
  10196. this._point = 1;
  10197. break;
  10198. }
  10199. case 1: {
  10200. this._context.lineTo(x, y);
  10201. break;
  10202. }
  10203. default: {
  10204. this._context.moveTo(x + this._radius, y);
  10205. this._context.arc(x, y, this._radius, 0, tau$1);
  10206. break;
  10207. }
  10208. }
  10209. },
  10210. result: noop$1
  10211. };
  10212. var lengthSum = new Adder(),
  10213. lengthRing,
  10214. x00,
  10215. y00,
  10216. x0,
  10217. y0;
  10218. var lengthStream = {
  10219. point: noop$1,
  10220. lineStart: function() {
  10221. lengthStream.point = lengthPointFirst;
  10222. },
  10223. lineEnd: function() {
  10224. if (lengthRing) lengthPoint(x00, y00);
  10225. lengthStream.point = noop$1;
  10226. },
  10227. polygonStart: function() {
  10228. lengthRing = true;
  10229. },
  10230. polygonEnd: function() {
  10231. lengthRing = null;
  10232. },
  10233. result: function() {
  10234. var length = +lengthSum;
  10235. lengthSum = new Adder();
  10236. return length;
  10237. }
  10238. };
  10239. function lengthPointFirst(x, y) {
  10240. lengthStream.point = lengthPoint;
  10241. x00 = x0 = x, y00 = y0 = y;
  10242. }
  10243. function lengthPoint(x, y) {
  10244. x0 -= x, y0 -= y;
  10245. lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
  10246. x0 = x, y0 = y;
  10247. }
  10248. var pathMeasure = lengthStream;
  10249. // Simple caching for constant-radius points.
  10250. let cacheDigits, cacheAppend, cacheRadius, cacheCircle;
  10251. class PathString {
  10252. constructor(digits) {
  10253. this._append = digits == null ? append : appendRound(digits);
  10254. this._radius = 4.5;
  10255. this._ = "";
  10256. }
  10257. pointRadius(_) {
  10258. this._radius = +_;
  10259. return this;
  10260. }
  10261. polygonStart() {
  10262. this._line = 0;
  10263. }
  10264. polygonEnd() {
  10265. this._line = NaN;
  10266. }
  10267. lineStart() {
  10268. this._point = 0;
  10269. }
  10270. lineEnd() {
  10271. if (this._line === 0) this._ += "Z";
  10272. this._point = NaN;
  10273. }
  10274. point(x, y) {
  10275. switch (this._point) {
  10276. case 0: {
  10277. this._append`M${x},${y}`;
  10278. this._point = 1;
  10279. break;
  10280. }
  10281. case 1: {
  10282. this._append`L${x},${y}`;
  10283. break;
  10284. }
  10285. default: {
  10286. this._append`M${x},${y}`;
  10287. if (this._radius !== cacheRadius || this._append !== cacheAppend) {
  10288. const r = this._radius;
  10289. const s = this._;
  10290. this._ = ""; // stash the old string so we can cache the circle path fragment
  10291. this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`;
  10292. cacheRadius = r;
  10293. cacheAppend = this._append;
  10294. cacheCircle = this._;
  10295. this._ = s;
  10296. }
  10297. this._ += cacheCircle;
  10298. break;
  10299. }
  10300. }
  10301. }
  10302. result() {
  10303. const result = this._;
  10304. this._ = "";
  10305. return result.length ? result : null;
  10306. }
  10307. }
  10308. function append(strings) {
  10309. let i = 1;
  10310. this._ += strings[0];
  10311. for (const j = strings.length; i < j; ++i) {
  10312. this._ += arguments[i] + strings[i];
  10313. }
  10314. }
  10315. function appendRound(digits) {
  10316. const d = Math.floor(digits);
  10317. if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`);
  10318. if (d > 15) return append;
  10319. if (d !== cacheDigits) {
  10320. const k = 10 ** d;
  10321. cacheDigits = d;
  10322. cacheAppend = function append(strings) {
  10323. let i = 1;
  10324. this._ += strings[0];
  10325. for (const j = strings.length; i < j; ++i) {
  10326. this._ += Math.round(arguments[i] * k) / k + strings[i];
  10327. }
  10328. };
  10329. }
  10330. return cacheAppend;
  10331. }
  10332. function index$2(projection, context) {
  10333. let digits = 3,
  10334. pointRadius = 4.5,
  10335. projectionStream,
  10336. contextStream;
  10337. function path(object) {
  10338. if (object) {
  10339. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  10340. geoStream(object, projectionStream(contextStream));
  10341. }
  10342. return contextStream.result();
  10343. }
  10344. path.area = function(object) {
  10345. geoStream(object, projectionStream(pathArea));
  10346. return pathArea.result();
  10347. };
  10348. path.measure = function(object) {
  10349. geoStream(object, projectionStream(pathMeasure));
  10350. return pathMeasure.result();
  10351. };
  10352. path.bounds = function(object) {
  10353. geoStream(object, projectionStream(boundsStream$1));
  10354. return boundsStream$1.result();
  10355. };
  10356. path.centroid = function(object) {
  10357. geoStream(object, projectionStream(pathCentroid));
  10358. return pathCentroid.result();
  10359. };
  10360. path.projection = function(_) {
  10361. if (!arguments.length) return projection;
  10362. projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream;
  10363. return path;
  10364. };
  10365. path.context = function(_) {
  10366. if (!arguments.length) return context;
  10367. contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
  10368. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  10369. return path;
  10370. };
  10371. path.pointRadius = function(_) {
  10372. if (!arguments.length) return pointRadius;
  10373. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  10374. return path;
  10375. };
  10376. path.digits = function(_) {
  10377. if (!arguments.length) return digits;
  10378. if (_ == null) digits = null;
  10379. else {
  10380. const d = Math.floor(_);
  10381. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  10382. digits = d;
  10383. }
  10384. if (context === null) contextStream = new PathString(digits);
  10385. return path;
  10386. };
  10387. return path.projection(projection).digits(digits).context(context);
  10388. }
  10389. function transform$1(methods) {
  10390. return {
  10391. stream: transformer$3(methods)
  10392. };
  10393. }
  10394. function transformer$3(methods) {
  10395. return function(stream) {
  10396. var s = new TransformStream;
  10397. for (var key in methods) s[key] = methods[key];
  10398. s.stream = stream;
  10399. return s;
  10400. };
  10401. }
  10402. function TransformStream() {}
  10403. TransformStream.prototype = {
  10404. constructor: TransformStream,
  10405. point: function(x, y) { this.stream.point(x, y); },
  10406. sphere: function() { this.stream.sphere(); },
  10407. lineStart: function() { this.stream.lineStart(); },
  10408. lineEnd: function() { this.stream.lineEnd(); },
  10409. polygonStart: function() { this.stream.polygonStart(); },
  10410. polygonEnd: function() { this.stream.polygonEnd(); }
  10411. };
  10412. function fit(projection, fitBounds, object) {
  10413. var clip = projection.clipExtent && projection.clipExtent();
  10414. projection.scale(150).translate([0, 0]);
  10415. if (clip != null) projection.clipExtent(null);
  10416. geoStream(object, projection.stream(boundsStream$1));
  10417. fitBounds(boundsStream$1.result());
  10418. if (clip != null) projection.clipExtent(clip);
  10419. return projection;
  10420. }
  10421. function fitExtent(projection, extent, object) {
  10422. return fit(projection, function(b) {
  10423. var w = extent[1][0] - extent[0][0],
  10424. h = extent[1][1] - extent[0][1],
  10425. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  10426. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  10427. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  10428. projection.scale(150 * k).translate([x, y]);
  10429. }, object);
  10430. }
  10431. function fitSize(projection, size, object) {
  10432. return fitExtent(projection, [[0, 0], size], object);
  10433. }
  10434. function fitWidth(projection, width, object) {
  10435. return fit(projection, function(b) {
  10436. var w = +width,
  10437. k = w / (b[1][0] - b[0][0]),
  10438. x = (w - k * (b[1][0] + b[0][0])) / 2,
  10439. y = -k * b[0][1];
  10440. projection.scale(150 * k).translate([x, y]);
  10441. }, object);
  10442. }
  10443. function fitHeight(projection, height, object) {
  10444. return fit(projection, function(b) {
  10445. var h = +height,
  10446. k = h / (b[1][1] - b[0][1]),
  10447. x = -k * b[0][0],
  10448. y = (h - k * (b[1][1] + b[0][1])) / 2;
  10449. projection.scale(150 * k).translate([x, y]);
  10450. }, object);
  10451. }
  10452. var maxDepth = 16, // maximum depth of subdivision
  10453. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  10454. function resample(project, delta2) {
  10455. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  10456. }
  10457. function resampleNone(project) {
  10458. return transformer$3({
  10459. point: function(x, y) {
  10460. x = project(x, y);
  10461. this.stream.point(x[0], x[1]);
  10462. }
  10463. });
  10464. }
  10465. function resample$1(project, delta2) {
  10466. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  10467. var dx = x1 - x0,
  10468. dy = y1 - y0,
  10469. d2 = dx * dx + dy * dy;
  10470. if (d2 > 4 * delta2 && depth--) {
  10471. var a = a0 + a1,
  10472. b = b0 + b1,
  10473. c = c0 + c1,
  10474. m = sqrt$2(a * a + b * b + c * c),
  10475. phi2 = asin$1(c /= m),
  10476. lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
  10477. p = project(lambda2, phi2),
  10478. x2 = p[0],
  10479. y2 = p[1],
  10480. dx2 = x2 - x0,
  10481. dy2 = y2 - y0,
  10482. dz = dy * dx2 - dx * dy2;
  10483. if (dz * dz / d2 > delta2 // perpendicular projected distance
  10484. || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  10485. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  10486. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  10487. stream.point(x2, y2);
  10488. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  10489. }
  10490. }
  10491. }
  10492. return function(stream) {
  10493. var lambda00, x00, y00, a00, b00, c00, // first point
  10494. lambda0, x0, y0, a0, b0, c0; // previous point
  10495. var resampleStream = {
  10496. point: point,
  10497. lineStart: lineStart,
  10498. lineEnd: lineEnd,
  10499. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  10500. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  10501. };
  10502. function point(x, y) {
  10503. x = project(x, y);
  10504. stream.point(x[0], x[1]);
  10505. }
  10506. function lineStart() {
  10507. x0 = NaN;
  10508. resampleStream.point = linePoint;
  10509. stream.lineStart();
  10510. }
  10511. function linePoint(lambda, phi) {
  10512. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  10513. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
  10514. stream.point(x0, y0);
  10515. }
  10516. function lineEnd() {
  10517. resampleStream.point = point;
  10518. stream.lineEnd();
  10519. }
  10520. function ringStart() {
  10521. lineStart();
  10522. resampleStream.point = ringPoint;
  10523. resampleStream.lineEnd = ringEnd;
  10524. }
  10525. function ringPoint(lambda, phi) {
  10526. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  10527. resampleStream.point = linePoint;
  10528. }
  10529. function ringEnd() {
  10530. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  10531. resampleStream.lineEnd = lineEnd;
  10532. lineEnd();
  10533. }
  10534. return resampleStream;
  10535. };
  10536. }
  10537. var transformRadians = transformer$3({
  10538. point: function(x, y) {
  10539. this.stream.point(x * radians, y * radians);
  10540. }
  10541. });
  10542. function transformRotate(rotate) {
  10543. return transformer$3({
  10544. point: function(x, y) {
  10545. var r = rotate(x, y);
  10546. return this.stream.point(r[0], r[1]);
  10547. }
  10548. });
  10549. }
  10550. function scaleTranslate(k, dx, dy, sx, sy) {
  10551. function transform(x, y) {
  10552. x *= sx; y *= sy;
  10553. return [dx + k * x, dy - k * y];
  10554. }
  10555. transform.invert = function(x, y) {
  10556. return [(x - dx) / k * sx, (dy - y) / k * sy];
  10557. };
  10558. return transform;
  10559. }
  10560. function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
  10561. if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
  10562. var cosAlpha = cos$1(alpha),
  10563. sinAlpha = sin$1(alpha),
  10564. a = cosAlpha * k,
  10565. b = sinAlpha * k,
  10566. ai = cosAlpha / k,
  10567. bi = sinAlpha / k,
  10568. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  10569. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  10570. function transform(x, y) {
  10571. x *= sx; y *= sy;
  10572. return [a * x - b * y + dx, dy - b * x - a * y];
  10573. }
  10574. transform.invert = function(x, y) {
  10575. return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
  10576. };
  10577. return transform;
  10578. }
  10579. function projection(project) {
  10580. return projectionMutator(function() { return project; })();
  10581. }
  10582. function projectionMutator(projectAt) {
  10583. var project,
  10584. k = 150, // scale
  10585. x = 480, y = 250, // translate
  10586. lambda = 0, phi = 0, // center
  10587. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  10588. alpha = 0, // post-rotate angle
  10589. sx = 1, // reflectX
  10590. sy = 1, // reflectX
  10591. theta = null, preclip = clipAntimeridian, // pre-clip angle
  10592. x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
  10593. delta2 = 0.5, // precision
  10594. projectResample,
  10595. projectTransform,
  10596. projectRotateTransform,
  10597. cache,
  10598. cacheStream;
  10599. function projection(point) {
  10600. return projectRotateTransform(point[0] * radians, point[1] * radians);
  10601. }
  10602. function invert(point) {
  10603. point = projectRotateTransform.invert(point[0], point[1]);
  10604. return point && [point[0] * degrees, point[1] * degrees];
  10605. }
  10606. projection.stream = function(stream) {
  10607. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  10608. };
  10609. projection.preclip = function(_) {
  10610. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  10611. };
  10612. projection.postclip = function(_) {
  10613. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  10614. };
  10615. projection.clipAngle = function(_) {
  10616. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
  10617. };
  10618. projection.clipExtent = function(_) {
  10619. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  10620. };
  10621. projection.scale = function(_) {
  10622. return arguments.length ? (k = +_, recenter()) : k;
  10623. };
  10624. projection.translate = function(_) {
  10625. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  10626. };
  10627. projection.center = function(_) {
  10628. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
  10629. };
  10630. projection.rotate = function(_) {
  10631. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
  10632. };
  10633. projection.angle = function(_) {
  10634. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
  10635. };
  10636. projection.reflectX = function(_) {
  10637. return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
  10638. };
  10639. projection.reflectY = function(_) {
  10640. return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
  10641. };
  10642. projection.precision = function(_) {
  10643. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
  10644. };
  10645. projection.fitExtent = function(extent, object) {
  10646. return fitExtent(projection, extent, object);
  10647. };
  10648. projection.fitSize = function(size, object) {
  10649. return fitSize(projection, size, object);
  10650. };
  10651. projection.fitWidth = function(width, object) {
  10652. return fitWidth(projection, width, object);
  10653. };
  10654. projection.fitHeight = function(height, object) {
  10655. return fitHeight(projection, height, object);
  10656. };
  10657. function recenter() {
  10658. var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
  10659. transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
  10660. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  10661. projectTransform = compose(project, transform);
  10662. projectRotateTransform = compose(rotate, projectTransform);
  10663. projectResample = resample(projectTransform, delta2);
  10664. return reset();
  10665. }
  10666. function reset() {
  10667. cache = cacheStream = null;
  10668. return projection;
  10669. }
  10670. return function() {
  10671. project = projectAt.apply(this, arguments);
  10672. projection.invert = project.invert && invert;
  10673. return recenter();
  10674. };
  10675. }
  10676. function conicProjection(projectAt) {
  10677. var phi0 = 0,
  10678. phi1 = pi$1 / 3,
  10679. m = projectionMutator(projectAt),
  10680. p = m(phi0, phi1);
  10681. p.parallels = function(_) {
  10682. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
  10683. };
  10684. return p;
  10685. }
  10686. function cylindricalEqualAreaRaw(phi0) {
  10687. var cosPhi0 = cos$1(phi0);
  10688. function forward(lambda, phi) {
  10689. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  10690. }
  10691. forward.invert = function(x, y) {
  10692. return [x / cosPhi0, asin$1(y * cosPhi0)];
  10693. };
  10694. return forward;
  10695. }
  10696. function conicEqualAreaRaw(y0, y1) {
  10697. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  10698. // Are the parallels symmetrical around the Equator?
  10699. if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
  10700. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
  10701. function project(x, y) {
  10702. var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
  10703. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  10704. }
  10705. project.invert = function(x, y) {
  10706. var r0y = r0 - y,
  10707. l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
  10708. if (r0y * n < 0)
  10709. l -= pi$1 * sign$1(x) * sign$1(r0y);
  10710. return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  10711. };
  10712. return project;
  10713. }
  10714. function conicEqualArea() {
  10715. return conicProjection(conicEqualAreaRaw)
  10716. .scale(155.424)
  10717. .center([0, 33.6442]);
  10718. }
  10719. function albers() {
  10720. return conicEqualArea()
  10721. .parallels([29.5, 45.5])
  10722. .scale(1070)
  10723. .translate([480, 250])
  10724. .rotate([96, 0])
  10725. .center([-0.6, 38.7]);
  10726. }
  10727. // The projections must have mutually exclusive clip regions on the sphere,
  10728. // as this will avoid emitting interleaving lines and polygons.
  10729. function multiplex(streams) {
  10730. var n = streams.length;
  10731. return {
  10732. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  10733. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  10734. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  10735. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  10736. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  10737. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  10738. };
  10739. }
  10740. // A composite projection for the United States, configured by default for
  10741. // 960×500. The projection also works quite well at 960×600 if you change the
  10742. // scale to 1285 and adjust the translate accordingly. The set of standard
  10743. // parallels for each region comes from USGS, which is published here:
  10744. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  10745. function albersUsa() {
  10746. var cache,
  10747. cacheStream,
  10748. lower48 = albers(), lower48Point,
  10749. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  10750. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  10751. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  10752. function albersUsa(coordinates) {
  10753. var x = coordinates[0], y = coordinates[1];
  10754. return point = null,
  10755. (lower48Point.point(x, y), point)
  10756. || (alaskaPoint.point(x, y), point)
  10757. || (hawaiiPoint.point(x, y), point);
  10758. }
  10759. albersUsa.invert = function(coordinates) {
  10760. var k = lower48.scale(),
  10761. t = lower48.translate(),
  10762. x = (coordinates[0] - t[0]) / k,
  10763. y = (coordinates[1] - t[1]) / k;
  10764. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  10765. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  10766. : lower48).invert(coordinates);
  10767. };
  10768. albersUsa.stream = function(stream) {
  10769. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  10770. };
  10771. albersUsa.precision = function(_) {
  10772. if (!arguments.length) return lower48.precision();
  10773. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  10774. return reset();
  10775. };
  10776. albersUsa.scale = function(_) {
  10777. if (!arguments.length) return lower48.scale();
  10778. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  10779. return albersUsa.translate(lower48.translate());
  10780. };
  10781. albersUsa.translate = function(_) {
  10782. if (!arguments.length) return lower48.translate();
  10783. var k = lower48.scale(), x = +_[0], y = +_[1];
  10784. lower48Point = lower48
  10785. .translate(_)
  10786. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  10787. .stream(pointStream);
  10788. alaskaPoint = alaska
  10789. .translate([x - 0.307 * k, y + 0.201 * k])
  10790. .clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10791. .stream(pointStream);
  10792. hawaiiPoint = hawaii
  10793. .translate([x - 0.205 * k, y + 0.212 * k])
  10794. .clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10795. .stream(pointStream);
  10796. return reset();
  10797. };
  10798. albersUsa.fitExtent = function(extent, object) {
  10799. return fitExtent(albersUsa, extent, object);
  10800. };
  10801. albersUsa.fitSize = function(size, object) {
  10802. return fitSize(albersUsa, size, object);
  10803. };
  10804. albersUsa.fitWidth = function(width, object) {
  10805. return fitWidth(albersUsa, width, object);
  10806. };
  10807. albersUsa.fitHeight = function(height, object) {
  10808. return fitHeight(albersUsa, height, object);
  10809. };
  10810. function reset() {
  10811. cache = cacheStream = null;
  10812. return albersUsa;
  10813. }
  10814. return albersUsa.scale(1070);
  10815. }
  10816. function azimuthalRaw(scale) {
  10817. return function(x, y) {
  10818. var cx = cos$1(x),
  10819. cy = cos$1(y),
  10820. k = scale(cx * cy);
  10821. if (k === Infinity) return [2, 0];
  10822. return [
  10823. k * cy * sin$1(x),
  10824. k * sin$1(y)
  10825. ];
  10826. }
  10827. }
  10828. function azimuthalInvert(angle) {
  10829. return function(x, y) {
  10830. var z = sqrt$2(x * x + y * y),
  10831. c = angle(z),
  10832. sc = sin$1(c),
  10833. cc = cos$1(c);
  10834. return [
  10835. atan2$1(x * sc, z * cc),
  10836. asin$1(z && y * sc / z)
  10837. ];
  10838. }
  10839. }
  10840. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  10841. return sqrt$2(2 / (1 + cxcy));
  10842. });
  10843. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  10844. return 2 * asin$1(z / 2);
  10845. });
  10846. function azimuthalEqualArea() {
  10847. return projection(azimuthalEqualAreaRaw)
  10848. .scale(124.75)
  10849. .clipAngle(180 - 1e-3);
  10850. }
  10851. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  10852. return (c = acos$1(c)) && c / sin$1(c);
  10853. });
  10854. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  10855. return z;
  10856. });
  10857. function azimuthalEquidistant() {
  10858. return projection(azimuthalEquidistantRaw)
  10859. .scale(79.4188)
  10860. .clipAngle(180 - 1e-3);
  10861. }
  10862. function mercatorRaw(lambda, phi) {
  10863. return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
  10864. }
  10865. mercatorRaw.invert = function(x, y) {
  10866. return [x, 2 * atan(exp(y)) - halfPi$1];
  10867. };
  10868. function mercator() {
  10869. return mercatorProjection(mercatorRaw)
  10870. .scale(961 / tau$1);
  10871. }
  10872. function mercatorProjection(project) {
  10873. var m = projection(project),
  10874. center = m.center,
  10875. scale = m.scale,
  10876. translate = m.translate,
  10877. clipExtent = m.clipExtent,
  10878. x0 = null, y0, x1, y1; // clip extent
  10879. m.scale = function(_) {
  10880. return arguments.length ? (scale(_), reclip()) : scale();
  10881. };
  10882. m.translate = function(_) {
  10883. return arguments.length ? (translate(_), reclip()) : translate();
  10884. };
  10885. m.center = function(_) {
  10886. return arguments.length ? (center(_), reclip()) : center();
  10887. };
  10888. m.clipExtent = function(_) {
  10889. return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  10890. };
  10891. function reclip() {
  10892. var k = pi$1 * scale(),
  10893. t = m(rotation(m.rotate()).invert([0, 0]));
  10894. return clipExtent(x0 == null
  10895. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  10896. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  10897. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  10898. }
  10899. return reclip();
  10900. }
  10901. function tany(y) {
  10902. return tan((halfPi$1 + y) / 2);
  10903. }
  10904. function conicConformalRaw(y0, y1) {
  10905. var cy0 = cos$1(y0),
  10906. n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
  10907. f = cy0 * pow$1(tany(y0), n) / n;
  10908. if (!n) return mercatorRaw;
  10909. function project(x, y) {
  10910. if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
  10911. else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
  10912. var r = f / pow$1(tany(y), n);
  10913. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  10914. }
  10915. project.invert = function(x, y) {
  10916. var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
  10917. l = atan2$1(x, abs$1(fy)) * sign$1(fy);
  10918. if (fy * n < 0)
  10919. l -= pi$1 * sign$1(x) * sign$1(fy);
  10920. return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
  10921. };
  10922. return project;
  10923. }
  10924. function conicConformal() {
  10925. return conicProjection(conicConformalRaw)
  10926. .scale(109.5)
  10927. .parallels([30, 30]);
  10928. }
  10929. function equirectangularRaw(lambda, phi) {
  10930. return [lambda, phi];
  10931. }
  10932. equirectangularRaw.invert = equirectangularRaw;
  10933. function equirectangular() {
  10934. return projection(equirectangularRaw)
  10935. .scale(152.63);
  10936. }
  10937. function conicEquidistantRaw(y0, y1) {
  10938. var cy0 = cos$1(y0),
  10939. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  10940. g = cy0 / n + y0;
  10941. if (abs$1(n) < epsilon$1) return equirectangularRaw;
  10942. function project(x, y) {
  10943. var gy = g - y, nx = n * x;
  10944. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  10945. }
  10946. project.invert = function(x, y) {
  10947. var gy = g - y,
  10948. l = atan2$1(x, abs$1(gy)) * sign$1(gy);
  10949. if (gy * n < 0)
  10950. l -= pi$1 * sign$1(x) * sign$1(gy);
  10951. return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
  10952. };
  10953. return project;
  10954. }
  10955. function conicEquidistant() {
  10956. return conicProjection(conicEquidistantRaw)
  10957. .scale(131.154)
  10958. .center([0, 13.9389]);
  10959. }
  10960. var A1 = 1.340264,
  10961. A2 = -0.081106,
  10962. A3 = 0.000893,
  10963. A4 = 0.003796,
  10964. M = sqrt$2(3) / 2,
  10965. iterations = 12;
  10966. function equalEarthRaw(lambda, phi) {
  10967. var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  10968. return [
  10969. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  10970. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  10971. ];
  10972. }
  10973. equalEarthRaw.invert = function(x, y) {
  10974. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  10975. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  10976. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  10977. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  10978. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  10979. if (abs$1(delta) < epsilon2) break;
  10980. }
  10981. return [
  10982. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  10983. asin$1(sin$1(l) / M)
  10984. ];
  10985. };
  10986. function equalEarth() {
  10987. return projection(equalEarthRaw)
  10988. .scale(177.158);
  10989. }
  10990. function gnomonicRaw(x, y) {
  10991. var cy = cos$1(y), k = cos$1(x) * cy;
  10992. return [cy * sin$1(x) / k, sin$1(y) / k];
  10993. }
  10994. gnomonicRaw.invert = azimuthalInvert(atan);
  10995. function gnomonic() {
  10996. return projection(gnomonicRaw)
  10997. .scale(144.049)
  10998. .clipAngle(60);
  10999. }
  11000. function identity$4() {
  11001. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
  11002. alpha = 0, ca, sa, // angle
  11003. x0 = null, y0, x1, y1, // clip extent
  11004. kx = 1, ky = 1,
  11005. transform = transformer$3({
  11006. point: function(x, y) {
  11007. var p = projection([x, y]);
  11008. this.stream.point(p[0], p[1]);
  11009. }
  11010. }),
  11011. postclip = identity$5,
  11012. cache,
  11013. cacheStream;
  11014. function reset() {
  11015. kx = k * sx;
  11016. ky = k * sy;
  11017. cache = cacheStream = null;
  11018. return projection;
  11019. }
  11020. function projection (p) {
  11021. var x = p[0] * kx, y = p[1] * ky;
  11022. if (alpha) {
  11023. var t = y * ca - x * sa;
  11024. x = x * ca + y * sa;
  11025. y = t;
  11026. }
  11027. return [x + tx, y + ty];
  11028. }
  11029. projection.invert = function(p) {
  11030. var x = p[0] - tx, y = p[1] - ty;
  11031. if (alpha) {
  11032. var t = y * ca + x * sa;
  11033. x = x * ca - y * sa;
  11034. y = t;
  11035. }
  11036. return [x / kx, y / ky];
  11037. };
  11038. projection.stream = function(stream) {
  11039. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  11040. };
  11041. projection.postclip = function(_) {
  11042. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  11043. };
  11044. projection.clipExtent = function(_) {
  11045. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  11046. };
  11047. projection.scale = function(_) {
  11048. return arguments.length ? (k = +_, reset()) : k;
  11049. };
  11050. projection.translate = function(_) {
  11051. return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
  11052. };
  11053. projection.angle = function(_) {
  11054. return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
  11055. };
  11056. projection.reflectX = function(_) {
  11057. return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
  11058. };
  11059. projection.reflectY = function(_) {
  11060. return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
  11061. };
  11062. projection.fitExtent = function(extent, object) {
  11063. return fitExtent(projection, extent, object);
  11064. };
  11065. projection.fitSize = function(size, object) {
  11066. return fitSize(projection, size, object);
  11067. };
  11068. projection.fitWidth = function(width, object) {
  11069. return fitWidth(projection, width, object);
  11070. };
  11071. projection.fitHeight = function(height, object) {
  11072. return fitHeight(projection, height, object);
  11073. };
  11074. return projection;
  11075. }
  11076. function naturalEarth1Raw(lambda, phi) {
  11077. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11078. return [
  11079. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  11080. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  11081. ];
  11082. }
  11083. naturalEarth1Raw.invert = function(x, y) {
  11084. var phi = y, i = 25, delta;
  11085. do {
  11086. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11087. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  11088. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  11089. } while (abs$1(delta) > epsilon$1 && --i > 0);
  11090. return [
  11091. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  11092. phi
  11093. ];
  11094. };
  11095. function naturalEarth1() {
  11096. return projection(naturalEarth1Raw)
  11097. .scale(175.295);
  11098. }
  11099. function orthographicRaw(x, y) {
  11100. return [cos$1(y) * sin$1(x), sin$1(y)];
  11101. }
  11102. orthographicRaw.invert = azimuthalInvert(asin$1);
  11103. function orthographic() {
  11104. return projection(orthographicRaw)
  11105. .scale(249.5)
  11106. .clipAngle(90 + epsilon$1);
  11107. }
  11108. function stereographicRaw(x, y) {
  11109. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  11110. return [cy * sin$1(x) / k, sin$1(y) / k];
  11111. }
  11112. stereographicRaw.invert = azimuthalInvert(function(z) {
  11113. return 2 * atan(z);
  11114. });
  11115. function stereographic() {
  11116. return projection(stereographicRaw)
  11117. .scale(250)
  11118. .clipAngle(142);
  11119. }
  11120. function transverseMercatorRaw(lambda, phi) {
  11121. return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
  11122. }
  11123. transverseMercatorRaw.invert = function(x, y) {
  11124. return [-y, 2 * atan(exp(x)) - halfPi$1];
  11125. };
  11126. function transverseMercator() {
  11127. var m = mercatorProjection(transverseMercatorRaw),
  11128. center = m.center,
  11129. rotate = m.rotate;
  11130. m.center = function(_) {
  11131. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  11132. };
  11133. m.rotate = function(_) {
  11134. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  11135. };
  11136. return rotate([0, 0, 90])
  11137. .scale(159.155);
  11138. }
  11139. function defaultSeparation$1(a, b) {
  11140. return a.parent === b.parent ? 1 : 2;
  11141. }
  11142. function meanX(children) {
  11143. return children.reduce(meanXReduce, 0) / children.length;
  11144. }
  11145. function meanXReduce(x, c) {
  11146. return x + c.x;
  11147. }
  11148. function maxY(children) {
  11149. return 1 + children.reduce(maxYReduce, 0);
  11150. }
  11151. function maxYReduce(y, c) {
  11152. return Math.max(y, c.y);
  11153. }
  11154. function leafLeft(node) {
  11155. var children;
  11156. while (children = node.children) node = children[0];
  11157. return node;
  11158. }
  11159. function leafRight(node) {
  11160. var children;
  11161. while (children = node.children) node = children[children.length - 1];
  11162. return node;
  11163. }
  11164. function cluster() {
  11165. var separation = defaultSeparation$1,
  11166. dx = 1,
  11167. dy = 1,
  11168. nodeSize = false;
  11169. function cluster(root) {
  11170. var previousNode,
  11171. x = 0;
  11172. // First walk, computing the initial x & y values.
  11173. root.eachAfter(function(node) {
  11174. var children = node.children;
  11175. if (children) {
  11176. node.x = meanX(children);
  11177. node.y = maxY(children);
  11178. } else {
  11179. node.x = previousNode ? x += separation(node, previousNode) : 0;
  11180. node.y = 0;
  11181. previousNode = node;
  11182. }
  11183. });
  11184. var left = leafLeft(root),
  11185. right = leafRight(root),
  11186. x0 = left.x - separation(left, right) / 2,
  11187. x1 = right.x + separation(right, left) / 2;
  11188. // Second walk, normalizing x & y to the desired size.
  11189. return root.eachAfter(nodeSize ? function(node) {
  11190. node.x = (node.x - root.x) * dx;
  11191. node.y = (root.y - node.y) * dy;
  11192. } : function(node) {
  11193. node.x = (node.x - x0) / (x1 - x0) * dx;
  11194. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  11195. });
  11196. }
  11197. cluster.separation = function(x) {
  11198. return arguments.length ? (separation = x, cluster) : separation;
  11199. };
  11200. cluster.size = function(x) {
  11201. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  11202. };
  11203. cluster.nodeSize = function(x) {
  11204. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  11205. };
  11206. return cluster;
  11207. }
  11208. function count(node) {
  11209. var sum = 0,
  11210. children = node.children,
  11211. i = children && children.length;
  11212. if (!i) sum = 1;
  11213. else while (--i >= 0) sum += children[i].value;
  11214. node.value = sum;
  11215. }
  11216. function node_count() {
  11217. return this.eachAfter(count);
  11218. }
  11219. function node_each(callback, that) {
  11220. let index = -1;
  11221. for (const node of this) {
  11222. callback.call(that, node, ++index, this);
  11223. }
  11224. return this;
  11225. }
  11226. function node_eachBefore(callback, that) {
  11227. var node = this, nodes = [node], children, i, index = -1;
  11228. while (node = nodes.pop()) {
  11229. callback.call(that, node, ++index, this);
  11230. if (children = node.children) {
  11231. for (i = children.length - 1; i >= 0; --i) {
  11232. nodes.push(children[i]);
  11233. }
  11234. }
  11235. }
  11236. return this;
  11237. }
  11238. function node_eachAfter(callback, that) {
  11239. var node = this, nodes = [node], next = [], children, i, n, index = -1;
  11240. while (node = nodes.pop()) {
  11241. next.push(node);
  11242. if (children = node.children) {
  11243. for (i = 0, n = children.length; i < n; ++i) {
  11244. nodes.push(children[i]);
  11245. }
  11246. }
  11247. }
  11248. while (node = next.pop()) {
  11249. callback.call(that, node, ++index, this);
  11250. }
  11251. return this;
  11252. }
  11253. function node_find(callback, that) {
  11254. let index = -1;
  11255. for (const node of this) {
  11256. if (callback.call(that, node, ++index, this)) {
  11257. return node;
  11258. }
  11259. }
  11260. }
  11261. function node_sum(value) {
  11262. return this.eachAfter(function(node) {
  11263. var sum = +value(node.data) || 0,
  11264. children = node.children,
  11265. i = children && children.length;
  11266. while (--i >= 0) sum += children[i].value;
  11267. node.value = sum;
  11268. });
  11269. }
  11270. function node_sort(compare) {
  11271. return this.eachBefore(function(node) {
  11272. if (node.children) {
  11273. node.children.sort(compare);
  11274. }
  11275. });
  11276. }
  11277. function node_path(end) {
  11278. var start = this,
  11279. ancestor = leastCommonAncestor(start, end),
  11280. nodes = [start];
  11281. while (start !== ancestor) {
  11282. start = start.parent;
  11283. nodes.push(start);
  11284. }
  11285. var k = nodes.length;
  11286. while (end !== ancestor) {
  11287. nodes.splice(k, 0, end);
  11288. end = end.parent;
  11289. }
  11290. return nodes;
  11291. }
  11292. function leastCommonAncestor(a, b) {
  11293. if (a === b) return a;
  11294. var aNodes = a.ancestors(),
  11295. bNodes = b.ancestors(),
  11296. c = null;
  11297. a = aNodes.pop();
  11298. b = bNodes.pop();
  11299. while (a === b) {
  11300. c = a;
  11301. a = aNodes.pop();
  11302. b = bNodes.pop();
  11303. }
  11304. return c;
  11305. }
  11306. function node_ancestors() {
  11307. var node = this, nodes = [node];
  11308. while (node = node.parent) {
  11309. nodes.push(node);
  11310. }
  11311. return nodes;
  11312. }
  11313. function node_descendants() {
  11314. return Array.from(this);
  11315. }
  11316. function node_leaves() {
  11317. var leaves = [];
  11318. this.eachBefore(function(node) {
  11319. if (!node.children) {
  11320. leaves.push(node);
  11321. }
  11322. });
  11323. return leaves;
  11324. }
  11325. function node_links() {
  11326. var root = this, links = [];
  11327. root.each(function(node) {
  11328. if (node !== root) { // Don’t include the root’s parent, if any.
  11329. links.push({source: node.parent, target: node});
  11330. }
  11331. });
  11332. return links;
  11333. }
  11334. function* node_iterator() {
  11335. var node = this, current, next = [node], children, i, n;
  11336. do {
  11337. current = next.reverse(), next = [];
  11338. while (node = current.pop()) {
  11339. yield node;
  11340. if (children = node.children) {
  11341. for (i = 0, n = children.length; i < n; ++i) {
  11342. next.push(children[i]);
  11343. }
  11344. }
  11345. }
  11346. } while (next.length);
  11347. }
  11348. function hierarchy(data, children) {
  11349. if (data instanceof Map) {
  11350. data = [undefined, data];
  11351. if (children === undefined) children = mapChildren;
  11352. } else if (children === undefined) {
  11353. children = objectChildren;
  11354. }
  11355. var root = new Node$1(data),
  11356. node,
  11357. nodes = [root],
  11358. child,
  11359. childs,
  11360. i,
  11361. n;
  11362. while (node = nodes.pop()) {
  11363. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  11364. node.children = childs;
  11365. for (i = n - 1; i >= 0; --i) {
  11366. nodes.push(child = childs[i] = new Node$1(childs[i]));
  11367. child.parent = node;
  11368. child.depth = node.depth + 1;
  11369. }
  11370. }
  11371. }
  11372. return root.eachBefore(computeHeight);
  11373. }
  11374. function node_copy() {
  11375. return hierarchy(this).eachBefore(copyData);
  11376. }
  11377. function objectChildren(d) {
  11378. return d.children;
  11379. }
  11380. function mapChildren(d) {
  11381. return Array.isArray(d) ? d[1] : null;
  11382. }
  11383. function copyData(node) {
  11384. if (node.data.value !== undefined) node.value = node.data.value;
  11385. node.data = node.data.data;
  11386. }
  11387. function computeHeight(node) {
  11388. var height = 0;
  11389. do node.height = height;
  11390. while ((node = node.parent) && (node.height < ++height));
  11391. }
  11392. function Node$1(data) {
  11393. this.data = data;
  11394. this.depth =
  11395. this.height = 0;
  11396. this.parent = null;
  11397. }
  11398. Node$1.prototype = hierarchy.prototype = {
  11399. constructor: Node$1,
  11400. count: node_count,
  11401. each: node_each,
  11402. eachAfter: node_eachAfter,
  11403. eachBefore: node_eachBefore,
  11404. find: node_find,
  11405. sum: node_sum,
  11406. sort: node_sort,
  11407. path: node_path,
  11408. ancestors: node_ancestors,
  11409. descendants: node_descendants,
  11410. leaves: node_leaves,
  11411. links: node_links,
  11412. copy: node_copy,
  11413. [Symbol.iterator]: node_iterator
  11414. };
  11415. function optional(f) {
  11416. return f == null ? null : required(f);
  11417. }
  11418. function required(f) {
  11419. if (typeof f !== "function") throw new Error;
  11420. return f;
  11421. }
  11422. function constantZero() {
  11423. return 0;
  11424. }
  11425. function constant$2(x) {
  11426. return function() {
  11427. return x;
  11428. };
  11429. }
  11430. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  11431. const a$1 = 1664525;
  11432. const c$3 = 1013904223;
  11433. const m = 4294967296; // 2^32
  11434. function lcg$1() {
  11435. let s = 1;
  11436. return () => (s = (a$1 * s + c$3) % m) / m;
  11437. }
  11438. function array$1(x) {
  11439. return typeof x === "object" && "length" in x
  11440. ? x // Array, TypedArray, NodeList, array-like
  11441. : Array.from(x); // Map, Set, iterable, string, or anything else
  11442. }
  11443. function shuffle(array, random) {
  11444. let m = array.length,
  11445. t,
  11446. i;
  11447. while (m) {
  11448. i = random() * m-- | 0;
  11449. t = array[m];
  11450. array[m] = array[i];
  11451. array[i] = t;
  11452. }
  11453. return array;
  11454. }
  11455. function enclose(circles) {
  11456. return packEncloseRandom(circles, lcg$1());
  11457. }
  11458. function packEncloseRandom(circles, random) {
  11459. var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e;
  11460. while (i < n) {
  11461. p = circles[i];
  11462. if (e && enclosesWeak(e, p)) ++i;
  11463. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  11464. }
  11465. return e;
  11466. }
  11467. function extendBasis(B, p) {
  11468. var i, j;
  11469. if (enclosesWeakAll(p, B)) return [p];
  11470. // If we get here then B must have at least one element.
  11471. for (i = 0; i < B.length; ++i) {
  11472. if (enclosesNot(p, B[i])
  11473. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  11474. return [B[i], p];
  11475. }
  11476. }
  11477. // If we get here then B must have at least two elements.
  11478. for (i = 0; i < B.length - 1; ++i) {
  11479. for (j = i + 1; j < B.length; ++j) {
  11480. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  11481. && enclosesNot(encloseBasis2(B[i], p), B[j])
  11482. && enclosesNot(encloseBasis2(B[j], p), B[i])
  11483. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  11484. return [B[i], B[j], p];
  11485. }
  11486. }
  11487. }
  11488. // If we get here then something is very wrong.
  11489. throw new Error;
  11490. }
  11491. function enclosesNot(a, b) {
  11492. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  11493. return dr < 0 || dr * dr < dx * dx + dy * dy;
  11494. }
  11495. function enclosesWeak(a, b) {
  11496. var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y;
  11497. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11498. }
  11499. function enclosesWeakAll(a, B) {
  11500. for (var i = 0; i < B.length; ++i) {
  11501. if (!enclosesWeak(a, B[i])) {
  11502. return false;
  11503. }
  11504. }
  11505. return true;
  11506. }
  11507. function encloseBasis(B) {
  11508. switch (B.length) {
  11509. case 1: return encloseBasis1(B[0]);
  11510. case 2: return encloseBasis2(B[0], B[1]);
  11511. case 3: return encloseBasis3(B[0], B[1], B[2]);
  11512. }
  11513. }
  11514. function encloseBasis1(a) {
  11515. return {
  11516. x: a.x,
  11517. y: a.y,
  11518. r: a.r
  11519. };
  11520. }
  11521. function encloseBasis2(a, b) {
  11522. var x1 = a.x, y1 = a.y, r1 = a.r,
  11523. x2 = b.x, y2 = b.y, r2 = b.r,
  11524. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  11525. l = Math.sqrt(x21 * x21 + y21 * y21);
  11526. return {
  11527. x: (x1 + x2 + x21 / l * r21) / 2,
  11528. y: (y1 + y2 + y21 / l * r21) / 2,
  11529. r: (l + r1 + r2) / 2
  11530. };
  11531. }
  11532. function encloseBasis3(a, b, c) {
  11533. var x1 = a.x, y1 = a.y, r1 = a.r,
  11534. x2 = b.x, y2 = b.y, r2 = b.r,
  11535. x3 = c.x, y3 = c.y, r3 = c.r,
  11536. a2 = x1 - x2,
  11537. a3 = x1 - x3,
  11538. b2 = y1 - y2,
  11539. b3 = y1 - y3,
  11540. c2 = r2 - r1,
  11541. c3 = r3 - r1,
  11542. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  11543. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  11544. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  11545. ab = a3 * b2 - a2 * b3,
  11546. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  11547. xb = (b3 * c2 - b2 * c3) / ab,
  11548. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  11549. yb = (a2 * c3 - a3 * c2) / ab,
  11550. A = xb * xb + yb * yb - 1,
  11551. B = 2 * (r1 + xa * xb + ya * yb),
  11552. C = xa * xa + ya * ya - r1 * r1,
  11553. r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  11554. return {
  11555. x: x1 + xa + xb * r,
  11556. y: y1 + ya + yb * r,
  11557. r: r
  11558. };
  11559. }
  11560. function place(b, a, c) {
  11561. var dx = b.x - a.x, x, a2,
  11562. dy = b.y - a.y, y, b2,
  11563. d2 = dx * dx + dy * dy;
  11564. if (d2) {
  11565. a2 = a.r + c.r, a2 *= a2;
  11566. b2 = b.r + c.r, b2 *= b2;
  11567. if (a2 > b2) {
  11568. x = (d2 + b2 - a2) / (2 * d2);
  11569. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  11570. c.x = b.x - x * dx - y * dy;
  11571. c.y = b.y - x * dy + y * dx;
  11572. } else {
  11573. x = (d2 + a2 - b2) / (2 * d2);
  11574. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  11575. c.x = a.x + x * dx - y * dy;
  11576. c.y = a.y + x * dy + y * dx;
  11577. }
  11578. } else {
  11579. c.x = a.x + c.r;
  11580. c.y = a.y;
  11581. }
  11582. }
  11583. function intersects(a, b) {
  11584. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  11585. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11586. }
  11587. function score(node) {
  11588. var a = node._,
  11589. b = node.next._,
  11590. ab = a.r + b.r,
  11591. dx = (a.x * b.r + b.x * a.r) / ab,
  11592. dy = (a.y * b.r + b.y * a.r) / ab;
  11593. return dx * dx + dy * dy;
  11594. }
  11595. function Node(circle) {
  11596. this._ = circle;
  11597. this.next = null;
  11598. this.previous = null;
  11599. }
  11600. function packSiblingsRandom(circles, random) {
  11601. if (!(n = (circles = array$1(circles)).length)) return 0;
  11602. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  11603. // Place the first circle.
  11604. a = circles[0], a.x = 0, a.y = 0;
  11605. if (!(n > 1)) return a.r;
  11606. // Place the second circle.
  11607. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  11608. if (!(n > 2)) return a.r + b.r;
  11609. // Place the third circle.
  11610. place(b, a, c = circles[2]);
  11611. // Initialize the front-chain using the first three circles a, b and c.
  11612. a = new Node(a), b = new Node(b), c = new Node(c);
  11613. a.next = c.previous = b;
  11614. b.next = a.previous = c;
  11615. c.next = b.previous = a;
  11616. // Attempt to place each remaining circle…
  11617. pack: for (i = 3; i < n; ++i) {
  11618. place(a._, b._, c = circles[i]), c = new Node(c);
  11619. // Find the closest intersecting circle on the front-chain, if any.
  11620. // “Closeness” is determined by linear distance along the front-chain.
  11621. // “Ahead” or “behind” is likewise determined by linear distance.
  11622. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  11623. do {
  11624. if (sj <= sk) {
  11625. if (intersects(j._, c._)) {
  11626. b = j, a.next = b, b.previous = a, --i;
  11627. continue pack;
  11628. }
  11629. sj += j._.r, j = j.next;
  11630. } else {
  11631. if (intersects(k._, c._)) {
  11632. a = k, a.next = b, b.previous = a, --i;
  11633. continue pack;
  11634. }
  11635. sk += k._.r, k = k.previous;
  11636. }
  11637. } while (j !== k.next);
  11638. // Success! Insert the new circle c between a and b.
  11639. c.previous = a, c.next = b, a.next = b.previous = b = c;
  11640. // Compute the new closest circle pair to the centroid.
  11641. aa = score(a);
  11642. while ((c = c.next) !== b) {
  11643. if ((ca = score(c)) < aa) {
  11644. a = c, aa = ca;
  11645. }
  11646. }
  11647. b = a.next;
  11648. }
  11649. // Compute the enclosing circle of the front chain.
  11650. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random);
  11651. // Translate the circles to put the enclosing circle around the origin.
  11652. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  11653. return c.r;
  11654. }
  11655. function siblings(circles) {
  11656. packSiblingsRandom(circles, lcg$1());
  11657. return circles;
  11658. }
  11659. function defaultRadius(d) {
  11660. return Math.sqrt(d.value);
  11661. }
  11662. function index$1() {
  11663. var radius = null,
  11664. dx = 1,
  11665. dy = 1,
  11666. padding = constantZero;
  11667. function pack(root) {
  11668. const random = lcg$1();
  11669. root.x = dx / 2, root.y = dy / 2;
  11670. if (radius) {
  11671. root.eachBefore(radiusLeaf(radius))
  11672. .eachAfter(packChildrenRandom(padding, 0.5, random))
  11673. .eachBefore(translateChild(1));
  11674. } else {
  11675. root.eachBefore(radiusLeaf(defaultRadius))
  11676. .eachAfter(packChildrenRandom(constantZero, 1, random))
  11677. .eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random))
  11678. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  11679. }
  11680. return root;
  11681. }
  11682. pack.radius = function(x) {
  11683. return arguments.length ? (radius = optional(x), pack) : radius;
  11684. };
  11685. pack.size = function(x) {
  11686. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  11687. };
  11688. pack.padding = function(x) {
  11689. return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
  11690. };
  11691. return pack;
  11692. }
  11693. function radiusLeaf(radius) {
  11694. return function(node) {
  11695. if (!node.children) {
  11696. node.r = Math.max(0, +radius(node) || 0);
  11697. }
  11698. };
  11699. }
  11700. function packChildrenRandom(padding, k, random) {
  11701. return function(node) {
  11702. if (children = node.children) {
  11703. var children,
  11704. i,
  11705. n = children.length,
  11706. r = padding(node) * k || 0,
  11707. e;
  11708. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  11709. e = packSiblingsRandom(children, random);
  11710. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  11711. node.r = e + r;
  11712. }
  11713. };
  11714. }
  11715. function translateChild(k) {
  11716. return function(node) {
  11717. var parent = node.parent;
  11718. node.r *= k;
  11719. if (parent) {
  11720. node.x = parent.x + k * node.x;
  11721. node.y = parent.y + k * node.y;
  11722. }
  11723. };
  11724. }
  11725. function roundNode(node) {
  11726. node.x0 = Math.round(node.x0);
  11727. node.y0 = Math.round(node.y0);
  11728. node.x1 = Math.round(node.x1);
  11729. node.y1 = Math.round(node.y1);
  11730. }
  11731. function treemapDice(parent, x0, y0, x1, y1) {
  11732. var nodes = parent.children,
  11733. node,
  11734. i = -1,
  11735. n = nodes.length,
  11736. k = parent.value && (x1 - x0) / parent.value;
  11737. while (++i < n) {
  11738. node = nodes[i], node.y0 = y0, node.y1 = y1;
  11739. node.x0 = x0, node.x1 = x0 += node.value * k;
  11740. }
  11741. }
  11742. function partition() {
  11743. var dx = 1,
  11744. dy = 1,
  11745. padding = 0,
  11746. round = false;
  11747. function partition(root) {
  11748. var n = root.height + 1;
  11749. root.x0 =
  11750. root.y0 = padding;
  11751. root.x1 = dx;
  11752. root.y1 = dy / n;
  11753. root.eachBefore(positionNode(dy, n));
  11754. if (round) root.eachBefore(roundNode);
  11755. return root;
  11756. }
  11757. function positionNode(dy, n) {
  11758. return function(node) {
  11759. if (node.children) {
  11760. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  11761. }
  11762. var x0 = node.x0,
  11763. y0 = node.y0,
  11764. x1 = node.x1 - padding,
  11765. y1 = node.y1 - padding;
  11766. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11767. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11768. node.x0 = x0;
  11769. node.y0 = y0;
  11770. node.x1 = x1;
  11771. node.y1 = y1;
  11772. };
  11773. }
  11774. partition.round = function(x) {
  11775. return arguments.length ? (round = !!x, partition) : round;
  11776. };
  11777. partition.size = function(x) {
  11778. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  11779. };
  11780. partition.padding = function(x) {
  11781. return arguments.length ? (padding = +x, partition) : padding;
  11782. };
  11783. return partition;
  11784. }
  11785. var preroot = {depth: -1},
  11786. ambiguous = {},
  11787. imputed = {};
  11788. function defaultId(d) {
  11789. return d.id;
  11790. }
  11791. function defaultParentId(d) {
  11792. return d.parentId;
  11793. }
  11794. function stratify() {
  11795. var id = defaultId,
  11796. parentId = defaultParentId,
  11797. path;
  11798. function stratify(data) {
  11799. var nodes = Array.from(data),
  11800. currentId = id,
  11801. currentParentId = parentId,
  11802. n,
  11803. d,
  11804. i,
  11805. root,
  11806. parent,
  11807. node,
  11808. nodeId,
  11809. nodeKey,
  11810. nodeByKey = new Map;
  11811. if (path != null) {
  11812. const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
  11813. const P = I.map(parentof);
  11814. const S = new Set(I).add("");
  11815. for (const i of P) {
  11816. if (!S.has(i)) {
  11817. S.add(i);
  11818. I.push(i);
  11819. P.push(parentof(i));
  11820. nodes.push(imputed);
  11821. }
  11822. }
  11823. currentId = (_, i) => I[i];
  11824. currentParentId = (_, i) => P[i];
  11825. }
  11826. for (i = 0, n = nodes.length; i < n; ++i) {
  11827. d = nodes[i], node = nodes[i] = new Node$1(d);
  11828. if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
  11829. nodeKey = node.id = nodeId;
  11830. nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
  11831. }
  11832. if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
  11833. node.parent = nodeId;
  11834. }
  11835. }
  11836. for (i = 0; i < n; ++i) {
  11837. node = nodes[i];
  11838. if (nodeId = node.parent) {
  11839. parent = nodeByKey.get(nodeId);
  11840. if (!parent) throw new Error("missing: " + nodeId);
  11841. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  11842. if (parent.children) parent.children.push(node);
  11843. else parent.children = [node];
  11844. node.parent = parent;
  11845. } else {
  11846. if (root) throw new Error("multiple roots");
  11847. root = node;
  11848. }
  11849. }
  11850. if (!root) throw new Error("no root");
  11851. // When imputing internal nodes, only introduce roots if needed.
  11852. // Then replace the imputed marker data with null.
  11853. if (path != null) {
  11854. while (root.data === imputed && root.children.length === 1) {
  11855. root = root.children[0], --n;
  11856. }
  11857. for (let i = nodes.length - 1; i >= 0; --i) {
  11858. node = nodes[i];
  11859. if (node.data !== imputed) break;
  11860. node.data = null;
  11861. }
  11862. }
  11863. root.parent = preroot;
  11864. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  11865. root.parent = null;
  11866. if (n > 0) throw new Error("cycle");
  11867. return root;
  11868. }
  11869. stratify.id = function(x) {
  11870. return arguments.length ? (id = optional(x), stratify) : id;
  11871. };
  11872. stratify.parentId = function(x) {
  11873. return arguments.length ? (parentId = optional(x), stratify) : parentId;
  11874. };
  11875. stratify.path = function(x) {
  11876. return arguments.length ? (path = optional(x), stratify) : path;
  11877. };
  11878. return stratify;
  11879. }
  11880. // To normalize a path, we coerce to a string, strip the trailing slash if any
  11881. // (as long as the trailing slash is not immediately preceded by another slash),
  11882. // and add leading slash if missing.
  11883. function normalize$1(path) {
  11884. path = `${path}`;
  11885. let i = path.length;
  11886. if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);
  11887. return path[0] === "/" ? path : `/${path}`;
  11888. }
  11889. // Walk backwards to find the first slash that is not the leading slash, e.g.:
  11890. // "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
  11891. // because the id of the root must be a truthy value.)
  11892. function parentof(path) {
  11893. let i = path.length;
  11894. if (i < 2) return "";
  11895. while (--i > 1) if (slash(path, i)) break;
  11896. return path.slice(0, i);
  11897. }
  11898. // Slashes can be escaped; to determine whether a slash is a path delimiter, we
  11899. // count the number of preceding backslashes escaping the forward slash: an odd
  11900. // number indicates an escaped forward slash.
  11901. function slash(path, i) {
  11902. if (path[i] === "/") {
  11903. let k = 0;
  11904. while (i > 0 && path[--i] === "\\") ++k;
  11905. if ((k & 1) === 0) return true;
  11906. }
  11907. return false;
  11908. }
  11909. function defaultSeparation(a, b) {
  11910. return a.parent === b.parent ? 1 : 2;
  11911. }
  11912. // function radialSeparation(a, b) {
  11913. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  11914. // }
  11915. // This function is used to traverse the left contour of a subtree (or
  11916. // subforest). It returns the successor of v on this contour. This successor is
  11917. // either given by the leftmost child of v or by the thread of v. The function
  11918. // returns null if and only if v is on the highest level of its subtree.
  11919. function nextLeft(v) {
  11920. var children = v.children;
  11921. return children ? children[0] : v.t;
  11922. }
  11923. // This function works analogously to nextLeft.
  11924. function nextRight(v) {
  11925. var children = v.children;
  11926. return children ? children[children.length - 1] : v.t;
  11927. }
  11928. // Shifts the current subtree rooted at w+. This is done by increasing
  11929. // prelim(w+) and mod(w+) by shift.
  11930. function moveSubtree(wm, wp, shift) {
  11931. var change = shift / (wp.i - wm.i);
  11932. wp.c -= change;
  11933. wp.s += shift;
  11934. wm.c += change;
  11935. wp.z += shift;
  11936. wp.m += shift;
  11937. }
  11938. // All other shifts, applied to the smaller subtrees between w- and w+, are
  11939. // performed by this function. To prepare the shifts, we have to adjust
  11940. // change(w+), shift(w+), and change(w-).
  11941. function executeShifts(v) {
  11942. var shift = 0,
  11943. change = 0,
  11944. children = v.children,
  11945. i = children.length,
  11946. w;
  11947. while (--i >= 0) {
  11948. w = children[i];
  11949. w.z += shift;
  11950. w.m += shift;
  11951. shift += w.s + (change += w.c);
  11952. }
  11953. }
  11954. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  11955. // returns the specified (default) ancestor.
  11956. function nextAncestor(vim, v, ancestor) {
  11957. return vim.a.parent === v.parent ? vim.a : ancestor;
  11958. }
  11959. function TreeNode(node, i) {
  11960. this._ = node;
  11961. this.parent = null;
  11962. this.children = null;
  11963. this.A = null; // default ancestor
  11964. this.a = this; // ancestor
  11965. this.z = 0; // prelim
  11966. this.m = 0; // mod
  11967. this.c = 0; // change
  11968. this.s = 0; // shift
  11969. this.t = null; // thread
  11970. this.i = i; // number
  11971. }
  11972. TreeNode.prototype = Object.create(Node$1.prototype);
  11973. function treeRoot(root) {
  11974. var tree = new TreeNode(root, 0),
  11975. node,
  11976. nodes = [tree],
  11977. child,
  11978. children,
  11979. i,
  11980. n;
  11981. while (node = nodes.pop()) {
  11982. if (children = node._.children) {
  11983. node.children = new Array(n = children.length);
  11984. for (i = n - 1; i >= 0; --i) {
  11985. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  11986. child.parent = node;
  11987. }
  11988. }
  11989. }
  11990. (tree.parent = new TreeNode(null, 0)).children = [tree];
  11991. return tree;
  11992. }
  11993. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  11994. function tree() {
  11995. var separation = defaultSeparation,
  11996. dx = 1,
  11997. dy = 1,
  11998. nodeSize = null;
  11999. function tree(root) {
  12000. var t = treeRoot(root);
  12001. // Compute the layout using Buchheim et al.’s algorithm.
  12002. t.eachAfter(firstWalk), t.parent.m = -t.z;
  12003. t.eachBefore(secondWalk);
  12004. // If a fixed node size is specified, scale x and y.
  12005. if (nodeSize) root.eachBefore(sizeNode);
  12006. // If a fixed tree size is specified, scale x and y based on the extent.
  12007. // Compute the left-most, right-most, and depth-most nodes for extents.
  12008. else {
  12009. var left = root,
  12010. right = root,
  12011. bottom = root;
  12012. root.eachBefore(function(node) {
  12013. if (node.x < left.x) left = node;
  12014. if (node.x > right.x) right = node;
  12015. if (node.depth > bottom.depth) bottom = node;
  12016. });
  12017. var s = left === right ? 1 : separation(left, right) / 2,
  12018. tx = s - left.x,
  12019. kx = dx / (right.x + s + tx),
  12020. ky = dy / (bottom.depth || 1);
  12021. root.eachBefore(function(node) {
  12022. node.x = (node.x + tx) * kx;
  12023. node.y = node.depth * ky;
  12024. });
  12025. }
  12026. return root;
  12027. }
  12028. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  12029. // applied recursively to the children of v, as well as the function
  12030. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  12031. // node v is placed to the midpoint of its outermost children.
  12032. function firstWalk(v) {
  12033. var children = v.children,
  12034. siblings = v.parent.children,
  12035. w = v.i ? siblings[v.i - 1] : null;
  12036. if (children) {
  12037. executeShifts(v);
  12038. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  12039. if (w) {
  12040. v.z = w.z + separation(v._, w._);
  12041. v.m = v.z - midpoint;
  12042. } else {
  12043. v.z = midpoint;
  12044. }
  12045. } else if (w) {
  12046. v.z = w.z + separation(v._, w._);
  12047. }
  12048. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  12049. }
  12050. // Computes all real x-coordinates by summing up the modifiers recursively.
  12051. function secondWalk(v) {
  12052. v._.x = v.z + v.parent.m;
  12053. v.m += v.parent.m;
  12054. }
  12055. // The core of the algorithm. Here, a new subtree is combined with the
  12056. // previous subtrees. Threads are used to traverse the inside and outside
  12057. // contours of the left and right subtree up to the highest common level. The
  12058. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  12059. // superscript o means outside and i means inside, the subscript - means left
  12060. // subtree and + means right subtree. For summing up the modifiers along the
  12061. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  12062. // nodes of the inside contours conflict, we compute the left one of the
  12063. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  12064. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  12065. // Finally, we add a new thread (if necessary).
  12066. function apportion(v, w, ancestor) {
  12067. if (w) {
  12068. var vip = v,
  12069. vop = v,
  12070. vim = w,
  12071. vom = vip.parent.children[0],
  12072. sip = vip.m,
  12073. sop = vop.m,
  12074. sim = vim.m,
  12075. som = vom.m,
  12076. shift;
  12077. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  12078. vom = nextLeft(vom);
  12079. vop = nextRight(vop);
  12080. vop.a = v;
  12081. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  12082. if (shift > 0) {
  12083. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  12084. sip += shift;
  12085. sop += shift;
  12086. }
  12087. sim += vim.m;
  12088. sip += vip.m;
  12089. som += vom.m;
  12090. sop += vop.m;
  12091. }
  12092. if (vim && !nextRight(vop)) {
  12093. vop.t = vim;
  12094. vop.m += sim - sop;
  12095. }
  12096. if (vip && !nextLeft(vom)) {
  12097. vom.t = vip;
  12098. vom.m += sip - som;
  12099. ancestor = v;
  12100. }
  12101. }
  12102. return ancestor;
  12103. }
  12104. function sizeNode(node) {
  12105. node.x *= dx;
  12106. node.y = node.depth * dy;
  12107. }
  12108. tree.separation = function(x) {
  12109. return arguments.length ? (separation = x, tree) : separation;
  12110. };
  12111. tree.size = function(x) {
  12112. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  12113. };
  12114. tree.nodeSize = function(x) {
  12115. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  12116. };
  12117. return tree;
  12118. }
  12119. function treemapSlice(parent, x0, y0, x1, y1) {
  12120. var nodes = parent.children,
  12121. node,
  12122. i = -1,
  12123. n = nodes.length,
  12124. k = parent.value && (y1 - y0) / parent.value;
  12125. while (++i < n) {
  12126. node = nodes[i], node.x0 = x0, node.x1 = x1;
  12127. node.y0 = y0, node.y1 = y0 += node.value * k;
  12128. }
  12129. }
  12130. var phi = (1 + Math.sqrt(5)) / 2;
  12131. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  12132. var rows = [],
  12133. nodes = parent.children,
  12134. row,
  12135. nodeValue,
  12136. i0 = 0,
  12137. i1 = 0,
  12138. n = nodes.length,
  12139. dx, dy,
  12140. value = parent.value,
  12141. sumValue,
  12142. minValue,
  12143. maxValue,
  12144. newRatio,
  12145. minRatio,
  12146. alpha,
  12147. beta;
  12148. while (i0 < n) {
  12149. dx = x1 - x0, dy = y1 - y0;
  12150. // Find the next non-empty node.
  12151. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  12152. minValue = maxValue = sumValue;
  12153. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  12154. beta = sumValue * sumValue * alpha;
  12155. minRatio = Math.max(maxValue / beta, beta / minValue);
  12156. // Keep adding nodes while the aspect ratio maintains or improves.
  12157. for (; i1 < n; ++i1) {
  12158. sumValue += nodeValue = nodes[i1].value;
  12159. if (nodeValue < minValue) minValue = nodeValue;
  12160. if (nodeValue > maxValue) maxValue = nodeValue;
  12161. beta = sumValue * sumValue * alpha;
  12162. newRatio = Math.max(maxValue / beta, beta / minValue);
  12163. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  12164. minRatio = newRatio;
  12165. }
  12166. // Position and record the row orientation.
  12167. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  12168. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  12169. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  12170. value -= sumValue, i0 = i1;
  12171. }
  12172. return rows;
  12173. }
  12174. var squarify = (function custom(ratio) {
  12175. function squarify(parent, x0, y0, x1, y1) {
  12176. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12177. }
  12178. squarify.ratio = function(x) {
  12179. return custom((x = +x) > 1 ? x : 1);
  12180. };
  12181. return squarify;
  12182. })(phi);
  12183. function index() {
  12184. var tile = squarify,
  12185. round = false,
  12186. dx = 1,
  12187. dy = 1,
  12188. paddingStack = [0],
  12189. paddingInner = constantZero,
  12190. paddingTop = constantZero,
  12191. paddingRight = constantZero,
  12192. paddingBottom = constantZero,
  12193. paddingLeft = constantZero;
  12194. function treemap(root) {
  12195. root.x0 =
  12196. root.y0 = 0;
  12197. root.x1 = dx;
  12198. root.y1 = dy;
  12199. root.eachBefore(positionNode);
  12200. paddingStack = [0];
  12201. if (round) root.eachBefore(roundNode);
  12202. return root;
  12203. }
  12204. function positionNode(node) {
  12205. var p = paddingStack[node.depth],
  12206. x0 = node.x0 + p,
  12207. y0 = node.y0 + p,
  12208. x1 = node.x1 - p,
  12209. y1 = node.y1 - p;
  12210. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12211. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12212. node.x0 = x0;
  12213. node.y0 = y0;
  12214. node.x1 = x1;
  12215. node.y1 = y1;
  12216. if (node.children) {
  12217. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  12218. x0 += paddingLeft(node) - p;
  12219. y0 += paddingTop(node) - p;
  12220. x1 -= paddingRight(node) - p;
  12221. y1 -= paddingBottom(node) - p;
  12222. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12223. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12224. tile(node, x0, y0, x1, y1);
  12225. }
  12226. }
  12227. treemap.round = function(x) {
  12228. return arguments.length ? (round = !!x, treemap) : round;
  12229. };
  12230. treemap.size = function(x) {
  12231. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  12232. };
  12233. treemap.tile = function(x) {
  12234. return arguments.length ? (tile = required(x), treemap) : tile;
  12235. };
  12236. treemap.padding = function(x) {
  12237. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  12238. };
  12239. treemap.paddingInner = function(x) {
  12240. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
  12241. };
  12242. treemap.paddingOuter = function(x) {
  12243. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  12244. };
  12245. treemap.paddingTop = function(x) {
  12246. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
  12247. };
  12248. treemap.paddingRight = function(x) {
  12249. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
  12250. };
  12251. treemap.paddingBottom = function(x) {
  12252. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
  12253. };
  12254. treemap.paddingLeft = function(x) {
  12255. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
  12256. };
  12257. return treemap;
  12258. }
  12259. function binary(parent, x0, y0, x1, y1) {
  12260. var nodes = parent.children,
  12261. i, n = nodes.length,
  12262. sum, sums = new Array(n + 1);
  12263. for (sums[0] = sum = i = 0; i < n; ++i) {
  12264. sums[i + 1] = sum += nodes[i].value;
  12265. }
  12266. partition(0, n, parent.value, x0, y0, x1, y1);
  12267. function partition(i, j, value, x0, y0, x1, y1) {
  12268. if (i >= j - 1) {
  12269. var node = nodes[i];
  12270. node.x0 = x0, node.y0 = y0;
  12271. node.x1 = x1, node.y1 = y1;
  12272. return;
  12273. }
  12274. var valueOffset = sums[i],
  12275. valueTarget = (value / 2) + valueOffset,
  12276. k = i + 1,
  12277. hi = j - 1;
  12278. while (k < hi) {
  12279. var mid = k + hi >>> 1;
  12280. if (sums[mid] < valueTarget) k = mid + 1;
  12281. else hi = mid;
  12282. }
  12283. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  12284. var valueLeft = sums[k] - valueOffset,
  12285. valueRight = value - valueLeft;
  12286. if ((x1 - x0) > (y1 - y0)) {
  12287. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  12288. partition(i, k, valueLeft, x0, y0, xk, y1);
  12289. partition(k, j, valueRight, xk, y0, x1, y1);
  12290. } else {
  12291. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  12292. partition(i, k, valueLeft, x0, y0, x1, yk);
  12293. partition(k, j, valueRight, x0, yk, x1, y1);
  12294. }
  12295. }
  12296. }
  12297. function sliceDice(parent, x0, y0, x1, y1) {
  12298. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  12299. }
  12300. var resquarify = (function custom(ratio) {
  12301. function resquarify(parent, x0, y0, x1, y1) {
  12302. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  12303. var rows,
  12304. row,
  12305. nodes,
  12306. i,
  12307. j = -1,
  12308. n,
  12309. m = rows.length,
  12310. value = parent.value;
  12311. while (++j < m) {
  12312. row = rows[j], nodes = row.children;
  12313. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  12314. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
  12315. else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
  12316. value -= row.value;
  12317. }
  12318. } else {
  12319. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12320. rows.ratio = ratio;
  12321. }
  12322. }
  12323. resquarify.ratio = function(x) {
  12324. return custom((x = +x) > 1 ? x : 1);
  12325. };
  12326. return resquarify;
  12327. })(phi);
  12328. function area$1(polygon) {
  12329. var i = -1,
  12330. n = polygon.length,
  12331. a,
  12332. b = polygon[n - 1],
  12333. area = 0;
  12334. while (++i < n) {
  12335. a = b;
  12336. b = polygon[i];
  12337. area += a[1] * b[0] - a[0] * b[1];
  12338. }
  12339. return area / 2;
  12340. }
  12341. function centroid(polygon) {
  12342. var i = -1,
  12343. n = polygon.length,
  12344. x = 0,
  12345. y = 0,
  12346. a,
  12347. b = polygon[n - 1],
  12348. c,
  12349. k = 0;
  12350. while (++i < n) {
  12351. a = b;
  12352. b = polygon[i];
  12353. k += c = a[0] * b[1] - b[0] * a[1];
  12354. x += (a[0] + b[0]) * c;
  12355. y += (a[1] + b[1]) * c;
  12356. }
  12357. return k *= 3, [x / k, y / k];
  12358. }
  12359. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  12360. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  12361. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  12362. // negative if clockwise, and zero if the points are collinear.
  12363. function cross$1(a, b, c) {
  12364. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  12365. }
  12366. function lexicographicOrder(a, b) {
  12367. return a[0] - b[0] || a[1] - b[1];
  12368. }
  12369. // Computes the upper convex hull per the monotone chain algorithm.
  12370. // Assumes points.length >= 3, is sorted by x, unique in y.
  12371. // Returns an array of indices into points in left-to-right order.
  12372. function computeUpperHullIndexes(points) {
  12373. const n = points.length,
  12374. indexes = [0, 1];
  12375. let size = 2, i;
  12376. for (i = 2; i < n; ++i) {
  12377. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  12378. indexes[size++] = i;
  12379. }
  12380. return indexes.slice(0, size); // remove popped points
  12381. }
  12382. function hull(points) {
  12383. if ((n = points.length) < 3) return null;
  12384. var i,
  12385. n,
  12386. sortedPoints = new Array(n),
  12387. flippedPoints = new Array(n);
  12388. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  12389. sortedPoints.sort(lexicographicOrder);
  12390. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  12391. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  12392. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  12393. // Construct the hull polygon, removing possible duplicate endpoints.
  12394. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  12395. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  12396. hull = [];
  12397. // Add upper hull in right-to-l order.
  12398. // Then add lower hull in left-to-right order.
  12399. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  12400. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  12401. return hull;
  12402. }
  12403. function contains(polygon, point) {
  12404. var n = polygon.length,
  12405. p = polygon[n - 1],
  12406. x = point[0], y = point[1],
  12407. x0 = p[0], y0 = p[1],
  12408. x1, y1,
  12409. inside = false;
  12410. for (var i = 0; i < n; ++i) {
  12411. p = polygon[i], x1 = p[0], y1 = p[1];
  12412. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  12413. x0 = x1, y0 = y1;
  12414. }
  12415. return inside;
  12416. }
  12417. function length(polygon) {
  12418. var i = -1,
  12419. n = polygon.length,
  12420. b = polygon[n - 1],
  12421. xa,
  12422. ya,
  12423. xb = b[0],
  12424. yb = b[1],
  12425. perimeter = 0;
  12426. while (++i < n) {
  12427. xa = xb;
  12428. ya = yb;
  12429. b = polygon[i];
  12430. xb = b[0];
  12431. yb = b[1];
  12432. xa -= xb;
  12433. ya -= yb;
  12434. perimeter += Math.hypot(xa, ya);
  12435. }
  12436. return perimeter;
  12437. }
  12438. var defaultSource = Math.random;
  12439. var uniform = (function sourceRandomUniform(source) {
  12440. function randomUniform(min, max) {
  12441. min = min == null ? 0 : +min;
  12442. max = max == null ? 1 : +max;
  12443. if (arguments.length === 1) max = min, min = 0;
  12444. else max -= min;
  12445. return function() {
  12446. return source() * max + min;
  12447. };
  12448. }
  12449. randomUniform.source = sourceRandomUniform;
  12450. return randomUniform;
  12451. })(defaultSource);
  12452. var int = (function sourceRandomInt(source) {
  12453. function randomInt(min, max) {
  12454. if (arguments.length < 2) max = min, min = 0;
  12455. min = Math.floor(min);
  12456. max = Math.floor(max) - min;
  12457. return function() {
  12458. return Math.floor(source() * max + min);
  12459. };
  12460. }
  12461. randomInt.source = sourceRandomInt;
  12462. return randomInt;
  12463. })(defaultSource);
  12464. var normal = (function sourceRandomNormal(source) {
  12465. function randomNormal(mu, sigma) {
  12466. var x, r;
  12467. mu = mu == null ? 0 : +mu;
  12468. sigma = sigma == null ? 1 : +sigma;
  12469. return function() {
  12470. var y;
  12471. // If available, use the second previously-generated uniform random.
  12472. if (x != null) y = x, x = null;
  12473. // Otherwise, generate a new x and y.
  12474. else do {
  12475. x = source() * 2 - 1;
  12476. y = source() * 2 - 1;
  12477. r = x * x + y * y;
  12478. } while (!r || r > 1);
  12479. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  12480. };
  12481. }
  12482. randomNormal.source = sourceRandomNormal;
  12483. return randomNormal;
  12484. })(defaultSource);
  12485. var logNormal = (function sourceRandomLogNormal(source) {
  12486. var N = normal.source(source);
  12487. function randomLogNormal() {
  12488. var randomNormal = N.apply(this, arguments);
  12489. return function() {
  12490. return Math.exp(randomNormal());
  12491. };
  12492. }
  12493. randomLogNormal.source = sourceRandomLogNormal;
  12494. return randomLogNormal;
  12495. })(defaultSource);
  12496. var irwinHall = (function sourceRandomIrwinHall(source) {
  12497. function randomIrwinHall(n) {
  12498. if ((n = +n) <= 0) return () => 0;
  12499. return function() {
  12500. for (var sum = 0, i = n; i > 1; --i) sum += source();
  12501. return sum + i * source();
  12502. };
  12503. }
  12504. randomIrwinHall.source = sourceRandomIrwinHall;
  12505. return randomIrwinHall;
  12506. })(defaultSource);
  12507. var bates = (function sourceRandomBates(source) {
  12508. var I = irwinHall.source(source);
  12509. function randomBates(n) {
  12510. // use limiting distribution at n === 0
  12511. if ((n = +n) === 0) return source;
  12512. var randomIrwinHall = I(n);
  12513. return function() {
  12514. return randomIrwinHall() / n;
  12515. };
  12516. }
  12517. randomBates.source = sourceRandomBates;
  12518. return randomBates;
  12519. })(defaultSource);
  12520. var exponential = (function sourceRandomExponential(source) {
  12521. function randomExponential(lambda) {
  12522. return function() {
  12523. return -Math.log1p(-source()) / lambda;
  12524. };
  12525. }
  12526. randomExponential.source = sourceRandomExponential;
  12527. return randomExponential;
  12528. })(defaultSource);
  12529. var pareto = (function sourceRandomPareto(source) {
  12530. function randomPareto(alpha) {
  12531. if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
  12532. alpha = 1 / -alpha;
  12533. return function() {
  12534. return Math.pow(1 - source(), alpha);
  12535. };
  12536. }
  12537. randomPareto.source = sourceRandomPareto;
  12538. return randomPareto;
  12539. })(defaultSource);
  12540. var bernoulli = (function sourceRandomBernoulli(source) {
  12541. function randomBernoulli(p) {
  12542. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12543. return function() {
  12544. return Math.floor(source() + p);
  12545. };
  12546. }
  12547. randomBernoulli.source = sourceRandomBernoulli;
  12548. return randomBernoulli;
  12549. })(defaultSource);
  12550. var geometric = (function sourceRandomGeometric(source) {
  12551. function randomGeometric(p) {
  12552. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12553. if (p === 0) return () => Infinity;
  12554. if (p === 1) return () => 1;
  12555. p = Math.log1p(-p);
  12556. return function() {
  12557. return 1 + Math.floor(Math.log1p(-source()) / p);
  12558. };
  12559. }
  12560. randomGeometric.source = sourceRandomGeometric;
  12561. return randomGeometric;
  12562. })(defaultSource);
  12563. var gamma = (function sourceRandomGamma(source) {
  12564. var randomNormal = normal.source(source)();
  12565. function randomGamma(k, theta) {
  12566. if ((k = +k) < 0) throw new RangeError("invalid k");
  12567. // degenerate distribution if k === 0
  12568. if (k === 0) return () => 0;
  12569. theta = theta == null ? 1 : +theta;
  12570. // exponential distribution if k === 1
  12571. if (k === 1) return () => -Math.log1p(-source()) * theta;
  12572. var d = (k < 1 ? k + 1 : k) - 1 / 3,
  12573. c = 1 / (3 * Math.sqrt(d)),
  12574. multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
  12575. return function() {
  12576. do {
  12577. do {
  12578. var x = randomNormal(),
  12579. v = 1 + c * x;
  12580. } while (v <= 0);
  12581. v *= v * v;
  12582. var u = 1 - source();
  12583. } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
  12584. return d * v * multiplier() * theta;
  12585. };
  12586. }
  12587. randomGamma.source = sourceRandomGamma;
  12588. return randomGamma;
  12589. })(defaultSource);
  12590. var beta = (function sourceRandomBeta(source) {
  12591. var G = gamma.source(source);
  12592. function randomBeta(alpha, beta) {
  12593. var X = G(alpha),
  12594. Y = G(beta);
  12595. return function() {
  12596. var x = X();
  12597. return x === 0 ? 0 : x / (x + Y());
  12598. };
  12599. }
  12600. randomBeta.source = sourceRandomBeta;
  12601. return randomBeta;
  12602. })(defaultSource);
  12603. var binomial = (function sourceRandomBinomial(source) {
  12604. var G = geometric.source(source),
  12605. B = beta.source(source);
  12606. function randomBinomial(n, p) {
  12607. n = +n;
  12608. if ((p = +p) >= 1) return () => n;
  12609. if (p <= 0) return () => 0;
  12610. return function() {
  12611. var acc = 0, nn = n, pp = p;
  12612. while (nn * pp > 16 && nn * (1 - pp) > 16) {
  12613. var i = Math.floor((nn + 1) * pp),
  12614. y = B(i, nn - i + 1)();
  12615. if (y <= pp) {
  12616. acc += i;
  12617. nn -= i;
  12618. pp = (pp - y) / (1 - y);
  12619. } else {
  12620. nn = i - 1;
  12621. pp /= y;
  12622. }
  12623. }
  12624. var sign = pp < 0.5,
  12625. pFinal = sign ? pp : 1 - pp,
  12626. g = G(pFinal);
  12627. for (var s = g(), k = 0; s <= nn; ++k) s += g();
  12628. return acc + (sign ? k : nn - k);
  12629. };
  12630. }
  12631. randomBinomial.source = sourceRandomBinomial;
  12632. return randomBinomial;
  12633. })(defaultSource);
  12634. var weibull = (function sourceRandomWeibull(source) {
  12635. function randomWeibull(k, a, b) {
  12636. var outerFunc;
  12637. if ((k = +k) === 0) {
  12638. outerFunc = x => -Math.log(x);
  12639. } else {
  12640. k = 1 / k;
  12641. outerFunc = x => Math.pow(x, k);
  12642. }
  12643. a = a == null ? 0 : +a;
  12644. b = b == null ? 1 : +b;
  12645. return function() {
  12646. return a + b * outerFunc(-Math.log1p(-source()));
  12647. };
  12648. }
  12649. randomWeibull.source = sourceRandomWeibull;
  12650. return randomWeibull;
  12651. })(defaultSource);
  12652. var cauchy = (function sourceRandomCauchy(source) {
  12653. function randomCauchy(a, b) {
  12654. a = a == null ? 0 : +a;
  12655. b = b == null ? 1 : +b;
  12656. return function() {
  12657. return a + b * Math.tan(Math.PI * source());
  12658. };
  12659. }
  12660. randomCauchy.source = sourceRandomCauchy;
  12661. return randomCauchy;
  12662. })(defaultSource);
  12663. var logistic = (function sourceRandomLogistic(source) {
  12664. function randomLogistic(a, b) {
  12665. a = a == null ? 0 : +a;
  12666. b = b == null ? 1 : +b;
  12667. return function() {
  12668. var u = source();
  12669. return a + b * Math.log(u / (1 - u));
  12670. };
  12671. }
  12672. randomLogistic.source = sourceRandomLogistic;
  12673. return randomLogistic;
  12674. })(defaultSource);
  12675. var poisson = (function sourceRandomPoisson(source) {
  12676. var G = gamma.source(source),
  12677. B = binomial.source(source);
  12678. function randomPoisson(lambda) {
  12679. return function() {
  12680. var acc = 0, l = lambda;
  12681. while (l > 16) {
  12682. var n = Math.floor(0.875 * l),
  12683. t = G(n)();
  12684. if (t > l) return acc + B(n - 1, l / t)();
  12685. acc += n;
  12686. l -= t;
  12687. }
  12688. for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
  12689. return acc + k;
  12690. };
  12691. }
  12692. randomPoisson.source = sourceRandomPoisson;
  12693. return randomPoisson;
  12694. })(defaultSource);
  12695. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  12696. const mul = 0x19660D;
  12697. const inc = 0x3C6EF35F;
  12698. const eps = 1 / 0x100000000;
  12699. function lcg(seed = Math.random()) {
  12700. let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
  12701. return () => (state = mul * state + inc | 0, eps * (state >>> 0));
  12702. }
  12703. function initRange(domain, range) {
  12704. switch (arguments.length) {
  12705. case 0: break;
  12706. case 1: this.range(domain); break;
  12707. default: this.range(range).domain(domain); break;
  12708. }
  12709. return this;
  12710. }
  12711. function initInterpolator(domain, interpolator) {
  12712. switch (arguments.length) {
  12713. case 0: break;
  12714. case 1: {
  12715. if (typeof domain === "function") this.interpolator(domain);
  12716. else this.range(domain);
  12717. break;
  12718. }
  12719. default: {
  12720. this.domain(domain);
  12721. if (typeof interpolator === "function") this.interpolator(interpolator);
  12722. else this.range(interpolator);
  12723. break;
  12724. }
  12725. }
  12726. return this;
  12727. }
  12728. const implicit = Symbol("implicit");
  12729. function ordinal() {
  12730. var index = new InternMap(),
  12731. domain = [],
  12732. range = [],
  12733. unknown = implicit;
  12734. function scale(d) {
  12735. let i = index.get(d);
  12736. if (i === undefined) {
  12737. if (unknown !== implicit) return unknown;
  12738. index.set(d, i = domain.push(d) - 1);
  12739. }
  12740. return range[i % range.length];
  12741. }
  12742. scale.domain = function(_) {
  12743. if (!arguments.length) return domain.slice();
  12744. domain = [], index = new InternMap();
  12745. for (const value of _) {
  12746. if (index.has(value)) continue;
  12747. index.set(value, domain.push(value) - 1);
  12748. }
  12749. return scale;
  12750. };
  12751. scale.range = function(_) {
  12752. return arguments.length ? (range = Array.from(_), scale) : range.slice();
  12753. };
  12754. scale.unknown = function(_) {
  12755. return arguments.length ? (unknown = _, scale) : unknown;
  12756. };
  12757. scale.copy = function() {
  12758. return ordinal(domain, range).unknown(unknown);
  12759. };
  12760. initRange.apply(scale, arguments);
  12761. return scale;
  12762. }
  12763. function band() {
  12764. var scale = ordinal().unknown(undefined),
  12765. domain = scale.domain,
  12766. ordinalRange = scale.range,
  12767. r0 = 0,
  12768. r1 = 1,
  12769. step,
  12770. bandwidth,
  12771. round = false,
  12772. paddingInner = 0,
  12773. paddingOuter = 0,
  12774. align = 0.5;
  12775. delete scale.unknown;
  12776. function rescale() {
  12777. var n = domain().length,
  12778. reverse = r1 < r0,
  12779. start = reverse ? r1 : r0,
  12780. stop = reverse ? r0 : r1;
  12781. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  12782. if (round) step = Math.floor(step);
  12783. start += (stop - start - step * (n - paddingInner)) * align;
  12784. bandwidth = step * (1 - paddingInner);
  12785. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  12786. var values = range$2(n).map(function(i) { return start + step * i; });
  12787. return ordinalRange(reverse ? values.reverse() : values);
  12788. }
  12789. scale.domain = function(_) {
  12790. return arguments.length ? (domain(_), rescale()) : domain();
  12791. };
  12792. scale.range = function(_) {
  12793. return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
  12794. };
  12795. scale.rangeRound = function(_) {
  12796. return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
  12797. };
  12798. scale.bandwidth = function() {
  12799. return bandwidth;
  12800. };
  12801. scale.step = function() {
  12802. return step;
  12803. };
  12804. scale.round = function(_) {
  12805. return arguments.length ? (round = !!_, rescale()) : round;
  12806. };
  12807. scale.padding = function(_) {
  12808. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  12809. };
  12810. scale.paddingInner = function(_) {
  12811. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  12812. };
  12813. scale.paddingOuter = function(_) {
  12814. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  12815. };
  12816. scale.align = function(_) {
  12817. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  12818. };
  12819. scale.copy = function() {
  12820. return band(domain(), [r0, r1])
  12821. .round(round)
  12822. .paddingInner(paddingInner)
  12823. .paddingOuter(paddingOuter)
  12824. .align(align);
  12825. };
  12826. return initRange.apply(rescale(), arguments);
  12827. }
  12828. function pointish(scale) {
  12829. var copy = scale.copy;
  12830. scale.padding = scale.paddingOuter;
  12831. delete scale.paddingInner;
  12832. delete scale.paddingOuter;
  12833. scale.copy = function() {
  12834. return pointish(copy());
  12835. };
  12836. return scale;
  12837. }
  12838. function point$4() {
  12839. return pointish(band.apply(null, arguments).paddingInner(1));
  12840. }
  12841. function constants(x) {
  12842. return function() {
  12843. return x;
  12844. };
  12845. }
  12846. function number$1(x) {
  12847. return +x;
  12848. }
  12849. var unit = [0, 1];
  12850. function identity$3(x) {
  12851. return x;
  12852. }
  12853. function normalize(a, b) {
  12854. return (b -= (a = +a))
  12855. ? function(x) { return (x - a) / b; }
  12856. : constants(isNaN(b) ? NaN : 0.5);
  12857. }
  12858. function clamper(a, b) {
  12859. var t;
  12860. if (a > b) t = a, a = b, b = t;
  12861. return function(x) { return Math.max(a, Math.min(b, x)); };
  12862. }
  12863. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  12864. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  12865. function bimap(domain, range, interpolate) {
  12866. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  12867. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  12868. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  12869. return function(x) { return r0(d0(x)); };
  12870. }
  12871. function polymap(domain, range, interpolate) {
  12872. var j = Math.min(domain.length, range.length) - 1,
  12873. d = new Array(j),
  12874. r = new Array(j),
  12875. i = -1;
  12876. // Reverse descending domains.
  12877. if (domain[j] < domain[0]) {
  12878. domain = domain.slice().reverse();
  12879. range = range.slice().reverse();
  12880. }
  12881. while (++i < j) {
  12882. d[i] = normalize(domain[i], domain[i + 1]);
  12883. r[i] = interpolate(range[i], range[i + 1]);
  12884. }
  12885. return function(x) {
  12886. var i = bisect(domain, x, 1, j) - 1;
  12887. return r[i](d[i](x));
  12888. };
  12889. }
  12890. function copy$1(source, target) {
  12891. return target
  12892. .domain(source.domain())
  12893. .range(source.range())
  12894. .interpolate(source.interpolate())
  12895. .clamp(source.clamp())
  12896. .unknown(source.unknown());
  12897. }
  12898. function transformer$2() {
  12899. var domain = unit,
  12900. range = unit,
  12901. interpolate = interpolate$2,
  12902. transform,
  12903. untransform,
  12904. unknown,
  12905. clamp = identity$3,
  12906. piecewise,
  12907. output,
  12908. input;
  12909. function rescale() {
  12910. var n = Math.min(domain.length, range.length);
  12911. if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
  12912. piecewise = n > 2 ? polymap : bimap;
  12913. output = input = null;
  12914. return scale;
  12915. }
  12916. function scale(x) {
  12917. return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  12918. }
  12919. scale.invert = function(y) {
  12920. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  12921. };
  12922. scale.domain = function(_) {
  12923. return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
  12924. };
  12925. scale.range = function(_) {
  12926. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  12927. };
  12928. scale.rangeRound = function(_) {
  12929. return range = Array.from(_), interpolate = interpolateRound, rescale();
  12930. };
  12931. scale.clamp = function(_) {
  12932. return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
  12933. };
  12934. scale.interpolate = function(_) {
  12935. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  12936. };
  12937. scale.unknown = function(_) {
  12938. return arguments.length ? (unknown = _, scale) : unknown;
  12939. };
  12940. return function(t, u) {
  12941. transform = t, untransform = u;
  12942. return rescale();
  12943. };
  12944. }
  12945. function continuous() {
  12946. return transformer$2()(identity$3, identity$3);
  12947. }
  12948. function tickFormat(start, stop, count, specifier) {
  12949. var step = tickStep(start, stop, count),
  12950. precision;
  12951. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  12952. switch (specifier.type) {
  12953. case "s": {
  12954. var value = Math.max(Math.abs(start), Math.abs(stop));
  12955. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  12956. return exports.formatPrefix(specifier, value);
  12957. }
  12958. case "":
  12959. case "e":
  12960. case "g":
  12961. case "p":
  12962. case "r": {
  12963. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  12964. break;
  12965. }
  12966. case "f":
  12967. case "%": {
  12968. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  12969. break;
  12970. }
  12971. }
  12972. return exports.format(specifier);
  12973. }
  12974. function linearish(scale) {
  12975. var domain = scale.domain;
  12976. scale.ticks = function(count) {
  12977. var d = domain();
  12978. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  12979. };
  12980. scale.tickFormat = function(count, specifier) {
  12981. var d = domain();
  12982. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  12983. };
  12984. scale.nice = function(count) {
  12985. if (count == null) count = 10;
  12986. var d = domain();
  12987. var i0 = 0;
  12988. var i1 = d.length - 1;
  12989. var start = d[i0];
  12990. var stop = d[i1];
  12991. var prestep;
  12992. var step;
  12993. var maxIter = 10;
  12994. if (stop < start) {
  12995. step = start, start = stop, stop = step;
  12996. step = i0, i0 = i1, i1 = step;
  12997. }
  12998. while (maxIter-- > 0) {
  12999. step = tickIncrement(start, stop, count);
  13000. if (step === prestep) {
  13001. d[i0] = start;
  13002. d[i1] = stop;
  13003. return domain(d);
  13004. } else if (step > 0) {
  13005. start = Math.floor(start / step) * step;
  13006. stop = Math.ceil(stop / step) * step;
  13007. } else if (step < 0) {
  13008. start = Math.ceil(start * step) / step;
  13009. stop = Math.floor(stop * step) / step;
  13010. } else {
  13011. break;
  13012. }
  13013. prestep = step;
  13014. }
  13015. return scale;
  13016. };
  13017. return scale;
  13018. }
  13019. function linear() {
  13020. var scale = continuous();
  13021. scale.copy = function() {
  13022. return copy$1(scale, linear());
  13023. };
  13024. initRange.apply(scale, arguments);
  13025. return linearish(scale);
  13026. }
  13027. function identity$2(domain) {
  13028. var unknown;
  13029. function scale(x) {
  13030. return x == null || isNaN(x = +x) ? unknown : x;
  13031. }
  13032. scale.invert = scale;
  13033. scale.domain = scale.range = function(_) {
  13034. return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
  13035. };
  13036. scale.unknown = function(_) {
  13037. return arguments.length ? (unknown = _, scale) : unknown;
  13038. };
  13039. scale.copy = function() {
  13040. return identity$2(domain).unknown(unknown);
  13041. };
  13042. domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
  13043. return linearish(scale);
  13044. }
  13045. function nice(domain, interval) {
  13046. domain = domain.slice();
  13047. var i0 = 0,
  13048. i1 = domain.length - 1,
  13049. x0 = domain[i0],
  13050. x1 = domain[i1],
  13051. t;
  13052. if (x1 < x0) {
  13053. t = i0, i0 = i1, i1 = t;
  13054. t = x0, x0 = x1, x1 = t;
  13055. }
  13056. domain[i0] = interval.floor(x0);
  13057. domain[i1] = interval.ceil(x1);
  13058. return domain;
  13059. }
  13060. function transformLog(x) {
  13061. return Math.log(x);
  13062. }
  13063. function transformExp(x) {
  13064. return Math.exp(x);
  13065. }
  13066. function transformLogn(x) {
  13067. return -Math.log(-x);
  13068. }
  13069. function transformExpn(x) {
  13070. return -Math.exp(-x);
  13071. }
  13072. function pow10(x) {
  13073. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  13074. }
  13075. function powp(base) {
  13076. return base === 10 ? pow10
  13077. : base === Math.E ? Math.exp
  13078. : x => Math.pow(base, x);
  13079. }
  13080. function logp(base) {
  13081. return base === Math.E ? Math.log
  13082. : base === 10 && Math.log10
  13083. || base === 2 && Math.log2
  13084. || (base = Math.log(base), x => Math.log(x) / base);
  13085. }
  13086. function reflect(f) {
  13087. return (x, k) => -f(-x, k);
  13088. }
  13089. function loggish(transform) {
  13090. const scale = transform(transformLog, transformExp);
  13091. const domain = scale.domain;
  13092. let base = 10;
  13093. let logs;
  13094. let pows;
  13095. function rescale() {
  13096. logs = logp(base), pows = powp(base);
  13097. if (domain()[0] < 0) {
  13098. logs = reflect(logs), pows = reflect(pows);
  13099. transform(transformLogn, transformExpn);
  13100. } else {
  13101. transform(transformLog, transformExp);
  13102. }
  13103. return scale;
  13104. }
  13105. scale.base = function(_) {
  13106. return arguments.length ? (base = +_, rescale()) : base;
  13107. };
  13108. scale.domain = function(_) {
  13109. return arguments.length ? (domain(_), rescale()) : domain();
  13110. };
  13111. scale.ticks = count => {
  13112. const d = domain();
  13113. let u = d[0];
  13114. let v = d[d.length - 1];
  13115. const r = v < u;
  13116. if (r) ([u, v] = [v, u]);
  13117. let i = logs(u);
  13118. let j = logs(v);
  13119. let k;
  13120. let t;
  13121. const n = count == null ? 10 : +count;
  13122. let z = [];
  13123. if (!(base % 1) && j - i < n) {
  13124. i = Math.floor(i), j = Math.ceil(j);
  13125. if (u > 0) for (; i <= j; ++i) {
  13126. for (k = 1; k < base; ++k) {
  13127. t = i < 0 ? k / pows(-i) : k * pows(i);
  13128. if (t < u) continue;
  13129. if (t > v) break;
  13130. z.push(t);
  13131. }
  13132. } else for (; i <= j; ++i) {
  13133. for (k = base - 1; k >= 1; --k) {
  13134. t = i > 0 ? k / pows(-i) : k * pows(i);
  13135. if (t < u) continue;
  13136. if (t > v) break;
  13137. z.push(t);
  13138. }
  13139. }
  13140. if (z.length * 2 < n) z = ticks(u, v, n);
  13141. } else {
  13142. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  13143. }
  13144. return r ? z.reverse() : z;
  13145. };
  13146. scale.tickFormat = (count, specifier) => {
  13147. if (count == null) count = 10;
  13148. if (specifier == null) specifier = base === 10 ? "s" : ",";
  13149. if (typeof specifier !== "function") {
  13150. if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true;
  13151. specifier = exports.format(specifier);
  13152. }
  13153. if (count === Infinity) return specifier;
  13154. const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  13155. return d => {
  13156. let i = d / pows(Math.round(logs(d)));
  13157. if (i * base < base - 0.5) i *= base;
  13158. return i <= k ? specifier(d) : "";
  13159. };
  13160. };
  13161. scale.nice = () => {
  13162. return domain(nice(domain(), {
  13163. floor: x => pows(Math.floor(logs(x))),
  13164. ceil: x => pows(Math.ceil(logs(x)))
  13165. }));
  13166. };
  13167. return scale;
  13168. }
  13169. function log() {
  13170. const scale = loggish(transformer$2()).domain([1, 10]);
  13171. scale.copy = () => copy$1(scale, log()).base(scale.base());
  13172. initRange.apply(scale, arguments);
  13173. return scale;
  13174. }
  13175. function transformSymlog(c) {
  13176. return function(x) {
  13177. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  13178. };
  13179. }
  13180. function transformSymexp(c) {
  13181. return function(x) {
  13182. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  13183. };
  13184. }
  13185. function symlogish(transform) {
  13186. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  13187. scale.constant = function(_) {
  13188. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  13189. };
  13190. return linearish(scale);
  13191. }
  13192. function symlog() {
  13193. var scale = symlogish(transformer$2());
  13194. scale.copy = function() {
  13195. return copy$1(scale, symlog()).constant(scale.constant());
  13196. };
  13197. return initRange.apply(scale, arguments);
  13198. }
  13199. function transformPow(exponent) {
  13200. return function(x) {
  13201. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  13202. };
  13203. }
  13204. function transformSqrt(x) {
  13205. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  13206. }
  13207. function transformSquare(x) {
  13208. return x < 0 ? -x * x : x * x;
  13209. }
  13210. function powish(transform) {
  13211. var scale = transform(identity$3, identity$3),
  13212. exponent = 1;
  13213. function rescale() {
  13214. return exponent === 1 ? transform(identity$3, identity$3)
  13215. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  13216. : transform(transformPow(exponent), transformPow(1 / exponent));
  13217. }
  13218. scale.exponent = function(_) {
  13219. return arguments.length ? (exponent = +_, rescale()) : exponent;
  13220. };
  13221. return linearish(scale);
  13222. }
  13223. function pow() {
  13224. var scale = powish(transformer$2());
  13225. scale.copy = function() {
  13226. return copy$1(scale, pow()).exponent(scale.exponent());
  13227. };
  13228. initRange.apply(scale, arguments);
  13229. return scale;
  13230. }
  13231. function sqrt$1() {
  13232. return pow.apply(null, arguments).exponent(0.5);
  13233. }
  13234. function square$1(x) {
  13235. return Math.sign(x) * x * x;
  13236. }
  13237. function unsquare(x) {
  13238. return Math.sign(x) * Math.sqrt(Math.abs(x));
  13239. }
  13240. function radial() {
  13241. var squared = continuous(),
  13242. range = [0, 1],
  13243. round = false,
  13244. unknown;
  13245. function scale(x) {
  13246. var y = unsquare(squared(x));
  13247. return isNaN(y) ? unknown : round ? Math.round(y) : y;
  13248. }
  13249. scale.invert = function(y) {
  13250. return squared.invert(square$1(y));
  13251. };
  13252. scale.domain = function(_) {
  13253. return arguments.length ? (squared.domain(_), scale) : squared.domain();
  13254. };
  13255. scale.range = function(_) {
  13256. return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
  13257. };
  13258. scale.rangeRound = function(_) {
  13259. return scale.range(_).round(true);
  13260. };
  13261. scale.round = function(_) {
  13262. return arguments.length ? (round = !!_, scale) : round;
  13263. };
  13264. scale.clamp = function(_) {
  13265. return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
  13266. };
  13267. scale.unknown = function(_) {
  13268. return arguments.length ? (unknown = _, scale) : unknown;
  13269. };
  13270. scale.copy = function() {
  13271. return radial(squared.domain(), range)
  13272. .round(round)
  13273. .clamp(squared.clamp())
  13274. .unknown(unknown);
  13275. };
  13276. initRange.apply(scale, arguments);
  13277. return linearish(scale);
  13278. }
  13279. function quantile() {
  13280. var domain = [],
  13281. range = [],
  13282. thresholds = [],
  13283. unknown;
  13284. function rescale() {
  13285. var i = 0, n = Math.max(1, range.length);
  13286. thresholds = new Array(n - 1);
  13287. while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
  13288. return scale;
  13289. }
  13290. function scale(x) {
  13291. return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
  13292. }
  13293. scale.invertExtent = function(y) {
  13294. var i = range.indexOf(y);
  13295. return i < 0 ? [NaN, NaN] : [
  13296. i > 0 ? thresholds[i - 1] : domain[0],
  13297. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  13298. ];
  13299. };
  13300. scale.domain = function(_) {
  13301. if (!arguments.length) return domain.slice();
  13302. domain = [];
  13303. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  13304. domain.sort(ascending$3);
  13305. return rescale();
  13306. };
  13307. scale.range = function(_) {
  13308. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  13309. };
  13310. scale.unknown = function(_) {
  13311. return arguments.length ? (unknown = _, scale) : unknown;
  13312. };
  13313. scale.quantiles = function() {
  13314. return thresholds.slice();
  13315. };
  13316. scale.copy = function() {
  13317. return quantile()
  13318. .domain(domain)
  13319. .range(range)
  13320. .unknown(unknown);
  13321. };
  13322. return initRange.apply(scale, arguments);
  13323. }
  13324. function quantize() {
  13325. var x0 = 0,
  13326. x1 = 1,
  13327. n = 1,
  13328. domain = [0.5],
  13329. range = [0, 1],
  13330. unknown;
  13331. function scale(x) {
  13332. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13333. }
  13334. function rescale() {
  13335. var i = -1;
  13336. domain = new Array(n);
  13337. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  13338. return scale;
  13339. }
  13340. scale.domain = function(_) {
  13341. return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
  13342. };
  13343. scale.range = function(_) {
  13344. return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
  13345. };
  13346. scale.invertExtent = function(y) {
  13347. var i = range.indexOf(y);
  13348. return i < 0 ? [NaN, NaN]
  13349. : i < 1 ? [x0, domain[0]]
  13350. : i >= n ? [domain[n - 1], x1]
  13351. : [domain[i - 1], domain[i]];
  13352. };
  13353. scale.unknown = function(_) {
  13354. return arguments.length ? (unknown = _, scale) : scale;
  13355. };
  13356. scale.thresholds = function() {
  13357. return domain.slice();
  13358. };
  13359. scale.copy = function() {
  13360. return quantize()
  13361. .domain([x0, x1])
  13362. .range(range)
  13363. .unknown(unknown);
  13364. };
  13365. return initRange.apply(linearish(scale), arguments);
  13366. }
  13367. function threshold() {
  13368. var domain = [0.5],
  13369. range = [0, 1],
  13370. unknown,
  13371. n = 1;
  13372. function scale(x) {
  13373. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13374. }
  13375. scale.domain = function(_) {
  13376. return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  13377. };
  13378. scale.range = function(_) {
  13379. return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  13380. };
  13381. scale.invertExtent = function(y) {
  13382. var i = range.indexOf(y);
  13383. return [domain[i - 1], domain[i]];
  13384. };
  13385. scale.unknown = function(_) {
  13386. return arguments.length ? (unknown = _, scale) : unknown;
  13387. };
  13388. scale.copy = function() {
  13389. return threshold()
  13390. .domain(domain)
  13391. .range(range)
  13392. .unknown(unknown);
  13393. };
  13394. return initRange.apply(scale, arguments);
  13395. }
  13396. const t0 = new Date, t1 = new Date;
  13397. function timeInterval(floori, offseti, count, field) {
  13398. function interval(date) {
  13399. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  13400. }
  13401. interval.floor = (date) => {
  13402. return floori(date = new Date(+date)), date;
  13403. };
  13404. interval.ceil = (date) => {
  13405. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  13406. };
  13407. interval.round = (date) => {
  13408. const d0 = interval(date), d1 = interval.ceil(date);
  13409. return date - d0 < d1 - date ? d0 : d1;
  13410. };
  13411. interval.offset = (date, step) => {
  13412. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  13413. };
  13414. interval.range = (start, stop, step) => {
  13415. const range = [];
  13416. start = interval.ceil(start);
  13417. step = step == null ? 1 : Math.floor(step);
  13418. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  13419. let previous;
  13420. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  13421. while (previous < start && start < stop);
  13422. return range;
  13423. };
  13424. interval.filter = (test) => {
  13425. return timeInterval((date) => {
  13426. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  13427. }, (date, step) => {
  13428. if (date >= date) {
  13429. if (step < 0) while (++step <= 0) {
  13430. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  13431. } else while (--step >= 0) {
  13432. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  13433. }
  13434. }
  13435. });
  13436. };
  13437. if (count) {
  13438. interval.count = (start, end) => {
  13439. t0.setTime(+start), t1.setTime(+end);
  13440. floori(t0), floori(t1);
  13441. return Math.floor(count(t0, t1));
  13442. };
  13443. interval.every = (step) => {
  13444. step = Math.floor(step);
  13445. return !isFinite(step) || !(step > 0) ? null
  13446. : !(step > 1) ? interval
  13447. : interval.filter(field
  13448. ? (d) => field(d) % step === 0
  13449. : (d) => interval.count(0, d) % step === 0);
  13450. };
  13451. }
  13452. return interval;
  13453. }
  13454. const millisecond = timeInterval(() => {
  13455. // noop
  13456. }, (date, step) => {
  13457. date.setTime(+date + step);
  13458. }, (start, end) => {
  13459. return end - start;
  13460. });
  13461. // An optimized implementation for this simple case.
  13462. millisecond.every = (k) => {
  13463. k = Math.floor(k);
  13464. if (!isFinite(k) || !(k > 0)) return null;
  13465. if (!(k > 1)) return millisecond;
  13466. return timeInterval((date) => {
  13467. date.setTime(Math.floor(date / k) * k);
  13468. }, (date, step) => {
  13469. date.setTime(+date + step * k);
  13470. }, (start, end) => {
  13471. return (end - start) / k;
  13472. });
  13473. };
  13474. const milliseconds = millisecond.range;
  13475. const durationSecond = 1000;
  13476. const durationMinute = durationSecond * 60;
  13477. const durationHour = durationMinute * 60;
  13478. const durationDay = durationHour * 24;
  13479. const durationWeek = durationDay * 7;
  13480. const durationMonth = durationDay * 30;
  13481. const durationYear = durationDay * 365;
  13482. const second = timeInterval((date) => {
  13483. date.setTime(date - date.getMilliseconds());
  13484. }, (date, step) => {
  13485. date.setTime(+date + step * durationSecond);
  13486. }, (start, end) => {
  13487. return (end - start) / durationSecond;
  13488. }, (date) => {
  13489. return date.getUTCSeconds();
  13490. });
  13491. const seconds = second.range;
  13492. const timeMinute = timeInterval((date) => {
  13493. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  13494. }, (date, step) => {
  13495. date.setTime(+date + step * durationMinute);
  13496. }, (start, end) => {
  13497. return (end - start) / durationMinute;
  13498. }, (date) => {
  13499. return date.getMinutes();
  13500. });
  13501. const timeMinutes = timeMinute.range;
  13502. const utcMinute = timeInterval((date) => {
  13503. date.setUTCSeconds(0, 0);
  13504. }, (date, step) => {
  13505. date.setTime(+date + step * durationMinute);
  13506. }, (start, end) => {
  13507. return (end - start) / durationMinute;
  13508. }, (date) => {
  13509. return date.getUTCMinutes();
  13510. });
  13511. const utcMinutes = utcMinute.range;
  13512. const timeHour = timeInterval((date) => {
  13513. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  13514. }, (date, step) => {
  13515. date.setTime(+date + step * durationHour);
  13516. }, (start, end) => {
  13517. return (end - start) / durationHour;
  13518. }, (date) => {
  13519. return date.getHours();
  13520. });
  13521. const timeHours = timeHour.range;
  13522. const utcHour = timeInterval((date) => {
  13523. date.setUTCMinutes(0, 0, 0);
  13524. }, (date, step) => {
  13525. date.setTime(+date + step * durationHour);
  13526. }, (start, end) => {
  13527. return (end - start) / durationHour;
  13528. }, (date) => {
  13529. return date.getUTCHours();
  13530. });
  13531. const utcHours = utcHour.range;
  13532. const timeDay = timeInterval(
  13533. date => date.setHours(0, 0, 0, 0),
  13534. (date, step) => date.setDate(date.getDate() + step),
  13535. (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
  13536. date => date.getDate() - 1
  13537. );
  13538. const timeDays = timeDay.range;
  13539. const utcDay = timeInterval((date) => {
  13540. date.setUTCHours(0, 0, 0, 0);
  13541. }, (date, step) => {
  13542. date.setUTCDate(date.getUTCDate() + step);
  13543. }, (start, end) => {
  13544. return (end - start) / durationDay;
  13545. }, (date) => {
  13546. return date.getUTCDate() - 1;
  13547. });
  13548. const utcDays = utcDay.range;
  13549. const unixDay = timeInterval((date) => {
  13550. date.setUTCHours(0, 0, 0, 0);
  13551. }, (date, step) => {
  13552. date.setUTCDate(date.getUTCDate() + step);
  13553. }, (start, end) => {
  13554. return (end - start) / durationDay;
  13555. }, (date) => {
  13556. return Math.floor(date / durationDay);
  13557. });
  13558. const unixDays = unixDay.range;
  13559. function timeWeekday(i) {
  13560. return timeInterval((date) => {
  13561. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  13562. date.setHours(0, 0, 0, 0);
  13563. }, (date, step) => {
  13564. date.setDate(date.getDate() + step * 7);
  13565. }, (start, end) => {
  13566. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  13567. });
  13568. }
  13569. const timeSunday = timeWeekday(0);
  13570. const timeMonday = timeWeekday(1);
  13571. const timeTuesday = timeWeekday(2);
  13572. const timeWednesday = timeWeekday(3);
  13573. const timeThursday = timeWeekday(4);
  13574. const timeFriday = timeWeekday(5);
  13575. const timeSaturday = timeWeekday(6);
  13576. const timeSundays = timeSunday.range;
  13577. const timeMondays = timeMonday.range;
  13578. const timeTuesdays = timeTuesday.range;
  13579. const timeWednesdays = timeWednesday.range;
  13580. const timeThursdays = timeThursday.range;
  13581. const timeFridays = timeFriday.range;
  13582. const timeSaturdays = timeSaturday.range;
  13583. function utcWeekday(i) {
  13584. return timeInterval((date) => {
  13585. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  13586. date.setUTCHours(0, 0, 0, 0);
  13587. }, (date, step) => {
  13588. date.setUTCDate(date.getUTCDate() + step * 7);
  13589. }, (start, end) => {
  13590. return (end - start) / durationWeek;
  13591. });
  13592. }
  13593. const utcSunday = utcWeekday(0);
  13594. const utcMonday = utcWeekday(1);
  13595. const utcTuesday = utcWeekday(2);
  13596. const utcWednesday = utcWeekday(3);
  13597. const utcThursday = utcWeekday(4);
  13598. const utcFriday = utcWeekday(5);
  13599. const utcSaturday = utcWeekday(6);
  13600. const utcSundays = utcSunday.range;
  13601. const utcMondays = utcMonday.range;
  13602. const utcTuesdays = utcTuesday.range;
  13603. const utcWednesdays = utcWednesday.range;
  13604. const utcThursdays = utcThursday.range;
  13605. const utcFridays = utcFriday.range;
  13606. const utcSaturdays = utcSaturday.range;
  13607. const timeMonth = timeInterval((date) => {
  13608. date.setDate(1);
  13609. date.setHours(0, 0, 0, 0);
  13610. }, (date, step) => {
  13611. date.setMonth(date.getMonth() + step);
  13612. }, (start, end) => {
  13613. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  13614. }, (date) => {
  13615. return date.getMonth();
  13616. });
  13617. const timeMonths = timeMonth.range;
  13618. const utcMonth = timeInterval((date) => {
  13619. date.setUTCDate(1);
  13620. date.setUTCHours(0, 0, 0, 0);
  13621. }, (date, step) => {
  13622. date.setUTCMonth(date.getUTCMonth() + step);
  13623. }, (start, end) => {
  13624. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  13625. }, (date) => {
  13626. return date.getUTCMonth();
  13627. });
  13628. const utcMonths = utcMonth.range;
  13629. const timeYear = timeInterval((date) => {
  13630. date.setMonth(0, 1);
  13631. date.setHours(0, 0, 0, 0);
  13632. }, (date, step) => {
  13633. date.setFullYear(date.getFullYear() + step);
  13634. }, (start, end) => {
  13635. return end.getFullYear() - start.getFullYear();
  13636. }, (date) => {
  13637. return date.getFullYear();
  13638. });
  13639. // An optimized implementation for this simple case.
  13640. timeYear.every = (k) => {
  13641. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13642. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  13643. date.setMonth(0, 1);
  13644. date.setHours(0, 0, 0, 0);
  13645. }, (date, step) => {
  13646. date.setFullYear(date.getFullYear() + step * k);
  13647. });
  13648. };
  13649. const timeYears = timeYear.range;
  13650. const utcYear = timeInterval((date) => {
  13651. date.setUTCMonth(0, 1);
  13652. date.setUTCHours(0, 0, 0, 0);
  13653. }, (date, step) => {
  13654. date.setUTCFullYear(date.getUTCFullYear() + step);
  13655. }, (start, end) => {
  13656. return end.getUTCFullYear() - start.getUTCFullYear();
  13657. }, (date) => {
  13658. return date.getUTCFullYear();
  13659. });
  13660. // An optimized implementation for this simple case.
  13661. utcYear.every = (k) => {
  13662. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13663. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  13664. date.setUTCMonth(0, 1);
  13665. date.setUTCHours(0, 0, 0, 0);
  13666. }, (date, step) => {
  13667. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  13668. });
  13669. };
  13670. const utcYears = utcYear.range;
  13671. function ticker(year, month, week, day, hour, minute) {
  13672. const tickIntervals = [
  13673. [second, 1, durationSecond],
  13674. [second, 5, 5 * durationSecond],
  13675. [second, 15, 15 * durationSecond],
  13676. [second, 30, 30 * durationSecond],
  13677. [minute, 1, durationMinute],
  13678. [minute, 5, 5 * durationMinute],
  13679. [minute, 15, 15 * durationMinute],
  13680. [minute, 30, 30 * durationMinute],
  13681. [ hour, 1, durationHour ],
  13682. [ hour, 3, 3 * durationHour ],
  13683. [ hour, 6, 6 * durationHour ],
  13684. [ hour, 12, 12 * durationHour ],
  13685. [ day, 1, durationDay ],
  13686. [ day, 2, 2 * durationDay ],
  13687. [ week, 1, durationWeek ],
  13688. [ month, 1, durationMonth ],
  13689. [ month, 3, 3 * durationMonth ],
  13690. [ year, 1, durationYear ]
  13691. ];
  13692. function ticks(start, stop, count) {
  13693. const reverse = stop < start;
  13694. if (reverse) [start, stop] = [stop, start];
  13695. const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
  13696. const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
  13697. return reverse ? ticks.reverse() : ticks;
  13698. }
  13699. function tickInterval(start, stop, count) {
  13700. const target = Math.abs(stop - start) / count;
  13701. const i = bisector(([,, step]) => step).right(tickIntervals, target);
  13702. if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
  13703. if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
  13704. const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  13705. return t.every(step);
  13706. }
  13707. return [ticks, tickInterval];
  13708. }
  13709. const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
  13710. const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
  13711. function localDate(d) {
  13712. if (0 <= d.y && d.y < 100) {
  13713. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  13714. date.setFullYear(d.y);
  13715. return date;
  13716. }
  13717. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  13718. }
  13719. function utcDate(d) {
  13720. if (0 <= d.y && d.y < 100) {
  13721. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  13722. date.setUTCFullYear(d.y);
  13723. return date;
  13724. }
  13725. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  13726. }
  13727. function newDate(y, m, d) {
  13728. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  13729. }
  13730. function formatLocale(locale) {
  13731. var locale_dateTime = locale.dateTime,
  13732. locale_date = locale.date,
  13733. locale_time = locale.time,
  13734. locale_periods = locale.periods,
  13735. locale_weekdays = locale.days,
  13736. locale_shortWeekdays = locale.shortDays,
  13737. locale_months = locale.months,
  13738. locale_shortMonths = locale.shortMonths;
  13739. var periodRe = formatRe(locale_periods),
  13740. periodLookup = formatLookup(locale_periods),
  13741. weekdayRe = formatRe(locale_weekdays),
  13742. weekdayLookup = formatLookup(locale_weekdays),
  13743. shortWeekdayRe = formatRe(locale_shortWeekdays),
  13744. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  13745. monthRe = formatRe(locale_months),
  13746. monthLookup = formatLookup(locale_months),
  13747. shortMonthRe = formatRe(locale_shortMonths),
  13748. shortMonthLookup = formatLookup(locale_shortMonths);
  13749. var formats = {
  13750. "a": formatShortWeekday,
  13751. "A": formatWeekday,
  13752. "b": formatShortMonth,
  13753. "B": formatMonth,
  13754. "c": null,
  13755. "d": formatDayOfMonth,
  13756. "e": formatDayOfMonth,
  13757. "f": formatMicroseconds,
  13758. "g": formatYearISO,
  13759. "G": formatFullYearISO,
  13760. "H": formatHour24,
  13761. "I": formatHour12,
  13762. "j": formatDayOfYear,
  13763. "L": formatMilliseconds,
  13764. "m": formatMonthNumber,
  13765. "M": formatMinutes,
  13766. "p": formatPeriod,
  13767. "q": formatQuarter,
  13768. "Q": formatUnixTimestamp,
  13769. "s": formatUnixTimestampSeconds,
  13770. "S": formatSeconds,
  13771. "u": formatWeekdayNumberMonday,
  13772. "U": formatWeekNumberSunday,
  13773. "V": formatWeekNumberISO,
  13774. "w": formatWeekdayNumberSunday,
  13775. "W": formatWeekNumberMonday,
  13776. "x": null,
  13777. "X": null,
  13778. "y": formatYear,
  13779. "Y": formatFullYear,
  13780. "Z": formatZone,
  13781. "%": formatLiteralPercent
  13782. };
  13783. var utcFormats = {
  13784. "a": formatUTCShortWeekday,
  13785. "A": formatUTCWeekday,
  13786. "b": formatUTCShortMonth,
  13787. "B": formatUTCMonth,
  13788. "c": null,
  13789. "d": formatUTCDayOfMonth,
  13790. "e": formatUTCDayOfMonth,
  13791. "f": formatUTCMicroseconds,
  13792. "g": formatUTCYearISO,
  13793. "G": formatUTCFullYearISO,
  13794. "H": formatUTCHour24,
  13795. "I": formatUTCHour12,
  13796. "j": formatUTCDayOfYear,
  13797. "L": formatUTCMilliseconds,
  13798. "m": formatUTCMonthNumber,
  13799. "M": formatUTCMinutes,
  13800. "p": formatUTCPeriod,
  13801. "q": formatUTCQuarter,
  13802. "Q": formatUnixTimestamp,
  13803. "s": formatUnixTimestampSeconds,
  13804. "S": formatUTCSeconds,
  13805. "u": formatUTCWeekdayNumberMonday,
  13806. "U": formatUTCWeekNumberSunday,
  13807. "V": formatUTCWeekNumberISO,
  13808. "w": formatUTCWeekdayNumberSunday,
  13809. "W": formatUTCWeekNumberMonday,
  13810. "x": null,
  13811. "X": null,
  13812. "y": formatUTCYear,
  13813. "Y": formatUTCFullYear,
  13814. "Z": formatUTCZone,
  13815. "%": formatLiteralPercent
  13816. };
  13817. var parses = {
  13818. "a": parseShortWeekday,
  13819. "A": parseWeekday,
  13820. "b": parseShortMonth,
  13821. "B": parseMonth,
  13822. "c": parseLocaleDateTime,
  13823. "d": parseDayOfMonth,
  13824. "e": parseDayOfMonth,
  13825. "f": parseMicroseconds,
  13826. "g": parseYear,
  13827. "G": parseFullYear,
  13828. "H": parseHour24,
  13829. "I": parseHour24,
  13830. "j": parseDayOfYear,
  13831. "L": parseMilliseconds,
  13832. "m": parseMonthNumber,
  13833. "M": parseMinutes,
  13834. "p": parsePeriod,
  13835. "q": parseQuarter,
  13836. "Q": parseUnixTimestamp,
  13837. "s": parseUnixTimestampSeconds,
  13838. "S": parseSeconds,
  13839. "u": parseWeekdayNumberMonday,
  13840. "U": parseWeekNumberSunday,
  13841. "V": parseWeekNumberISO,
  13842. "w": parseWeekdayNumberSunday,
  13843. "W": parseWeekNumberMonday,
  13844. "x": parseLocaleDate,
  13845. "X": parseLocaleTime,
  13846. "y": parseYear,
  13847. "Y": parseFullYear,
  13848. "Z": parseZone,
  13849. "%": parseLiteralPercent
  13850. };
  13851. // These recursive directive definitions must be deferred.
  13852. formats.x = newFormat(locale_date, formats);
  13853. formats.X = newFormat(locale_time, formats);
  13854. formats.c = newFormat(locale_dateTime, formats);
  13855. utcFormats.x = newFormat(locale_date, utcFormats);
  13856. utcFormats.X = newFormat(locale_time, utcFormats);
  13857. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  13858. function newFormat(specifier, formats) {
  13859. return function(date) {
  13860. var string = [],
  13861. i = -1,
  13862. j = 0,
  13863. n = specifier.length,
  13864. c,
  13865. pad,
  13866. format;
  13867. if (!(date instanceof Date)) date = new Date(+date);
  13868. while (++i < n) {
  13869. if (specifier.charCodeAt(i) === 37) {
  13870. string.push(specifier.slice(j, i));
  13871. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  13872. else pad = c === "e" ? " " : "0";
  13873. if (format = formats[c]) c = format(date, pad);
  13874. string.push(c);
  13875. j = i + 1;
  13876. }
  13877. }
  13878. string.push(specifier.slice(j, i));
  13879. return string.join("");
  13880. };
  13881. }
  13882. function newParse(specifier, Z) {
  13883. return function(string) {
  13884. var d = newDate(1900, undefined, 1),
  13885. i = parseSpecifier(d, specifier, string += "", 0),
  13886. week, day;
  13887. if (i != string.length) return null;
  13888. // If a UNIX timestamp is specified, return it.
  13889. if ("Q" in d) return new Date(d.Q);
  13890. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  13891. // If this is utcParse, never use the local timezone.
  13892. if (Z && !("Z" in d)) d.Z = 0;
  13893. // The am-pm flag is 0 for AM, and 1 for PM.
  13894. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  13895. // If the month was not specified, inherit from the quarter.
  13896. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  13897. // Convert day-of-week and week-of-year to day-of-year.
  13898. if ("V" in d) {
  13899. if (d.V < 1 || d.V > 53) return null;
  13900. if (!("w" in d)) d.w = 1;
  13901. if ("Z" in d) {
  13902. week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
  13903. week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
  13904. week = utcDay.offset(week, (d.V - 1) * 7);
  13905. d.y = week.getUTCFullYear();
  13906. d.m = week.getUTCMonth();
  13907. d.d = week.getUTCDate() + (d.w + 6) % 7;
  13908. } else {
  13909. week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
  13910. week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
  13911. week = timeDay.offset(week, (d.V - 1) * 7);
  13912. d.y = week.getFullYear();
  13913. d.m = week.getMonth();
  13914. d.d = week.getDate() + (d.w + 6) % 7;
  13915. }
  13916. } else if ("W" in d || "U" in d) {
  13917. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  13918. day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  13919. d.m = 0;
  13920. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
  13921. }
  13922. // If a time zone is specified, all fields are interpreted as UTC and then
  13923. // offset according to the specified time zone.
  13924. if ("Z" in d) {
  13925. d.H += d.Z / 100 | 0;
  13926. d.M += d.Z % 100;
  13927. return utcDate(d);
  13928. }
  13929. // Otherwise, all fields are in local time.
  13930. return localDate(d);
  13931. };
  13932. }
  13933. function parseSpecifier(d, specifier, string, j) {
  13934. var i = 0,
  13935. n = specifier.length,
  13936. m = string.length,
  13937. c,
  13938. parse;
  13939. while (i < n) {
  13940. if (j >= m) return -1;
  13941. c = specifier.charCodeAt(i++);
  13942. if (c === 37) {
  13943. c = specifier.charAt(i++);
  13944. parse = parses[c in pads ? specifier.charAt(i++) : c];
  13945. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  13946. } else if (c != string.charCodeAt(j++)) {
  13947. return -1;
  13948. }
  13949. }
  13950. return j;
  13951. }
  13952. function parsePeriod(d, string, i) {
  13953. var n = periodRe.exec(string.slice(i));
  13954. return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13955. }
  13956. function parseShortWeekday(d, string, i) {
  13957. var n = shortWeekdayRe.exec(string.slice(i));
  13958. return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13959. }
  13960. function parseWeekday(d, string, i) {
  13961. var n = weekdayRe.exec(string.slice(i));
  13962. return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13963. }
  13964. function parseShortMonth(d, string, i) {
  13965. var n = shortMonthRe.exec(string.slice(i));
  13966. return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13967. }
  13968. function parseMonth(d, string, i) {
  13969. var n = monthRe.exec(string.slice(i));
  13970. return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13971. }
  13972. function parseLocaleDateTime(d, string, i) {
  13973. return parseSpecifier(d, locale_dateTime, string, i);
  13974. }
  13975. function parseLocaleDate(d, string, i) {
  13976. return parseSpecifier(d, locale_date, string, i);
  13977. }
  13978. function parseLocaleTime(d, string, i) {
  13979. return parseSpecifier(d, locale_time, string, i);
  13980. }
  13981. function formatShortWeekday(d) {
  13982. return locale_shortWeekdays[d.getDay()];
  13983. }
  13984. function formatWeekday(d) {
  13985. return locale_weekdays[d.getDay()];
  13986. }
  13987. function formatShortMonth(d) {
  13988. return locale_shortMonths[d.getMonth()];
  13989. }
  13990. function formatMonth(d) {
  13991. return locale_months[d.getMonth()];
  13992. }
  13993. function formatPeriod(d) {
  13994. return locale_periods[+(d.getHours() >= 12)];
  13995. }
  13996. function formatQuarter(d) {
  13997. return 1 + ~~(d.getMonth() / 3);
  13998. }
  13999. function formatUTCShortWeekday(d) {
  14000. return locale_shortWeekdays[d.getUTCDay()];
  14001. }
  14002. function formatUTCWeekday(d) {
  14003. return locale_weekdays[d.getUTCDay()];
  14004. }
  14005. function formatUTCShortMonth(d) {
  14006. return locale_shortMonths[d.getUTCMonth()];
  14007. }
  14008. function formatUTCMonth(d) {
  14009. return locale_months[d.getUTCMonth()];
  14010. }
  14011. function formatUTCPeriod(d) {
  14012. return locale_periods[+(d.getUTCHours() >= 12)];
  14013. }
  14014. function formatUTCQuarter(d) {
  14015. return 1 + ~~(d.getUTCMonth() / 3);
  14016. }
  14017. return {
  14018. format: function(specifier) {
  14019. var f = newFormat(specifier += "", formats);
  14020. f.toString = function() { return specifier; };
  14021. return f;
  14022. },
  14023. parse: function(specifier) {
  14024. var p = newParse(specifier += "", false);
  14025. p.toString = function() { return specifier; };
  14026. return p;
  14027. },
  14028. utcFormat: function(specifier) {
  14029. var f = newFormat(specifier += "", utcFormats);
  14030. f.toString = function() { return specifier; };
  14031. return f;
  14032. },
  14033. utcParse: function(specifier) {
  14034. var p = newParse(specifier += "", true);
  14035. p.toString = function() { return specifier; };
  14036. return p;
  14037. }
  14038. };
  14039. }
  14040. var pads = {"-": "", "_": " ", "0": "0"},
  14041. numberRe = /^\s*\d+/, // note: ignores next directive
  14042. percentRe = /^%/,
  14043. requoteRe = /[\\^$*+?|[\]().{}]/g;
  14044. function pad(value, fill, width) {
  14045. var sign = value < 0 ? "-" : "",
  14046. string = (sign ? -value : value) + "",
  14047. length = string.length;
  14048. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  14049. }
  14050. function requote(s) {
  14051. return s.replace(requoteRe, "\\$&");
  14052. }
  14053. function formatRe(names) {
  14054. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  14055. }
  14056. function formatLookup(names) {
  14057. return new Map(names.map((name, i) => [name.toLowerCase(), i]));
  14058. }
  14059. function parseWeekdayNumberSunday(d, string, i) {
  14060. var n = numberRe.exec(string.slice(i, i + 1));
  14061. return n ? (d.w = +n[0], i + n[0].length) : -1;
  14062. }
  14063. function parseWeekdayNumberMonday(d, string, i) {
  14064. var n = numberRe.exec(string.slice(i, i + 1));
  14065. return n ? (d.u = +n[0], i + n[0].length) : -1;
  14066. }
  14067. function parseWeekNumberSunday(d, string, i) {
  14068. var n = numberRe.exec(string.slice(i, i + 2));
  14069. return n ? (d.U = +n[0], i + n[0].length) : -1;
  14070. }
  14071. function parseWeekNumberISO(d, string, i) {
  14072. var n = numberRe.exec(string.slice(i, i + 2));
  14073. return n ? (d.V = +n[0], i + n[0].length) : -1;
  14074. }
  14075. function parseWeekNumberMonday(d, string, i) {
  14076. var n = numberRe.exec(string.slice(i, i + 2));
  14077. return n ? (d.W = +n[0], i + n[0].length) : -1;
  14078. }
  14079. function parseFullYear(d, string, i) {
  14080. var n = numberRe.exec(string.slice(i, i + 4));
  14081. return n ? (d.y = +n[0], i + n[0].length) : -1;
  14082. }
  14083. function parseYear(d, string, i) {
  14084. var n = numberRe.exec(string.slice(i, i + 2));
  14085. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  14086. }
  14087. function parseZone(d, string, i) {
  14088. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  14089. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  14090. }
  14091. function parseQuarter(d, string, i) {
  14092. var n = numberRe.exec(string.slice(i, i + 1));
  14093. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  14094. }
  14095. function parseMonthNumber(d, string, i) {
  14096. var n = numberRe.exec(string.slice(i, i + 2));
  14097. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  14098. }
  14099. function parseDayOfMonth(d, string, i) {
  14100. var n = numberRe.exec(string.slice(i, i + 2));
  14101. return n ? (d.d = +n[0], i + n[0].length) : -1;
  14102. }
  14103. function parseDayOfYear(d, string, i) {
  14104. var n = numberRe.exec(string.slice(i, i + 3));
  14105. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  14106. }
  14107. function parseHour24(d, string, i) {
  14108. var n = numberRe.exec(string.slice(i, i + 2));
  14109. return n ? (d.H = +n[0], i + n[0].length) : -1;
  14110. }
  14111. function parseMinutes(d, string, i) {
  14112. var n = numberRe.exec(string.slice(i, i + 2));
  14113. return n ? (d.M = +n[0], i + n[0].length) : -1;
  14114. }
  14115. function parseSeconds(d, string, i) {
  14116. var n = numberRe.exec(string.slice(i, i + 2));
  14117. return n ? (d.S = +n[0], i + n[0].length) : -1;
  14118. }
  14119. function parseMilliseconds(d, string, i) {
  14120. var n = numberRe.exec(string.slice(i, i + 3));
  14121. return n ? (d.L = +n[0], i + n[0].length) : -1;
  14122. }
  14123. function parseMicroseconds(d, string, i) {
  14124. var n = numberRe.exec(string.slice(i, i + 6));
  14125. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  14126. }
  14127. function parseLiteralPercent(d, string, i) {
  14128. var n = percentRe.exec(string.slice(i, i + 1));
  14129. return n ? i + n[0].length : -1;
  14130. }
  14131. function parseUnixTimestamp(d, string, i) {
  14132. var n = numberRe.exec(string.slice(i));
  14133. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  14134. }
  14135. function parseUnixTimestampSeconds(d, string, i) {
  14136. var n = numberRe.exec(string.slice(i));
  14137. return n ? (d.s = +n[0], i + n[0].length) : -1;
  14138. }
  14139. function formatDayOfMonth(d, p) {
  14140. return pad(d.getDate(), p, 2);
  14141. }
  14142. function formatHour24(d, p) {
  14143. return pad(d.getHours(), p, 2);
  14144. }
  14145. function formatHour12(d, p) {
  14146. return pad(d.getHours() % 12 || 12, p, 2);
  14147. }
  14148. function formatDayOfYear(d, p) {
  14149. return pad(1 + timeDay.count(timeYear(d), d), p, 3);
  14150. }
  14151. function formatMilliseconds(d, p) {
  14152. return pad(d.getMilliseconds(), p, 3);
  14153. }
  14154. function formatMicroseconds(d, p) {
  14155. return formatMilliseconds(d, p) + "000";
  14156. }
  14157. function formatMonthNumber(d, p) {
  14158. return pad(d.getMonth() + 1, p, 2);
  14159. }
  14160. function formatMinutes(d, p) {
  14161. return pad(d.getMinutes(), p, 2);
  14162. }
  14163. function formatSeconds(d, p) {
  14164. return pad(d.getSeconds(), p, 2);
  14165. }
  14166. function formatWeekdayNumberMonday(d) {
  14167. var day = d.getDay();
  14168. return day === 0 ? 7 : day;
  14169. }
  14170. function formatWeekNumberSunday(d, p) {
  14171. return pad(timeSunday.count(timeYear(d) - 1, d), p, 2);
  14172. }
  14173. function dISO(d) {
  14174. var day = d.getDay();
  14175. return (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14176. }
  14177. function formatWeekNumberISO(d, p) {
  14178. d = dISO(d);
  14179. return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
  14180. }
  14181. function formatWeekdayNumberSunday(d) {
  14182. return d.getDay();
  14183. }
  14184. function formatWeekNumberMonday(d, p) {
  14185. return pad(timeMonday.count(timeYear(d) - 1, d), p, 2);
  14186. }
  14187. function formatYear(d, p) {
  14188. return pad(d.getFullYear() % 100, p, 2);
  14189. }
  14190. function formatYearISO(d, p) {
  14191. d = dISO(d);
  14192. return pad(d.getFullYear() % 100, p, 2);
  14193. }
  14194. function formatFullYear(d, p) {
  14195. return pad(d.getFullYear() % 10000, p, 4);
  14196. }
  14197. function formatFullYearISO(d, p) {
  14198. var day = d.getDay();
  14199. d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14200. return pad(d.getFullYear() % 10000, p, 4);
  14201. }
  14202. function formatZone(d) {
  14203. var z = d.getTimezoneOffset();
  14204. return (z > 0 ? "-" : (z *= -1, "+"))
  14205. + pad(z / 60 | 0, "0", 2)
  14206. + pad(z % 60, "0", 2);
  14207. }
  14208. function formatUTCDayOfMonth(d, p) {
  14209. return pad(d.getUTCDate(), p, 2);
  14210. }
  14211. function formatUTCHour24(d, p) {
  14212. return pad(d.getUTCHours(), p, 2);
  14213. }
  14214. function formatUTCHour12(d, p) {
  14215. return pad(d.getUTCHours() % 12 || 12, p, 2);
  14216. }
  14217. function formatUTCDayOfYear(d, p) {
  14218. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  14219. }
  14220. function formatUTCMilliseconds(d, p) {
  14221. return pad(d.getUTCMilliseconds(), p, 3);
  14222. }
  14223. function formatUTCMicroseconds(d, p) {
  14224. return formatUTCMilliseconds(d, p) + "000";
  14225. }
  14226. function formatUTCMonthNumber(d, p) {
  14227. return pad(d.getUTCMonth() + 1, p, 2);
  14228. }
  14229. function formatUTCMinutes(d, p) {
  14230. return pad(d.getUTCMinutes(), p, 2);
  14231. }
  14232. function formatUTCSeconds(d, p) {
  14233. return pad(d.getUTCSeconds(), p, 2);
  14234. }
  14235. function formatUTCWeekdayNumberMonday(d) {
  14236. var dow = d.getUTCDay();
  14237. return dow === 0 ? 7 : dow;
  14238. }
  14239. function formatUTCWeekNumberSunday(d, p) {
  14240. return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
  14241. }
  14242. function UTCdISO(d) {
  14243. var day = d.getUTCDay();
  14244. return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14245. }
  14246. function formatUTCWeekNumberISO(d, p) {
  14247. d = UTCdISO(d);
  14248. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  14249. }
  14250. function formatUTCWeekdayNumberSunday(d) {
  14251. return d.getUTCDay();
  14252. }
  14253. function formatUTCWeekNumberMonday(d, p) {
  14254. return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
  14255. }
  14256. function formatUTCYear(d, p) {
  14257. return pad(d.getUTCFullYear() % 100, p, 2);
  14258. }
  14259. function formatUTCYearISO(d, p) {
  14260. d = UTCdISO(d);
  14261. return pad(d.getUTCFullYear() % 100, p, 2);
  14262. }
  14263. function formatUTCFullYear(d, p) {
  14264. return pad(d.getUTCFullYear() % 10000, p, 4);
  14265. }
  14266. function formatUTCFullYearISO(d, p) {
  14267. var day = d.getUTCDay();
  14268. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14269. return pad(d.getUTCFullYear() % 10000, p, 4);
  14270. }
  14271. function formatUTCZone() {
  14272. return "+0000";
  14273. }
  14274. function formatLiteralPercent() {
  14275. return "%";
  14276. }
  14277. function formatUnixTimestamp(d) {
  14278. return +d;
  14279. }
  14280. function formatUnixTimestampSeconds(d) {
  14281. return Math.floor(+d / 1000);
  14282. }
  14283. var locale;
  14284. exports.timeFormat = void 0;
  14285. exports.timeParse = void 0;
  14286. exports.utcFormat = void 0;
  14287. exports.utcParse = void 0;
  14288. defaultLocale({
  14289. dateTime: "%x, %X",
  14290. date: "%-m/%-d/%Y",
  14291. time: "%-I:%M:%S %p",
  14292. periods: ["AM", "PM"],
  14293. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  14294. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  14295. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  14296. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  14297. });
  14298. function defaultLocale(definition) {
  14299. locale = formatLocale(definition);
  14300. exports.timeFormat = locale.format;
  14301. exports.timeParse = locale.parse;
  14302. exports.utcFormat = locale.utcFormat;
  14303. exports.utcParse = locale.utcParse;
  14304. return locale;
  14305. }
  14306. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  14307. function formatIsoNative(date) {
  14308. return date.toISOString();
  14309. }
  14310. var formatIso = Date.prototype.toISOString
  14311. ? formatIsoNative
  14312. : exports.utcFormat(isoSpecifier);
  14313. var formatIso$1 = formatIso;
  14314. function parseIsoNative(string) {
  14315. var date = new Date(string);
  14316. return isNaN(date) ? null : date;
  14317. }
  14318. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  14319. ? parseIsoNative
  14320. : exports.utcParse(isoSpecifier);
  14321. var parseIso$1 = parseIso;
  14322. function date(t) {
  14323. return new Date(t);
  14324. }
  14325. function number(t) {
  14326. return t instanceof Date ? +t : +new Date(+t);
  14327. }
  14328. function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
  14329. var scale = continuous(),
  14330. invert = scale.invert,
  14331. domain = scale.domain;
  14332. var formatMillisecond = format(".%L"),
  14333. formatSecond = format(":%S"),
  14334. formatMinute = format("%I:%M"),
  14335. formatHour = format("%I %p"),
  14336. formatDay = format("%a %d"),
  14337. formatWeek = format("%b %d"),
  14338. formatMonth = format("%B"),
  14339. formatYear = format("%Y");
  14340. function tickFormat(date) {
  14341. return (second(date) < date ? formatMillisecond
  14342. : minute(date) < date ? formatSecond
  14343. : hour(date) < date ? formatMinute
  14344. : day(date) < date ? formatHour
  14345. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  14346. : year(date) < date ? formatMonth
  14347. : formatYear)(date);
  14348. }
  14349. scale.invert = function(y) {
  14350. return new Date(invert(y));
  14351. };
  14352. scale.domain = function(_) {
  14353. return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
  14354. };
  14355. scale.ticks = function(interval) {
  14356. var d = domain();
  14357. return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14358. };
  14359. scale.tickFormat = function(count, specifier) {
  14360. return specifier == null ? tickFormat : format(specifier);
  14361. };
  14362. scale.nice = function(interval) {
  14363. var d = domain();
  14364. if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14365. return interval ? domain(nice(d, interval)) : scale;
  14366. };
  14367. scale.copy = function() {
  14368. return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
  14369. };
  14370. return scale;
  14371. }
  14372. function time() {
  14373. return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  14374. }
  14375. function utcTime() {
  14376. return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  14377. }
  14378. function transformer$1() {
  14379. var x0 = 0,
  14380. x1 = 1,
  14381. t0,
  14382. t1,
  14383. k10,
  14384. transform,
  14385. interpolator = identity$3,
  14386. clamp = false,
  14387. unknown;
  14388. function scale(x) {
  14389. return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  14390. }
  14391. scale.domain = function(_) {
  14392. return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  14393. };
  14394. scale.clamp = function(_) {
  14395. return arguments.length ? (clamp = !!_, scale) : clamp;
  14396. };
  14397. scale.interpolator = function(_) {
  14398. return arguments.length ? (interpolator = _, scale) : interpolator;
  14399. };
  14400. function range(interpolate) {
  14401. return function(_) {
  14402. var r0, r1;
  14403. return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
  14404. };
  14405. }
  14406. scale.range = range(interpolate$2);
  14407. scale.rangeRound = range(interpolateRound);
  14408. scale.unknown = function(_) {
  14409. return arguments.length ? (unknown = _, scale) : unknown;
  14410. };
  14411. return function(t) {
  14412. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  14413. return scale;
  14414. };
  14415. }
  14416. function copy(source, target) {
  14417. return target
  14418. .domain(source.domain())
  14419. .interpolator(source.interpolator())
  14420. .clamp(source.clamp())
  14421. .unknown(source.unknown());
  14422. }
  14423. function sequential() {
  14424. var scale = linearish(transformer$1()(identity$3));
  14425. scale.copy = function() {
  14426. return copy(scale, sequential());
  14427. };
  14428. return initInterpolator.apply(scale, arguments);
  14429. }
  14430. function sequentialLog() {
  14431. var scale = loggish(transformer$1()).domain([1, 10]);
  14432. scale.copy = function() {
  14433. return copy(scale, sequentialLog()).base(scale.base());
  14434. };
  14435. return initInterpolator.apply(scale, arguments);
  14436. }
  14437. function sequentialSymlog() {
  14438. var scale = symlogish(transformer$1());
  14439. scale.copy = function() {
  14440. return copy(scale, sequentialSymlog()).constant(scale.constant());
  14441. };
  14442. return initInterpolator.apply(scale, arguments);
  14443. }
  14444. function sequentialPow() {
  14445. var scale = powish(transformer$1());
  14446. scale.copy = function() {
  14447. return copy(scale, sequentialPow()).exponent(scale.exponent());
  14448. };
  14449. return initInterpolator.apply(scale, arguments);
  14450. }
  14451. function sequentialSqrt() {
  14452. return sequentialPow.apply(null, arguments).exponent(0.5);
  14453. }
  14454. function sequentialQuantile() {
  14455. var domain = [],
  14456. interpolator = identity$3;
  14457. function scale(x) {
  14458. if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1));
  14459. }
  14460. scale.domain = function(_) {
  14461. if (!arguments.length) return domain.slice();
  14462. domain = [];
  14463. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  14464. domain.sort(ascending$3);
  14465. return scale;
  14466. };
  14467. scale.interpolator = function(_) {
  14468. return arguments.length ? (interpolator = _, scale) : interpolator;
  14469. };
  14470. scale.range = function() {
  14471. return domain.map((d, i) => interpolator(i / (domain.length - 1)));
  14472. };
  14473. scale.quantiles = function(n) {
  14474. return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
  14475. };
  14476. scale.copy = function() {
  14477. return sequentialQuantile(interpolator).domain(domain);
  14478. };
  14479. return initInterpolator.apply(scale, arguments);
  14480. }
  14481. function transformer() {
  14482. var x0 = 0,
  14483. x1 = 0.5,
  14484. x2 = 1,
  14485. s = 1,
  14486. t0,
  14487. t1,
  14488. t2,
  14489. k10,
  14490. k21,
  14491. interpolator = identity$3,
  14492. transform,
  14493. clamp = false,
  14494. unknown;
  14495. function scale(x) {
  14496. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  14497. }
  14498. scale.domain = function(_) {
  14499. return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
  14500. };
  14501. scale.clamp = function(_) {
  14502. return arguments.length ? (clamp = !!_, scale) : clamp;
  14503. };
  14504. scale.interpolator = function(_) {
  14505. return arguments.length ? (interpolator = _, scale) : interpolator;
  14506. };
  14507. function range(interpolate) {
  14508. return function(_) {
  14509. var r0, r1, r2;
  14510. return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
  14511. };
  14512. }
  14513. scale.range = range(interpolate$2);
  14514. scale.rangeRound = range(interpolateRound);
  14515. scale.unknown = function(_) {
  14516. return arguments.length ? (unknown = _, scale) : unknown;
  14517. };
  14518. return function(t) {
  14519. transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
  14520. return scale;
  14521. };
  14522. }
  14523. function diverging$1() {
  14524. var scale = linearish(transformer()(identity$3));
  14525. scale.copy = function() {
  14526. return copy(scale, diverging$1());
  14527. };
  14528. return initInterpolator.apply(scale, arguments);
  14529. }
  14530. function divergingLog() {
  14531. var scale = loggish(transformer()).domain([0.1, 1, 10]);
  14532. scale.copy = function() {
  14533. return copy(scale, divergingLog()).base(scale.base());
  14534. };
  14535. return initInterpolator.apply(scale, arguments);
  14536. }
  14537. function divergingSymlog() {
  14538. var scale = symlogish(transformer());
  14539. scale.copy = function() {
  14540. return copy(scale, divergingSymlog()).constant(scale.constant());
  14541. };
  14542. return initInterpolator.apply(scale, arguments);
  14543. }
  14544. function divergingPow() {
  14545. var scale = powish(transformer());
  14546. scale.copy = function() {
  14547. return copy(scale, divergingPow()).exponent(scale.exponent());
  14548. };
  14549. return initInterpolator.apply(scale, arguments);
  14550. }
  14551. function divergingSqrt() {
  14552. return divergingPow.apply(null, arguments).exponent(0.5);
  14553. }
  14554. function colors(specifier) {
  14555. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  14556. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  14557. return colors;
  14558. }
  14559. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  14560. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  14561. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  14562. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  14563. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  14564. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  14565. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  14566. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  14567. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  14568. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  14569. var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
  14570. var scheme$q = new Array(3).concat(
  14571. "d8b365f5f5f55ab4ac",
  14572. "a6611adfc27d80cdc1018571",
  14573. "a6611adfc27df5f5f580cdc1018571",
  14574. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  14575. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  14576. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  14577. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  14578. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  14579. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  14580. ).map(colors);
  14581. var BrBG = ramp$1(scheme$q);
  14582. var scheme$p = new Array(3).concat(
  14583. "af8dc3f7f7f77fbf7b",
  14584. "7b3294c2a5cfa6dba0008837",
  14585. "7b3294c2a5cff7f7f7a6dba0008837",
  14586. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  14587. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  14588. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  14589. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  14590. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  14591. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  14592. ).map(colors);
  14593. var PRGn = ramp$1(scheme$p);
  14594. var scheme$o = new Array(3).concat(
  14595. "e9a3c9f7f7f7a1d76a",
  14596. "d01c8bf1b6dab8e1864dac26",
  14597. "d01c8bf1b6daf7f7f7b8e1864dac26",
  14598. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  14599. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  14600. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  14601. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  14602. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  14603. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  14604. ).map(colors);
  14605. var PiYG = ramp$1(scheme$o);
  14606. var scheme$n = new Array(3).concat(
  14607. "998ec3f7f7f7f1a340",
  14608. "5e3c99b2abd2fdb863e66101",
  14609. "5e3c99b2abd2f7f7f7fdb863e66101",
  14610. "542788998ec3d8daebfee0b6f1a340b35806",
  14611. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  14612. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  14613. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  14614. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  14615. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  14616. ).map(colors);
  14617. var PuOr = ramp$1(scheme$n);
  14618. var scheme$m = new Array(3).concat(
  14619. "ef8a62f7f7f767a9cf",
  14620. "ca0020f4a58292c5de0571b0",
  14621. "ca0020f4a582f7f7f792c5de0571b0",
  14622. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  14623. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  14624. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  14625. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  14626. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  14627. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  14628. ).map(colors);
  14629. var RdBu = ramp$1(scheme$m);
  14630. var scheme$l = new Array(3).concat(
  14631. "ef8a62ffffff999999",
  14632. "ca0020f4a582bababa404040",
  14633. "ca0020f4a582ffffffbababa404040",
  14634. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  14635. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  14636. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  14637. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  14638. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  14639. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  14640. ).map(colors);
  14641. var RdGy = ramp$1(scheme$l);
  14642. var scheme$k = new Array(3).concat(
  14643. "fc8d59ffffbf91bfdb",
  14644. "d7191cfdae61abd9e92c7bb6",
  14645. "d7191cfdae61ffffbfabd9e92c7bb6",
  14646. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  14647. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  14648. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  14649. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  14650. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  14651. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  14652. ).map(colors);
  14653. var RdYlBu = ramp$1(scheme$k);
  14654. var scheme$j = new Array(3).concat(
  14655. "fc8d59ffffbf91cf60",
  14656. "d7191cfdae61a6d96a1a9641",
  14657. "d7191cfdae61ffffbfa6d96a1a9641",
  14658. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  14659. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  14660. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  14661. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  14662. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  14663. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  14664. ).map(colors);
  14665. var RdYlGn = ramp$1(scheme$j);
  14666. var scheme$i = new Array(3).concat(
  14667. "fc8d59ffffbf99d594",
  14668. "d7191cfdae61abdda42b83ba",
  14669. "d7191cfdae61ffffbfabdda42b83ba",
  14670. "d53e4ffc8d59fee08be6f59899d5943288bd",
  14671. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  14672. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  14673. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  14674. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  14675. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  14676. ).map(colors);
  14677. var Spectral = ramp$1(scheme$i);
  14678. var scheme$h = new Array(3).concat(
  14679. "e5f5f999d8c92ca25f",
  14680. "edf8fbb2e2e266c2a4238b45",
  14681. "edf8fbb2e2e266c2a42ca25f006d2c",
  14682. "edf8fbccece699d8c966c2a42ca25f006d2c",
  14683. "edf8fbccece699d8c966c2a441ae76238b45005824",
  14684. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  14685. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  14686. ).map(colors);
  14687. var BuGn = ramp$1(scheme$h);
  14688. var scheme$g = new Array(3).concat(
  14689. "e0ecf49ebcda8856a7",
  14690. "edf8fbb3cde38c96c688419d",
  14691. "edf8fbb3cde38c96c68856a7810f7c",
  14692. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  14693. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  14694. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  14695. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  14696. ).map(colors);
  14697. var BuPu = ramp$1(scheme$g);
  14698. var scheme$f = new Array(3).concat(
  14699. "e0f3dba8ddb543a2ca",
  14700. "f0f9e8bae4bc7bccc42b8cbe",
  14701. "f0f9e8bae4bc7bccc443a2ca0868ac",
  14702. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  14703. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14704. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14705. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  14706. ).map(colors);
  14707. var GnBu = ramp$1(scheme$f);
  14708. var scheme$e = new Array(3).concat(
  14709. "fee8c8fdbb84e34a33",
  14710. "fef0d9fdcc8afc8d59d7301f",
  14711. "fef0d9fdcc8afc8d59e34a33b30000",
  14712. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  14713. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  14714. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  14715. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  14716. ).map(colors);
  14717. var OrRd = ramp$1(scheme$e);
  14718. var scheme$d = new Array(3).concat(
  14719. "ece2f0a6bddb1c9099",
  14720. "f6eff7bdc9e167a9cf02818a",
  14721. "f6eff7bdc9e167a9cf1c9099016c59",
  14722. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  14723. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  14724. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  14725. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  14726. ).map(colors);
  14727. var PuBuGn = ramp$1(scheme$d);
  14728. var scheme$c = new Array(3).concat(
  14729. "ece7f2a6bddb2b8cbe",
  14730. "f1eef6bdc9e174a9cf0570b0",
  14731. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  14732. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  14733. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14734. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14735. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  14736. ).map(colors);
  14737. var PuBu = ramp$1(scheme$c);
  14738. var scheme$b = new Array(3).concat(
  14739. "e7e1efc994c7dd1c77",
  14740. "f1eef6d7b5d8df65b0ce1256",
  14741. "f1eef6d7b5d8df65b0dd1c77980043",
  14742. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  14743. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  14744. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  14745. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  14746. ).map(colors);
  14747. var PuRd = ramp$1(scheme$b);
  14748. var scheme$a = new Array(3).concat(
  14749. "fde0ddfa9fb5c51b8a",
  14750. "feebe2fbb4b9f768a1ae017e",
  14751. "feebe2fbb4b9f768a1c51b8a7a0177",
  14752. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  14753. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14754. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14755. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  14756. ).map(colors);
  14757. var RdPu = ramp$1(scheme$a);
  14758. var scheme$9 = new Array(3).concat(
  14759. "edf8b17fcdbb2c7fb8",
  14760. "ffffcca1dab441b6c4225ea8",
  14761. "ffffcca1dab441b6c42c7fb8253494",
  14762. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  14763. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14764. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14765. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  14766. ).map(colors);
  14767. var YlGnBu = ramp$1(scheme$9);
  14768. var scheme$8 = new Array(3).concat(
  14769. "f7fcb9addd8e31a354",
  14770. "ffffccc2e69978c679238443",
  14771. "ffffccc2e69978c67931a354006837",
  14772. "ffffccd9f0a3addd8e78c67931a354006837",
  14773. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  14774. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  14775. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  14776. ).map(colors);
  14777. var YlGn = ramp$1(scheme$8);
  14778. var scheme$7 = new Array(3).concat(
  14779. "fff7bcfec44fd95f0e",
  14780. "ffffd4fed98efe9929cc4c02",
  14781. "ffffd4fed98efe9929d95f0e993404",
  14782. "ffffd4fee391fec44ffe9929d95f0e993404",
  14783. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  14784. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  14785. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  14786. ).map(colors);
  14787. var YlOrBr = ramp$1(scheme$7);
  14788. var scheme$6 = new Array(3).concat(
  14789. "ffeda0feb24cf03b20",
  14790. "ffffb2fecc5cfd8d3ce31a1c",
  14791. "ffffb2fecc5cfd8d3cf03b20bd0026",
  14792. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  14793. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14794. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14795. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  14796. ).map(colors);
  14797. var YlOrRd = ramp$1(scheme$6);
  14798. var scheme$5 = new Array(3).concat(
  14799. "deebf79ecae13182bd",
  14800. "eff3ffbdd7e76baed62171b5",
  14801. "eff3ffbdd7e76baed63182bd08519c",
  14802. "eff3ffc6dbef9ecae16baed63182bd08519c",
  14803. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  14804. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  14805. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  14806. ).map(colors);
  14807. var Blues = ramp$1(scheme$5);
  14808. var scheme$4 = new Array(3).concat(
  14809. "e5f5e0a1d99b31a354",
  14810. "edf8e9bae4b374c476238b45",
  14811. "edf8e9bae4b374c47631a354006d2c",
  14812. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  14813. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  14814. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  14815. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  14816. ).map(colors);
  14817. var Greens = ramp$1(scheme$4);
  14818. var scheme$3 = new Array(3).concat(
  14819. "f0f0f0bdbdbd636363",
  14820. "f7f7f7cccccc969696525252",
  14821. "f7f7f7cccccc969696636363252525",
  14822. "f7f7f7d9d9d9bdbdbd969696636363252525",
  14823. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  14824. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  14825. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  14826. ).map(colors);
  14827. var Greys = ramp$1(scheme$3);
  14828. var scheme$2 = new Array(3).concat(
  14829. "efedf5bcbddc756bb1",
  14830. "f2f0f7cbc9e29e9ac86a51a3",
  14831. "f2f0f7cbc9e29e9ac8756bb154278f",
  14832. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  14833. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14834. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14835. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  14836. ).map(colors);
  14837. var Purples = ramp$1(scheme$2);
  14838. var scheme$1 = new Array(3).concat(
  14839. "fee0d2fc9272de2d26",
  14840. "fee5d9fcae91fb6a4acb181d",
  14841. "fee5d9fcae91fb6a4ade2d26a50f15",
  14842. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  14843. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14844. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14845. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  14846. ).map(colors);
  14847. var Reds = ramp$1(scheme$1);
  14848. var scheme = new Array(3).concat(
  14849. "fee6cefdae6be6550d",
  14850. "feeddefdbe85fd8d3cd94701",
  14851. "feeddefdbe85fd8d3ce6550da63603",
  14852. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  14853. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14854. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14855. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  14856. ).map(colors);
  14857. var Oranges = ramp$1(scheme);
  14858. function cividis(t) {
  14859. t = Math.max(0, Math.min(1, t));
  14860. return "rgb("
  14861. + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
  14862. + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
  14863. + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
  14864. + ")";
  14865. }
  14866. var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
  14867. var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14868. var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14869. var c$2 = cubehelix$3();
  14870. function rainbow(t) {
  14871. if (t < 0 || t > 1) t -= Math.floor(t);
  14872. var ts = Math.abs(t - 0.5);
  14873. c$2.h = 360 * t - 100;
  14874. c$2.s = 1.5 - 1.5 * ts;
  14875. c$2.l = 0.8 - 0.9 * ts;
  14876. return c$2 + "";
  14877. }
  14878. var c$1 = rgb(),
  14879. pi_1_3 = Math.PI / 3,
  14880. pi_2_3 = Math.PI * 2 / 3;
  14881. function sinebow(t) {
  14882. var x;
  14883. t = (0.5 - t) * Math.PI;
  14884. c$1.r = 255 * (x = Math.sin(t)) * x;
  14885. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  14886. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  14887. return c$1 + "";
  14888. }
  14889. function turbo(t) {
  14890. t = Math.max(0, Math.min(1, t));
  14891. return "rgb("
  14892. + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
  14893. + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
  14894. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  14895. + ")";
  14896. }
  14897. function ramp(range) {
  14898. var n = range.length;
  14899. return function(t) {
  14900. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  14901. };
  14902. }
  14903. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  14904. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  14905. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  14906. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  14907. function constant$1(x) {
  14908. return function constant() {
  14909. return x;
  14910. };
  14911. }
  14912. const abs = Math.abs;
  14913. const atan2 = Math.atan2;
  14914. const cos = Math.cos;
  14915. const max = Math.max;
  14916. const min = Math.min;
  14917. const sin = Math.sin;
  14918. const sqrt = Math.sqrt;
  14919. const epsilon = 1e-12;
  14920. const pi = Math.PI;
  14921. const halfPi = pi / 2;
  14922. const tau = 2 * pi;
  14923. function acos(x) {
  14924. return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
  14925. }
  14926. function asin(x) {
  14927. return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
  14928. }
  14929. function withPath(shape) {
  14930. let digits = 3;
  14931. shape.digits = function(_) {
  14932. if (!arguments.length) return digits;
  14933. if (_ == null) {
  14934. digits = null;
  14935. } else {
  14936. const d = Math.floor(_);
  14937. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  14938. digits = d;
  14939. }
  14940. return shape;
  14941. };
  14942. return () => new Path$1(digits);
  14943. }
  14944. function arcInnerRadius(d) {
  14945. return d.innerRadius;
  14946. }
  14947. function arcOuterRadius(d) {
  14948. return d.outerRadius;
  14949. }
  14950. function arcStartAngle(d) {
  14951. return d.startAngle;
  14952. }
  14953. function arcEndAngle(d) {
  14954. return d.endAngle;
  14955. }
  14956. function arcPadAngle(d) {
  14957. return d && d.padAngle; // Note: optional!
  14958. }
  14959. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  14960. var x10 = x1 - x0, y10 = y1 - y0,
  14961. x32 = x3 - x2, y32 = y3 - y2,
  14962. t = y32 * x10 - x32 * y10;
  14963. if (t * t < epsilon) return;
  14964. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  14965. return [x0 + t * x10, y0 + t * y10];
  14966. }
  14967. // Compute perpendicular offset line of length rc.
  14968. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  14969. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  14970. var x01 = x0 - x1,
  14971. y01 = y0 - y1,
  14972. lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
  14973. ox = lo * y01,
  14974. oy = -lo * x01,
  14975. x11 = x0 + ox,
  14976. y11 = y0 + oy,
  14977. x10 = x1 + ox,
  14978. y10 = y1 + oy,
  14979. x00 = (x11 + x10) / 2,
  14980. y00 = (y11 + y10) / 2,
  14981. dx = x10 - x11,
  14982. dy = y10 - y11,
  14983. d2 = dx * dx + dy * dy,
  14984. r = r1 - rc,
  14985. D = x11 * y10 - x10 * y11,
  14986. d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
  14987. cx0 = (D * dy - dx * d) / d2,
  14988. cy0 = (-D * dx - dy * d) / d2,
  14989. cx1 = (D * dy + dx * d) / d2,
  14990. cy1 = (-D * dx + dy * d) / d2,
  14991. dx0 = cx0 - x00,
  14992. dy0 = cy0 - y00,
  14993. dx1 = cx1 - x00,
  14994. dy1 = cy1 - y00;
  14995. // Pick the closer of the two intersection points.
  14996. // TODO Is there a faster way to determine which intersection to use?
  14997. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  14998. return {
  14999. cx: cx0,
  15000. cy: cy0,
  15001. x01: -ox,
  15002. y01: -oy,
  15003. x11: cx0 * (r1 / r - 1),
  15004. y11: cy0 * (r1 / r - 1)
  15005. };
  15006. }
  15007. function arc() {
  15008. var innerRadius = arcInnerRadius,
  15009. outerRadius = arcOuterRadius,
  15010. cornerRadius = constant$1(0),
  15011. padRadius = null,
  15012. startAngle = arcStartAngle,
  15013. endAngle = arcEndAngle,
  15014. padAngle = arcPadAngle,
  15015. context = null,
  15016. path = withPath(arc);
  15017. function arc() {
  15018. var buffer,
  15019. r,
  15020. r0 = +innerRadius.apply(this, arguments),
  15021. r1 = +outerRadius.apply(this, arguments),
  15022. a0 = startAngle.apply(this, arguments) - halfPi,
  15023. a1 = endAngle.apply(this, arguments) - halfPi,
  15024. da = abs(a1 - a0),
  15025. cw = a1 > a0;
  15026. if (!context) context = buffer = path();
  15027. // Ensure that the outer radius is always larger than the inner radius.
  15028. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  15029. // Is it a point?
  15030. if (!(r1 > epsilon)) context.moveTo(0, 0);
  15031. // Or is it a circle or annulus?
  15032. else if (da > tau - epsilon) {
  15033. context.moveTo(r1 * cos(a0), r1 * sin(a0));
  15034. context.arc(0, 0, r1, a0, a1, !cw);
  15035. if (r0 > epsilon) {
  15036. context.moveTo(r0 * cos(a1), r0 * sin(a1));
  15037. context.arc(0, 0, r0, a1, a0, cw);
  15038. }
  15039. }
  15040. // Or is it a circular or annular sector?
  15041. else {
  15042. var a01 = a0,
  15043. a11 = a1,
  15044. a00 = a0,
  15045. a10 = a1,
  15046. da0 = da,
  15047. da1 = da,
  15048. ap = padAngle.apply(this, arguments) / 2,
  15049. rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
  15050. rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  15051. rc0 = rc,
  15052. rc1 = rc,
  15053. t0,
  15054. t1;
  15055. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  15056. if (rp > epsilon) {
  15057. var p0 = asin(rp / r0 * sin(ap)),
  15058. p1 = asin(rp / r1 * sin(ap));
  15059. if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  15060. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  15061. if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  15062. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  15063. }
  15064. var x01 = r1 * cos(a01),
  15065. y01 = r1 * sin(a01),
  15066. x10 = r0 * cos(a10),
  15067. y10 = r0 * sin(a10);
  15068. // Apply rounded corners?
  15069. if (rc > epsilon) {
  15070. var x11 = r1 * cos(a11),
  15071. y11 = r1 * sin(a11),
  15072. x00 = r0 * cos(a00),
  15073. y00 = r0 * sin(a00),
  15074. oc;
  15075. // Restrict the corner radius according to the sector angle. If this
  15076. // intersection fails, it’s probably because the arc is too small, so
  15077. // disable the corner radius entirely.
  15078. if (da < pi) {
  15079. if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
  15080. var ax = x01 - oc[0],
  15081. ay = y01 - oc[1],
  15082. bx = x11 - oc[0],
  15083. by = y11 - oc[1],
  15084. kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
  15085. lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  15086. rc0 = min(rc, (r0 - lc) / (kc - 1));
  15087. rc1 = min(rc, (r1 - lc) / (kc + 1));
  15088. } else {
  15089. rc0 = rc1 = 0;
  15090. }
  15091. }
  15092. }
  15093. // Is the sector collapsed to a line?
  15094. if (!(da1 > epsilon)) context.moveTo(x01, y01);
  15095. // Does the sector’s outer ring have rounded corners?
  15096. else if (rc1 > epsilon) {
  15097. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  15098. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  15099. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15100. // Have the corners merged?
  15101. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15102. // Otherwise, draw the two corners and the ring.
  15103. else {
  15104. context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15105. context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  15106. context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15107. }
  15108. }
  15109. // Or is the outer ring just a circular arc?
  15110. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  15111. // Is there no inner ring, and it’s a circular sector?
  15112. // Or perhaps it’s an annular sector collapsed due to padding?
  15113. if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
  15114. // Does the sector’s inner ring (or point) have rounded corners?
  15115. else if (rc0 > epsilon) {
  15116. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  15117. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  15118. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15119. // Have the corners merged?
  15120. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15121. // Otherwise, draw the two corners and the ring.
  15122. else {
  15123. context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15124. context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  15125. context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15126. }
  15127. }
  15128. // Or is the inner ring just a circular arc?
  15129. else context.arc(0, 0, r0, a10, a00, cw);
  15130. }
  15131. context.closePath();
  15132. if (buffer) return context = null, buffer + "" || null;
  15133. }
  15134. arc.centroid = function() {
  15135. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  15136. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
  15137. return [cos(a) * r, sin(a) * r];
  15138. };
  15139. arc.innerRadius = function(_) {
  15140. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
  15141. };
  15142. arc.outerRadius = function(_) {
  15143. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
  15144. };
  15145. arc.cornerRadius = function(_) {
  15146. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
  15147. };
  15148. arc.padRadius = function(_) {
  15149. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
  15150. };
  15151. arc.startAngle = function(_) {
  15152. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
  15153. };
  15154. arc.endAngle = function(_) {
  15155. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
  15156. };
  15157. arc.padAngle = function(_) {
  15158. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
  15159. };
  15160. arc.context = function(_) {
  15161. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  15162. };
  15163. return arc;
  15164. }
  15165. var slice = Array.prototype.slice;
  15166. function array(x) {
  15167. return typeof x === "object" && "length" in x
  15168. ? x // Array, TypedArray, NodeList, array-like
  15169. : Array.from(x); // Map, Set, iterable, string, or anything else
  15170. }
  15171. function Linear(context) {
  15172. this._context = context;
  15173. }
  15174. Linear.prototype = {
  15175. areaStart: function() {
  15176. this._line = 0;
  15177. },
  15178. areaEnd: function() {
  15179. this._line = NaN;
  15180. },
  15181. lineStart: function() {
  15182. this._point = 0;
  15183. },
  15184. lineEnd: function() {
  15185. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15186. this._line = 1 - this._line;
  15187. },
  15188. point: function(x, y) {
  15189. x = +x, y = +y;
  15190. switch (this._point) {
  15191. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15192. case 1: this._point = 2; // falls through
  15193. default: this._context.lineTo(x, y); break;
  15194. }
  15195. }
  15196. };
  15197. function curveLinear(context) {
  15198. return new Linear(context);
  15199. }
  15200. function x(p) {
  15201. return p[0];
  15202. }
  15203. function y(p) {
  15204. return p[1];
  15205. }
  15206. function line(x$1, y$1) {
  15207. var defined = constant$1(true),
  15208. context = null,
  15209. curve = curveLinear,
  15210. output = null,
  15211. path = withPath(line);
  15212. x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1);
  15213. y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
  15214. function line(data) {
  15215. var i,
  15216. n = (data = array(data)).length,
  15217. d,
  15218. defined0 = false,
  15219. buffer;
  15220. if (context == null) output = curve(buffer = path());
  15221. for (i = 0; i <= n; ++i) {
  15222. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15223. if (defined0 = !defined0) output.lineStart();
  15224. else output.lineEnd();
  15225. }
  15226. if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
  15227. }
  15228. if (buffer) return output = null, buffer + "" || null;
  15229. }
  15230. line.x = function(_) {
  15231. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1;
  15232. };
  15233. line.y = function(_) {
  15234. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
  15235. };
  15236. line.defined = function(_) {
  15237. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
  15238. };
  15239. line.curve = function(_) {
  15240. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  15241. };
  15242. line.context = function(_) {
  15243. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  15244. };
  15245. return line;
  15246. }
  15247. function area(x0, y0, y1) {
  15248. var x1 = null,
  15249. defined = constant$1(true),
  15250. context = null,
  15251. curve = curveLinear,
  15252. output = null,
  15253. path = withPath(area);
  15254. x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0);
  15255. y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
  15256. y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
  15257. function area(data) {
  15258. var i,
  15259. j,
  15260. k,
  15261. n = (data = array(data)).length,
  15262. d,
  15263. defined0 = false,
  15264. buffer,
  15265. x0z = new Array(n),
  15266. y0z = new Array(n);
  15267. if (context == null) output = curve(buffer = path());
  15268. for (i = 0; i <= n; ++i) {
  15269. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15270. if (defined0 = !defined0) {
  15271. j = i;
  15272. output.areaStart();
  15273. output.lineStart();
  15274. } else {
  15275. output.lineEnd();
  15276. output.lineStart();
  15277. for (k = i - 1; k >= j; --k) {
  15278. output.point(x0z[k], y0z[k]);
  15279. }
  15280. output.lineEnd();
  15281. output.areaEnd();
  15282. }
  15283. }
  15284. if (defined0) {
  15285. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  15286. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  15287. }
  15288. }
  15289. if (buffer) return output = null, buffer + "" || null;
  15290. }
  15291. function arealine() {
  15292. return line().defined(defined).curve(curve).context(context);
  15293. }
  15294. area.x = function(_) {
  15295. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
  15296. };
  15297. area.x0 = function(_) {
  15298. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
  15299. };
  15300. area.x1 = function(_) {
  15301. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
  15302. };
  15303. area.y = function(_) {
  15304. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
  15305. };
  15306. area.y0 = function(_) {
  15307. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
  15308. };
  15309. area.y1 = function(_) {
  15310. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
  15311. };
  15312. area.lineX0 =
  15313. area.lineY0 = function() {
  15314. return arealine().x(x0).y(y0);
  15315. };
  15316. area.lineY1 = function() {
  15317. return arealine().x(x0).y(y1);
  15318. };
  15319. area.lineX1 = function() {
  15320. return arealine().x(x1).y(y0);
  15321. };
  15322. area.defined = function(_) {
  15323. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
  15324. };
  15325. area.curve = function(_) {
  15326. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  15327. };
  15328. area.context = function(_) {
  15329. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  15330. };
  15331. return area;
  15332. }
  15333. function descending$1(a, b) {
  15334. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  15335. }
  15336. function identity$1(d) {
  15337. return d;
  15338. }
  15339. function pie() {
  15340. var value = identity$1,
  15341. sortValues = descending$1,
  15342. sort = null,
  15343. startAngle = constant$1(0),
  15344. endAngle = constant$1(tau),
  15345. padAngle = constant$1(0);
  15346. function pie(data) {
  15347. var i,
  15348. n = (data = array(data)).length,
  15349. j,
  15350. k,
  15351. sum = 0,
  15352. index = new Array(n),
  15353. arcs = new Array(n),
  15354. a0 = +startAngle.apply(this, arguments),
  15355. da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
  15356. a1,
  15357. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  15358. pa = p * (da < 0 ? -1 : 1),
  15359. v;
  15360. for (i = 0; i < n; ++i) {
  15361. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  15362. sum += v;
  15363. }
  15364. }
  15365. // Optionally sort the arcs by previously-computed values or by data.
  15366. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  15367. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  15368. // Compute the arcs! They are stored in the original data's order.
  15369. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  15370. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  15371. data: data[j],
  15372. index: i,
  15373. value: v,
  15374. startAngle: a0,
  15375. endAngle: a1,
  15376. padAngle: p
  15377. };
  15378. }
  15379. return arcs;
  15380. }
  15381. pie.value = function(_) {
  15382. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
  15383. };
  15384. pie.sortValues = function(_) {
  15385. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  15386. };
  15387. pie.sort = function(_) {
  15388. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  15389. };
  15390. pie.startAngle = function(_) {
  15391. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
  15392. };
  15393. pie.endAngle = function(_) {
  15394. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
  15395. };
  15396. pie.padAngle = function(_) {
  15397. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
  15398. };
  15399. return pie;
  15400. }
  15401. var curveRadialLinear = curveRadial(curveLinear);
  15402. function Radial(curve) {
  15403. this._curve = curve;
  15404. }
  15405. Radial.prototype = {
  15406. areaStart: function() {
  15407. this._curve.areaStart();
  15408. },
  15409. areaEnd: function() {
  15410. this._curve.areaEnd();
  15411. },
  15412. lineStart: function() {
  15413. this._curve.lineStart();
  15414. },
  15415. lineEnd: function() {
  15416. this._curve.lineEnd();
  15417. },
  15418. point: function(a, r) {
  15419. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  15420. }
  15421. };
  15422. function curveRadial(curve) {
  15423. function radial(context) {
  15424. return new Radial(curve(context));
  15425. }
  15426. radial._curve = curve;
  15427. return radial;
  15428. }
  15429. function lineRadial(l) {
  15430. var c = l.curve;
  15431. l.angle = l.x, delete l.x;
  15432. l.radius = l.y, delete l.y;
  15433. l.curve = function(_) {
  15434. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15435. };
  15436. return l;
  15437. }
  15438. function lineRadial$1() {
  15439. return lineRadial(line().curve(curveRadialLinear));
  15440. }
  15441. function areaRadial() {
  15442. var a = area().curve(curveRadialLinear),
  15443. c = a.curve,
  15444. x0 = a.lineX0,
  15445. x1 = a.lineX1,
  15446. y0 = a.lineY0,
  15447. y1 = a.lineY1;
  15448. a.angle = a.x, delete a.x;
  15449. a.startAngle = a.x0, delete a.x0;
  15450. a.endAngle = a.x1, delete a.x1;
  15451. a.radius = a.y, delete a.y;
  15452. a.innerRadius = a.y0, delete a.y0;
  15453. a.outerRadius = a.y1, delete a.y1;
  15454. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  15455. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  15456. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  15457. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  15458. a.curve = function(_) {
  15459. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15460. };
  15461. return a;
  15462. }
  15463. function pointRadial(x, y) {
  15464. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  15465. }
  15466. class Bump {
  15467. constructor(context, x) {
  15468. this._context = context;
  15469. this._x = x;
  15470. }
  15471. areaStart() {
  15472. this._line = 0;
  15473. }
  15474. areaEnd() {
  15475. this._line = NaN;
  15476. }
  15477. lineStart() {
  15478. this._point = 0;
  15479. }
  15480. lineEnd() {
  15481. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15482. this._line = 1 - this._line;
  15483. }
  15484. point(x, y) {
  15485. x = +x, y = +y;
  15486. switch (this._point) {
  15487. case 0: {
  15488. this._point = 1;
  15489. if (this._line) this._context.lineTo(x, y);
  15490. else this._context.moveTo(x, y);
  15491. break;
  15492. }
  15493. case 1: this._point = 2; // falls through
  15494. default: {
  15495. if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
  15496. else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
  15497. break;
  15498. }
  15499. }
  15500. this._x0 = x, this._y0 = y;
  15501. }
  15502. }
  15503. class BumpRadial {
  15504. constructor(context) {
  15505. this._context = context;
  15506. }
  15507. lineStart() {
  15508. this._point = 0;
  15509. }
  15510. lineEnd() {}
  15511. point(x, y) {
  15512. x = +x, y = +y;
  15513. if (this._point === 0) {
  15514. this._point = 1;
  15515. } else {
  15516. const p0 = pointRadial(this._x0, this._y0);
  15517. const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
  15518. const p2 = pointRadial(x, this._y0);
  15519. const p3 = pointRadial(x, y);
  15520. this._context.moveTo(...p0);
  15521. this._context.bezierCurveTo(...p1, ...p2, ...p3);
  15522. }
  15523. this._x0 = x, this._y0 = y;
  15524. }
  15525. }
  15526. function bumpX(context) {
  15527. return new Bump(context, true);
  15528. }
  15529. function bumpY(context) {
  15530. return new Bump(context, false);
  15531. }
  15532. function bumpRadial(context) {
  15533. return new BumpRadial(context);
  15534. }
  15535. function linkSource(d) {
  15536. return d.source;
  15537. }
  15538. function linkTarget(d) {
  15539. return d.target;
  15540. }
  15541. function link(curve) {
  15542. let source = linkSource,
  15543. target = linkTarget,
  15544. x$1 = x,
  15545. y$1 = y,
  15546. context = null,
  15547. output = null,
  15548. path = withPath(link);
  15549. function link() {
  15550. let buffer;
  15551. const argv = slice.call(arguments);
  15552. const s = source.apply(this, argv);
  15553. const t = target.apply(this, argv);
  15554. if (context == null) output = curve(buffer = path());
  15555. output.lineStart();
  15556. argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15557. argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15558. output.lineEnd();
  15559. if (buffer) return output = null, buffer + "" || null;
  15560. }
  15561. link.source = function(_) {
  15562. return arguments.length ? (source = _, link) : source;
  15563. };
  15564. link.target = function(_) {
  15565. return arguments.length ? (target = _, link) : target;
  15566. };
  15567. link.x = function(_) {
  15568. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1;
  15569. };
  15570. link.y = function(_) {
  15571. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
  15572. };
  15573. link.context = function(_) {
  15574. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
  15575. };
  15576. return link;
  15577. }
  15578. function linkHorizontal() {
  15579. return link(bumpX);
  15580. }
  15581. function linkVertical() {
  15582. return link(bumpY);
  15583. }
  15584. function linkRadial() {
  15585. const l = link(bumpRadial);
  15586. l.angle = l.x, delete l.x;
  15587. l.radius = l.y, delete l.y;
  15588. return l;
  15589. }
  15590. const sqrt3$2 = sqrt(3);
  15591. var asterisk = {
  15592. draw(context, size) {
  15593. const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
  15594. const t = r / 2;
  15595. const u = t * sqrt3$2;
  15596. context.moveTo(0, r);
  15597. context.lineTo(0, -r);
  15598. context.moveTo(-u, -t);
  15599. context.lineTo(u, t);
  15600. context.moveTo(-u, t);
  15601. context.lineTo(u, -t);
  15602. }
  15603. };
  15604. var circle = {
  15605. draw(context, size) {
  15606. const r = sqrt(size / pi);
  15607. context.moveTo(r, 0);
  15608. context.arc(0, 0, r, 0, tau);
  15609. }
  15610. };
  15611. var cross = {
  15612. draw(context, size) {
  15613. const r = sqrt(size / 5) / 2;
  15614. context.moveTo(-3 * r, -r);
  15615. context.lineTo(-r, -r);
  15616. context.lineTo(-r, -3 * r);
  15617. context.lineTo(r, -3 * r);
  15618. context.lineTo(r, -r);
  15619. context.lineTo(3 * r, -r);
  15620. context.lineTo(3 * r, r);
  15621. context.lineTo(r, r);
  15622. context.lineTo(r, 3 * r);
  15623. context.lineTo(-r, 3 * r);
  15624. context.lineTo(-r, r);
  15625. context.lineTo(-3 * r, r);
  15626. context.closePath();
  15627. }
  15628. };
  15629. const tan30 = sqrt(1 / 3);
  15630. const tan30_2 = tan30 * 2;
  15631. var diamond = {
  15632. draw(context, size) {
  15633. const y = sqrt(size / tan30_2);
  15634. const x = y * tan30;
  15635. context.moveTo(0, -y);
  15636. context.lineTo(x, 0);
  15637. context.lineTo(0, y);
  15638. context.lineTo(-x, 0);
  15639. context.closePath();
  15640. }
  15641. };
  15642. var diamond2 = {
  15643. draw(context, size) {
  15644. const r = sqrt(size) * 0.62625;
  15645. context.moveTo(0, -r);
  15646. context.lineTo(r, 0);
  15647. context.lineTo(0, r);
  15648. context.lineTo(-r, 0);
  15649. context.closePath();
  15650. }
  15651. };
  15652. var plus = {
  15653. draw(context, size) {
  15654. const r = sqrt(size - min(size / 7, 2)) * 0.87559;
  15655. context.moveTo(-r, 0);
  15656. context.lineTo(r, 0);
  15657. context.moveTo(0, r);
  15658. context.lineTo(0, -r);
  15659. }
  15660. };
  15661. var square = {
  15662. draw(context, size) {
  15663. const w = sqrt(size);
  15664. const x = -w / 2;
  15665. context.rect(x, x, w, w);
  15666. }
  15667. };
  15668. var square2 = {
  15669. draw(context, size) {
  15670. const r = sqrt(size) * 0.4431;
  15671. context.moveTo(r, r);
  15672. context.lineTo(r, -r);
  15673. context.lineTo(-r, -r);
  15674. context.lineTo(-r, r);
  15675. context.closePath();
  15676. }
  15677. };
  15678. const ka = 0.89081309152928522810;
  15679. const kr = sin(pi / 10) / sin(7 * pi / 10);
  15680. const kx = sin(tau / 10) * kr;
  15681. const ky = -cos(tau / 10) * kr;
  15682. var star = {
  15683. draw(context, size) {
  15684. const r = sqrt(size * ka);
  15685. const x = kx * r;
  15686. const y = ky * r;
  15687. context.moveTo(0, -r);
  15688. context.lineTo(x, y);
  15689. for (let i = 1; i < 5; ++i) {
  15690. const a = tau * i / 5;
  15691. const c = cos(a);
  15692. const s = sin(a);
  15693. context.lineTo(s * r, -c * r);
  15694. context.lineTo(c * x - s * y, s * x + c * y);
  15695. }
  15696. context.closePath();
  15697. }
  15698. };
  15699. const sqrt3$1 = sqrt(3);
  15700. var triangle = {
  15701. draw(context, size) {
  15702. const y = -sqrt(size / (sqrt3$1 * 3));
  15703. context.moveTo(0, y * 2);
  15704. context.lineTo(-sqrt3$1 * y, -y);
  15705. context.lineTo(sqrt3$1 * y, -y);
  15706. context.closePath();
  15707. }
  15708. };
  15709. const sqrt3 = sqrt(3);
  15710. var triangle2 = {
  15711. draw(context, size) {
  15712. const s = sqrt(size) * 0.6824;
  15713. const t = s / 2;
  15714. const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
  15715. context.moveTo(0, -s);
  15716. context.lineTo(u, t);
  15717. context.lineTo(-u, t);
  15718. context.closePath();
  15719. }
  15720. };
  15721. const c = -0.5;
  15722. const s = sqrt(3) / 2;
  15723. const k = 1 / sqrt(12);
  15724. const a = (k / 2 + 1) * 3;
  15725. var wye = {
  15726. draw(context, size) {
  15727. const r = sqrt(size / a);
  15728. const x0 = r / 2, y0 = r * k;
  15729. const x1 = x0, y1 = r * k + r;
  15730. const x2 = -x1, y2 = y1;
  15731. context.moveTo(x0, y0);
  15732. context.lineTo(x1, y1);
  15733. context.lineTo(x2, y2);
  15734. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  15735. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  15736. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  15737. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  15738. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  15739. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  15740. context.closePath();
  15741. }
  15742. };
  15743. var times = {
  15744. draw(context, size) {
  15745. const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
  15746. context.moveTo(-r, -r);
  15747. context.lineTo(r, r);
  15748. context.moveTo(-r, r);
  15749. context.lineTo(r, -r);
  15750. }
  15751. };
  15752. // These symbols are designed to be filled.
  15753. const symbolsFill = [
  15754. circle,
  15755. cross,
  15756. diamond,
  15757. square,
  15758. star,
  15759. triangle,
  15760. wye
  15761. ];
  15762. // These symbols are designed to be stroked (with a width of 1.5px and round caps).
  15763. const symbolsStroke = [
  15764. circle,
  15765. plus,
  15766. times,
  15767. triangle2,
  15768. asterisk,
  15769. square2,
  15770. diamond2
  15771. ];
  15772. function Symbol$1(type, size) {
  15773. let context = null,
  15774. path = withPath(symbol);
  15775. type = typeof type === "function" ? type : constant$1(type || circle);
  15776. size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
  15777. function symbol() {
  15778. let buffer;
  15779. if (!context) context = buffer = path();
  15780. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  15781. if (buffer) return context = null, buffer + "" || null;
  15782. }
  15783. symbol.type = function(_) {
  15784. return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
  15785. };
  15786. symbol.size = function(_) {
  15787. return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
  15788. };
  15789. symbol.context = function(_) {
  15790. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  15791. };
  15792. return symbol;
  15793. }
  15794. function noop() {}
  15795. function point$3(that, x, y) {
  15796. that._context.bezierCurveTo(
  15797. (2 * that._x0 + that._x1) / 3,
  15798. (2 * that._y0 + that._y1) / 3,
  15799. (that._x0 + 2 * that._x1) / 3,
  15800. (that._y0 + 2 * that._y1) / 3,
  15801. (that._x0 + 4 * that._x1 + x) / 6,
  15802. (that._y0 + 4 * that._y1 + y) / 6
  15803. );
  15804. }
  15805. function Basis(context) {
  15806. this._context = context;
  15807. }
  15808. Basis.prototype = {
  15809. areaStart: function() {
  15810. this._line = 0;
  15811. },
  15812. areaEnd: function() {
  15813. this._line = NaN;
  15814. },
  15815. lineStart: function() {
  15816. this._x0 = this._x1 =
  15817. this._y0 = this._y1 = NaN;
  15818. this._point = 0;
  15819. },
  15820. lineEnd: function() {
  15821. switch (this._point) {
  15822. case 3: point$3(this, this._x1, this._y1); // falls through
  15823. case 2: this._context.lineTo(this._x1, this._y1); break;
  15824. }
  15825. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15826. this._line = 1 - this._line;
  15827. },
  15828. point: function(x, y) {
  15829. x = +x, y = +y;
  15830. switch (this._point) {
  15831. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15832. case 1: this._point = 2; break;
  15833. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
  15834. default: point$3(this, x, y); break;
  15835. }
  15836. this._x0 = this._x1, this._x1 = x;
  15837. this._y0 = this._y1, this._y1 = y;
  15838. }
  15839. };
  15840. function basis(context) {
  15841. return new Basis(context);
  15842. }
  15843. function BasisClosed(context) {
  15844. this._context = context;
  15845. }
  15846. BasisClosed.prototype = {
  15847. areaStart: noop,
  15848. areaEnd: noop,
  15849. lineStart: function() {
  15850. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  15851. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  15852. this._point = 0;
  15853. },
  15854. lineEnd: function() {
  15855. switch (this._point) {
  15856. case 1: {
  15857. this._context.moveTo(this._x2, this._y2);
  15858. this._context.closePath();
  15859. break;
  15860. }
  15861. case 2: {
  15862. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  15863. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  15864. this._context.closePath();
  15865. break;
  15866. }
  15867. case 3: {
  15868. this.point(this._x2, this._y2);
  15869. this.point(this._x3, this._y3);
  15870. this.point(this._x4, this._y4);
  15871. break;
  15872. }
  15873. }
  15874. },
  15875. point: function(x, y) {
  15876. x = +x, y = +y;
  15877. switch (this._point) {
  15878. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  15879. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  15880. case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
  15881. default: point$3(this, x, y); break;
  15882. }
  15883. this._x0 = this._x1, this._x1 = x;
  15884. this._y0 = this._y1, this._y1 = y;
  15885. }
  15886. };
  15887. function basisClosed(context) {
  15888. return new BasisClosed(context);
  15889. }
  15890. function BasisOpen(context) {
  15891. this._context = context;
  15892. }
  15893. BasisOpen.prototype = {
  15894. areaStart: function() {
  15895. this._line = 0;
  15896. },
  15897. areaEnd: function() {
  15898. this._line = NaN;
  15899. },
  15900. lineStart: function() {
  15901. this._x0 = this._x1 =
  15902. this._y0 = this._y1 = NaN;
  15903. this._point = 0;
  15904. },
  15905. lineEnd: function() {
  15906. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15907. this._line = 1 - this._line;
  15908. },
  15909. point: function(x, y) {
  15910. x = +x, y = +y;
  15911. switch (this._point) {
  15912. case 0: this._point = 1; break;
  15913. case 1: this._point = 2; break;
  15914. case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
  15915. case 3: this._point = 4; // falls through
  15916. default: point$3(this, x, y); break;
  15917. }
  15918. this._x0 = this._x1, this._x1 = x;
  15919. this._y0 = this._y1, this._y1 = y;
  15920. }
  15921. };
  15922. function basisOpen(context) {
  15923. return new BasisOpen(context);
  15924. }
  15925. function Bundle(context, beta) {
  15926. this._basis = new Basis(context);
  15927. this._beta = beta;
  15928. }
  15929. Bundle.prototype = {
  15930. lineStart: function() {
  15931. this._x = [];
  15932. this._y = [];
  15933. this._basis.lineStart();
  15934. },
  15935. lineEnd: function() {
  15936. var x = this._x,
  15937. y = this._y,
  15938. j = x.length - 1;
  15939. if (j > 0) {
  15940. var x0 = x[0],
  15941. y0 = y[0],
  15942. dx = x[j] - x0,
  15943. dy = y[j] - y0,
  15944. i = -1,
  15945. t;
  15946. while (++i <= j) {
  15947. t = i / j;
  15948. this._basis.point(
  15949. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  15950. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  15951. );
  15952. }
  15953. }
  15954. this._x = this._y = null;
  15955. this._basis.lineEnd();
  15956. },
  15957. point: function(x, y) {
  15958. this._x.push(+x);
  15959. this._y.push(+y);
  15960. }
  15961. };
  15962. var bundle = (function custom(beta) {
  15963. function bundle(context) {
  15964. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  15965. }
  15966. bundle.beta = function(beta) {
  15967. return custom(+beta);
  15968. };
  15969. return bundle;
  15970. })(0.85);
  15971. function point$2(that, x, y) {
  15972. that._context.bezierCurveTo(
  15973. that._x1 + that._k * (that._x2 - that._x0),
  15974. that._y1 + that._k * (that._y2 - that._y0),
  15975. that._x2 + that._k * (that._x1 - x),
  15976. that._y2 + that._k * (that._y1 - y),
  15977. that._x2,
  15978. that._y2
  15979. );
  15980. }
  15981. function Cardinal(context, tension) {
  15982. this._context = context;
  15983. this._k = (1 - tension) / 6;
  15984. }
  15985. Cardinal.prototype = {
  15986. areaStart: function() {
  15987. this._line = 0;
  15988. },
  15989. areaEnd: function() {
  15990. this._line = NaN;
  15991. },
  15992. lineStart: function() {
  15993. this._x0 = this._x1 = this._x2 =
  15994. this._y0 = this._y1 = this._y2 = NaN;
  15995. this._point = 0;
  15996. },
  15997. lineEnd: function() {
  15998. switch (this._point) {
  15999. case 2: this._context.lineTo(this._x2, this._y2); break;
  16000. case 3: point$2(this, this._x1, this._y1); break;
  16001. }
  16002. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16003. this._line = 1 - this._line;
  16004. },
  16005. point: function(x, y) {
  16006. x = +x, y = +y;
  16007. switch (this._point) {
  16008. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16009. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  16010. case 2: this._point = 3; // falls through
  16011. default: point$2(this, x, y); break;
  16012. }
  16013. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16014. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16015. }
  16016. };
  16017. var cardinal = (function custom(tension) {
  16018. function cardinal(context) {
  16019. return new Cardinal(context, tension);
  16020. }
  16021. cardinal.tension = function(tension) {
  16022. return custom(+tension);
  16023. };
  16024. return cardinal;
  16025. })(0);
  16026. function CardinalClosed(context, tension) {
  16027. this._context = context;
  16028. this._k = (1 - tension) / 6;
  16029. }
  16030. CardinalClosed.prototype = {
  16031. areaStart: noop,
  16032. areaEnd: noop,
  16033. lineStart: function() {
  16034. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16035. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16036. this._point = 0;
  16037. },
  16038. lineEnd: function() {
  16039. switch (this._point) {
  16040. case 1: {
  16041. this._context.moveTo(this._x3, this._y3);
  16042. this._context.closePath();
  16043. break;
  16044. }
  16045. case 2: {
  16046. this._context.lineTo(this._x3, this._y3);
  16047. this._context.closePath();
  16048. break;
  16049. }
  16050. case 3: {
  16051. this.point(this._x3, this._y3);
  16052. this.point(this._x4, this._y4);
  16053. this.point(this._x5, this._y5);
  16054. break;
  16055. }
  16056. }
  16057. },
  16058. point: function(x, y) {
  16059. x = +x, y = +y;
  16060. switch (this._point) {
  16061. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16062. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16063. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16064. default: point$2(this, x, y); break;
  16065. }
  16066. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16067. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16068. }
  16069. };
  16070. var cardinalClosed = (function custom(tension) {
  16071. function cardinal(context) {
  16072. return new CardinalClosed(context, tension);
  16073. }
  16074. cardinal.tension = function(tension) {
  16075. return custom(+tension);
  16076. };
  16077. return cardinal;
  16078. })(0);
  16079. function CardinalOpen(context, tension) {
  16080. this._context = context;
  16081. this._k = (1 - tension) / 6;
  16082. }
  16083. CardinalOpen.prototype = {
  16084. areaStart: function() {
  16085. this._line = 0;
  16086. },
  16087. areaEnd: function() {
  16088. this._line = NaN;
  16089. },
  16090. lineStart: function() {
  16091. this._x0 = this._x1 = this._x2 =
  16092. this._y0 = this._y1 = this._y2 = NaN;
  16093. this._point = 0;
  16094. },
  16095. lineEnd: function() {
  16096. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16097. this._line = 1 - this._line;
  16098. },
  16099. point: function(x, y) {
  16100. x = +x, y = +y;
  16101. switch (this._point) {
  16102. case 0: this._point = 1; break;
  16103. case 1: this._point = 2; break;
  16104. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16105. case 3: this._point = 4; // falls through
  16106. default: point$2(this, x, y); break;
  16107. }
  16108. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16109. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16110. }
  16111. };
  16112. var cardinalOpen = (function custom(tension) {
  16113. function cardinal(context) {
  16114. return new CardinalOpen(context, tension);
  16115. }
  16116. cardinal.tension = function(tension) {
  16117. return custom(+tension);
  16118. };
  16119. return cardinal;
  16120. })(0);
  16121. function point$1(that, x, y) {
  16122. var x1 = that._x1,
  16123. y1 = that._y1,
  16124. x2 = that._x2,
  16125. y2 = that._y2;
  16126. if (that._l01_a > epsilon) {
  16127. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  16128. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  16129. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  16130. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  16131. }
  16132. if (that._l23_a > epsilon) {
  16133. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  16134. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  16135. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  16136. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  16137. }
  16138. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  16139. }
  16140. function CatmullRom(context, alpha) {
  16141. this._context = context;
  16142. this._alpha = alpha;
  16143. }
  16144. CatmullRom.prototype = {
  16145. areaStart: function() {
  16146. this._line = 0;
  16147. },
  16148. areaEnd: function() {
  16149. this._line = NaN;
  16150. },
  16151. lineStart: function() {
  16152. this._x0 = this._x1 = this._x2 =
  16153. this._y0 = this._y1 = this._y2 = NaN;
  16154. this._l01_a = this._l12_a = this._l23_a =
  16155. this._l01_2a = this._l12_2a = this._l23_2a =
  16156. this._point = 0;
  16157. },
  16158. lineEnd: function() {
  16159. switch (this._point) {
  16160. case 2: this._context.lineTo(this._x2, this._y2); break;
  16161. case 3: this.point(this._x2, this._y2); break;
  16162. }
  16163. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16164. this._line = 1 - this._line;
  16165. },
  16166. point: function(x, y) {
  16167. x = +x, y = +y;
  16168. if (this._point) {
  16169. var x23 = this._x2 - x,
  16170. y23 = this._y2 - y;
  16171. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16172. }
  16173. switch (this._point) {
  16174. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16175. case 1: this._point = 2; break;
  16176. case 2: this._point = 3; // falls through
  16177. default: point$1(this, x, y); break;
  16178. }
  16179. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16180. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16181. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16182. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16183. }
  16184. };
  16185. var catmullRom = (function custom(alpha) {
  16186. function catmullRom(context) {
  16187. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  16188. }
  16189. catmullRom.alpha = function(alpha) {
  16190. return custom(+alpha);
  16191. };
  16192. return catmullRom;
  16193. })(0.5);
  16194. function CatmullRomClosed(context, alpha) {
  16195. this._context = context;
  16196. this._alpha = alpha;
  16197. }
  16198. CatmullRomClosed.prototype = {
  16199. areaStart: noop,
  16200. areaEnd: noop,
  16201. lineStart: function() {
  16202. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16203. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16204. this._l01_a = this._l12_a = this._l23_a =
  16205. this._l01_2a = this._l12_2a = this._l23_2a =
  16206. this._point = 0;
  16207. },
  16208. lineEnd: function() {
  16209. switch (this._point) {
  16210. case 1: {
  16211. this._context.moveTo(this._x3, this._y3);
  16212. this._context.closePath();
  16213. break;
  16214. }
  16215. case 2: {
  16216. this._context.lineTo(this._x3, this._y3);
  16217. this._context.closePath();
  16218. break;
  16219. }
  16220. case 3: {
  16221. this.point(this._x3, this._y3);
  16222. this.point(this._x4, this._y4);
  16223. this.point(this._x5, this._y5);
  16224. break;
  16225. }
  16226. }
  16227. },
  16228. point: function(x, y) {
  16229. x = +x, y = +y;
  16230. if (this._point) {
  16231. var x23 = this._x2 - x,
  16232. y23 = this._y2 - y;
  16233. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16234. }
  16235. switch (this._point) {
  16236. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16237. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16238. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16239. default: point$1(this, x, y); break;
  16240. }
  16241. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16242. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16243. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16244. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16245. }
  16246. };
  16247. var catmullRomClosed = (function custom(alpha) {
  16248. function catmullRom(context) {
  16249. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  16250. }
  16251. catmullRom.alpha = function(alpha) {
  16252. return custom(+alpha);
  16253. };
  16254. return catmullRom;
  16255. })(0.5);
  16256. function CatmullRomOpen(context, alpha) {
  16257. this._context = context;
  16258. this._alpha = alpha;
  16259. }
  16260. CatmullRomOpen.prototype = {
  16261. areaStart: function() {
  16262. this._line = 0;
  16263. },
  16264. areaEnd: function() {
  16265. this._line = NaN;
  16266. },
  16267. lineStart: function() {
  16268. this._x0 = this._x1 = this._x2 =
  16269. this._y0 = this._y1 = this._y2 = NaN;
  16270. this._l01_a = this._l12_a = this._l23_a =
  16271. this._l01_2a = this._l12_2a = this._l23_2a =
  16272. this._point = 0;
  16273. },
  16274. lineEnd: function() {
  16275. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16276. this._line = 1 - this._line;
  16277. },
  16278. point: function(x, y) {
  16279. x = +x, y = +y;
  16280. if (this._point) {
  16281. var x23 = this._x2 - x,
  16282. y23 = this._y2 - y;
  16283. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16284. }
  16285. switch (this._point) {
  16286. case 0: this._point = 1; break;
  16287. case 1: this._point = 2; break;
  16288. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16289. case 3: this._point = 4; // falls through
  16290. default: point$1(this, x, y); break;
  16291. }
  16292. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16293. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16294. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16295. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16296. }
  16297. };
  16298. var catmullRomOpen = (function custom(alpha) {
  16299. function catmullRom(context) {
  16300. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  16301. }
  16302. catmullRom.alpha = function(alpha) {
  16303. return custom(+alpha);
  16304. };
  16305. return catmullRom;
  16306. })(0.5);
  16307. function LinearClosed(context) {
  16308. this._context = context;
  16309. }
  16310. LinearClosed.prototype = {
  16311. areaStart: noop,
  16312. areaEnd: noop,
  16313. lineStart: function() {
  16314. this._point = 0;
  16315. },
  16316. lineEnd: function() {
  16317. if (this._point) this._context.closePath();
  16318. },
  16319. point: function(x, y) {
  16320. x = +x, y = +y;
  16321. if (this._point) this._context.lineTo(x, y);
  16322. else this._point = 1, this._context.moveTo(x, y);
  16323. }
  16324. };
  16325. function linearClosed(context) {
  16326. return new LinearClosed(context);
  16327. }
  16328. function sign(x) {
  16329. return x < 0 ? -1 : 1;
  16330. }
  16331. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  16332. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  16333. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  16334. // NOV(II), P. 443, 1990.
  16335. function slope3(that, x2, y2) {
  16336. var h0 = that._x1 - that._x0,
  16337. h1 = x2 - that._x1,
  16338. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  16339. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  16340. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  16341. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  16342. }
  16343. // Calculate a one-sided slope.
  16344. function slope2(that, t) {
  16345. var h = that._x1 - that._x0;
  16346. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  16347. }
  16348. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  16349. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  16350. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  16351. function point(that, t0, t1) {
  16352. var x0 = that._x0,
  16353. y0 = that._y0,
  16354. x1 = that._x1,
  16355. y1 = that._y1,
  16356. dx = (x1 - x0) / 3;
  16357. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  16358. }
  16359. function MonotoneX(context) {
  16360. this._context = context;
  16361. }
  16362. MonotoneX.prototype = {
  16363. areaStart: function() {
  16364. this._line = 0;
  16365. },
  16366. areaEnd: function() {
  16367. this._line = NaN;
  16368. },
  16369. lineStart: function() {
  16370. this._x0 = this._x1 =
  16371. this._y0 = this._y1 =
  16372. this._t0 = NaN;
  16373. this._point = 0;
  16374. },
  16375. lineEnd: function() {
  16376. switch (this._point) {
  16377. case 2: this._context.lineTo(this._x1, this._y1); break;
  16378. case 3: point(this, this._t0, slope2(this, this._t0)); break;
  16379. }
  16380. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16381. this._line = 1 - this._line;
  16382. },
  16383. point: function(x, y) {
  16384. var t1 = NaN;
  16385. x = +x, y = +y;
  16386. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  16387. switch (this._point) {
  16388. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16389. case 1: this._point = 2; break;
  16390. case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  16391. default: point(this, this._t0, t1 = slope3(this, x, y)); break;
  16392. }
  16393. this._x0 = this._x1, this._x1 = x;
  16394. this._y0 = this._y1, this._y1 = y;
  16395. this._t0 = t1;
  16396. }
  16397. };
  16398. function MonotoneY(context) {
  16399. this._context = new ReflectContext(context);
  16400. }
  16401. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  16402. MonotoneX.prototype.point.call(this, y, x);
  16403. };
  16404. function ReflectContext(context) {
  16405. this._context = context;
  16406. }
  16407. ReflectContext.prototype = {
  16408. moveTo: function(x, y) { this._context.moveTo(y, x); },
  16409. closePath: function() { this._context.closePath(); },
  16410. lineTo: function(x, y) { this._context.lineTo(y, x); },
  16411. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  16412. };
  16413. function monotoneX(context) {
  16414. return new MonotoneX(context);
  16415. }
  16416. function monotoneY(context) {
  16417. return new MonotoneY(context);
  16418. }
  16419. function Natural(context) {
  16420. this._context = context;
  16421. }
  16422. Natural.prototype = {
  16423. areaStart: function() {
  16424. this._line = 0;
  16425. },
  16426. areaEnd: function() {
  16427. this._line = NaN;
  16428. },
  16429. lineStart: function() {
  16430. this._x = [];
  16431. this._y = [];
  16432. },
  16433. lineEnd: function() {
  16434. var x = this._x,
  16435. y = this._y,
  16436. n = x.length;
  16437. if (n) {
  16438. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  16439. if (n === 2) {
  16440. this._context.lineTo(x[1], y[1]);
  16441. } else {
  16442. var px = controlPoints(x),
  16443. py = controlPoints(y);
  16444. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  16445. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  16446. }
  16447. }
  16448. }
  16449. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  16450. this._line = 1 - this._line;
  16451. this._x = this._y = null;
  16452. },
  16453. point: function(x, y) {
  16454. this._x.push(+x);
  16455. this._y.push(+y);
  16456. }
  16457. };
  16458. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  16459. function controlPoints(x) {
  16460. var i,
  16461. n = x.length - 1,
  16462. m,
  16463. a = new Array(n),
  16464. b = new Array(n),
  16465. r = new Array(n);
  16466. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  16467. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  16468. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  16469. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  16470. a[n - 1] = r[n - 1] / b[n - 1];
  16471. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  16472. b[n - 1] = (x[n] + a[n - 1]) / 2;
  16473. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  16474. return [a, b];
  16475. }
  16476. function natural(context) {
  16477. return new Natural(context);
  16478. }
  16479. function Step(context, t) {
  16480. this._context = context;
  16481. this._t = t;
  16482. }
  16483. Step.prototype = {
  16484. areaStart: function() {
  16485. this._line = 0;
  16486. },
  16487. areaEnd: function() {
  16488. this._line = NaN;
  16489. },
  16490. lineStart: function() {
  16491. this._x = this._y = NaN;
  16492. this._point = 0;
  16493. },
  16494. lineEnd: function() {
  16495. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  16496. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16497. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  16498. },
  16499. point: function(x, y) {
  16500. x = +x, y = +y;
  16501. switch (this._point) {
  16502. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16503. case 1: this._point = 2; // falls through
  16504. default: {
  16505. if (this._t <= 0) {
  16506. this._context.lineTo(this._x, y);
  16507. this._context.lineTo(x, y);
  16508. } else {
  16509. var x1 = this._x * (1 - this._t) + x * this._t;
  16510. this._context.lineTo(x1, this._y);
  16511. this._context.lineTo(x1, y);
  16512. }
  16513. break;
  16514. }
  16515. }
  16516. this._x = x, this._y = y;
  16517. }
  16518. };
  16519. function step(context) {
  16520. return new Step(context, 0.5);
  16521. }
  16522. function stepBefore(context) {
  16523. return new Step(context, 0);
  16524. }
  16525. function stepAfter(context) {
  16526. return new Step(context, 1);
  16527. }
  16528. function none$1(series, order) {
  16529. if (!((n = series.length) > 1)) return;
  16530. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  16531. s0 = s1, s1 = series[order[i]];
  16532. for (j = 0; j < m; ++j) {
  16533. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  16534. }
  16535. }
  16536. }
  16537. function none(series) {
  16538. var n = series.length, o = new Array(n);
  16539. while (--n >= 0) o[n] = n;
  16540. return o;
  16541. }
  16542. function stackValue(d, key) {
  16543. return d[key];
  16544. }
  16545. function stackSeries(key) {
  16546. const series = [];
  16547. series.key = key;
  16548. return series;
  16549. }
  16550. function stack() {
  16551. var keys = constant$1([]),
  16552. order = none,
  16553. offset = none$1,
  16554. value = stackValue;
  16555. function stack(data) {
  16556. var sz = Array.from(keys.apply(this, arguments), stackSeries),
  16557. i, n = sz.length, j = -1,
  16558. oz;
  16559. for (const d of data) {
  16560. for (i = 0, ++j; i < n; ++i) {
  16561. (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
  16562. }
  16563. }
  16564. for (i = 0, oz = array(order(sz)); i < n; ++i) {
  16565. sz[oz[i]].index = i;
  16566. }
  16567. offset(sz, oz);
  16568. return sz;
  16569. }
  16570. stack.keys = function(_) {
  16571. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
  16572. };
  16573. stack.value = function(_) {
  16574. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
  16575. };
  16576. stack.order = function(_) {
  16577. return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
  16578. };
  16579. stack.offset = function(_) {
  16580. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  16581. };
  16582. return stack;
  16583. }
  16584. function expand(series, order) {
  16585. if (!((n = series.length) > 0)) return;
  16586. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  16587. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  16588. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  16589. }
  16590. none$1(series, order);
  16591. }
  16592. function diverging(series, order) {
  16593. if (!((n = series.length) > 0)) return;
  16594. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  16595. for (yp = yn = 0, i = 0; i < n; ++i) {
  16596. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  16597. d[0] = yp, d[1] = yp += dy;
  16598. } else if (dy < 0) {
  16599. d[1] = yn, d[0] = yn += dy;
  16600. } else {
  16601. d[0] = 0, d[1] = dy;
  16602. }
  16603. }
  16604. }
  16605. }
  16606. function silhouette(series, order) {
  16607. if (!((n = series.length) > 0)) return;
  16608. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  16609. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  16610. s0[j][1] += s0[j][0] = -y / 2;
  16611. }
  16612. none$1(series, order);
  16613. }
  16614. function wiggle(series, order) {
  16615. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  16616. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  16617. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  16618. var si = series[order[i]],
  16619. sij0 = si[j][1] || 0,
  16620. sij1 = si[j - 1][1] || 0,
  16621. s3 = (sij0 - sij1) / 2;
  16622. for (var k = 0; k < i; ++k) {
  16623. var sk = series[order[k]],
  16624. skj0 = sk[j][1] || 0,
  16625. skj1 = sk[j - 1][1] || 0;
  16626. s3 += skj0 - skj1;
  16627. }
  16628. s1 += sij0, s2 += s3 * sij0;
  16629. }
  16630. s0[j - 1][1] += s0[j - 1][0] = y;
  16631. if (s1) y -= s2 / s1;
  16632. }
  16633. s0[j - 1][1] += s0[j - 1][0] = y;
  16634. none$1(series, order);
  16635. }
  16636. function appearance(series) {
  16637. var peaks = series.map(peak);
  16638. return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  16639. }
  16640. function peak(series) {
  16641. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  16642. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  16643. return j;
  16644. }
  16645. function ascending(series) {
  16646. var sums = series.map(sum);
  16647. return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
  16648. }
  16649. function sum(series) {
  16650. var s = 0, i = -1, n = series.length, v;
  16651. while (++i < n) if (v = +series[i][1]) s += v;
  16652. return s;
  16653. }
  16654. function descending(series) {
  16655. return ascending(series).reverse();
  16656. }
  16657. function insideOut(series) {
  16658. var n = series.length,
  16659. i,
  16660. j,
  16661. sums = series.map(sum),
  16662. order = appearance(series),
  16663. top = 0,
  16664. bottom = 0,
  16665. tops = [],
  16666. bottoms = [];
  16667. for (i = 0; i < n; ++i) {
  16668. j = order[i];
  16669. if (top < bottom) {
  16670. top += sums[j];
  16671. tops.push(j);
  16672. } else {
  16673. bottom += sums[j];
  16674. bottoms.push(j);
  16675. }
  16676. }
  16677. return bottoms.reverse().concat(tops);
  16678. }
  16679. function reverse(series) {
  16680. return none(series).reverse();
  16681. }
  16682. var constant = x => () => x;
  16683. function ZoomEvent(type, {
  16684. sourceEvent,
  16685. target,
  16686. transform,
  16687. dispatch
  16688. }) {
  16689. Object.defineProperties(this, {
  16690. type: {value: type, enumerable: true, configurable: true},
  16691. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  16692. target: {value: target, enumerable: true, configurable: true},
  16693. transform: {value: transform, enumerable: true, configurable: true},
  16694. _: {value: dispatch}
  16695. });
  16696. }
  16697. function Transform(k, x, y) {
  16698. this.k = k;
  16699. this.x = x;
  16700. this.y = y;
  16701. }
  16702. Transform.prototype = {
  16703. constructor: Transform,
  16704. scale: function(k) {
  16705. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  16706. },
  16707. translate: function(x, y) {
  16708. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  16709. },
  16710. apply: function(point) {
  16711. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  16712. },
  16713. applyX: function(x) {
  16714. return x * this.k + this.x;
  16715. },
  16716. applyY: function(y) {
  16717. return y * this.k + this.y;
  16718. },
  16719. invert: function(location) {
  16720. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  16721. },
  16722. invertX: function(x) {
  16723. return (x - this.x) / this.k;
  16724. },
  16725. invertY: function(y) {
  16726. return (y - this.y) / this.k;
  16727. },
  16728. rescaleX: function(x) {
  16729. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  16730. },
  16731. rescaleY: function(y) {
  16732. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  16733. },
  16734. toString: function() {
  16735. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  16736. }
  16737. };
  16738. var identity = new Transform(1, 0, 0);
  16739. transform.prototype = Transform.prototype;
  16740. function transform(node) {
  16741. while (!node.__zoom) if (!(node = node.parentNode)) return identity;
  16742. return node.__zoom;
  16743. }
  16744. function nopropagation(event) {
  16745. event.stopImmediatePropagation();
  16746. }
  16747. function noevent(event) {
  16748. event.preventDefault();
  16749. event.stopImmediatePropagation();
  16750. }
  16751. // Ignore right-click, since that should open the context menu.
  16752. // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
  16753. function defaultFilter(event) {
  16754. return (!event.ctrlKey || event.type === 'wheel') && !event.button;
  16755. }
  16756. function defaultExtent() {
  16757. var e = this;
  16758. if (e instanceof SVGElement) {
  16759. e = e.ownerSVGElement || e;
  16760. if (e.hasAttribute("viewBox")) {
  16761. e = e.viewBox.baseVal;
  16762. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  16763. }
  16764. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  16765. }
  16766. return [[0, 0], [e.clientWidth, e.clientHeight]];
  16767. }
  16768. function defaultTransform() {
  16769. return this.__zoom || identity;
  16770. }
  16771. function defaultWheelDelta(event) {
  16772. return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
  16773. }
  16774. function defaultTouchable() {
  16775. return navigator.maxTouchPoints || ("ontouchstart" in this);
  16776. }
  16777. function defaultConstrain(transform, extent, translateExtent) {
  16778. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  16779. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  16780. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  16781. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  16782. return transform.translate(
  16783. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  16784. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  16785. );
  16786. }
  16787. function zoom() {
  16788. var filter = defaultFilter,
  16789. extent = defaultExtent,
  16790. constrain = defaultConstrain,
  16791. wheelDelta = defaultWheelDelta,
  16792. touchable = defaultTouchable,
  16793. scaleExtent = [0, Infinity],
  16794. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  16795. duration = 250,
  16796. interpolate = interpolateZoom,
  16797. listeners = dispatch("start", "zoom", "end"),
  16798. touchstarting,
  16799. touchfirst,
  16800. touchending,
  16801. touchDelay = 500,
  16802. wheelDelay = 150,
  16803. clickDistance2 = 0,
  16804. tapDistance = 10;
  16805. function zoom(selection) {
  16806. selection
  16807. .property("__zoom", defaultTransform)
  16808. .on("wheel.zoom", wheeled, {passive: false})
  16809. .on("mousedown.zoom", mousedowned)
  16810. .on("dblclick.zoom", dblclicked)
  16811. .filter(touchable)
  16812. .on("touchstart.zoom", touchstarted)
  16813. .on("touchmove.zoom", touchmoved)
  16814. .on("touchend.zoom touchcancel.zoom", touchended)
  16815. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  16816. }
  16817. zoom.transform = function(collection, transform, point, event) {
  16818. var selection = collection.selection ? collection.selection() : collection;
  16819. selection.property("__zoom", defaultTransform);
  16820. if (collection !== selection) {
  16821. schedule(collection, transform, point, event);
  16822. } else {
  16823. selection.interrupt().each(function() {
  16824. gesture(this, arguments)
  16825. .event(event)
  16826. .start()
  16827. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  16828. .end();
  16829. });
  16830. }
  16831. };
  16832. zoom.scaleBy = function(selection, k, p, event) {
  16833. zoom.scaleTo(selection, function() {
  16834. var k0 = this.__zoom.k,
  16835. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16836. return k0 * k1;
  16837. }, p, event);
  16838. };
  16839. zoom.scaleTo = function(selection, k, p, event) {
  16840. zoom.transform(selection, function() {
  16841. var e = extent.apply(this, arguments),
  16842. t0 = this.__zoom,
  16843. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  16844. p1 = t0.invert(p0),
  16845. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16846. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  16847. }, p, event);
  16848. };
  16849. zoom.translateBy = function(selection, x, y, event) {
  16850. zoom.transform(selection, function() {
  16851. return constrain(this.__zoom.translate(
  16852. typeof x === "function" ? x.apply(this, arguments) : x,
  16853. typeof y === "function" ? y.apply(this, arguments) : y
  16854. ), extent.apply(this, arguments), translateExtent);
  16855. }, null, event);
  16856. };
  16857. zoom.translateTo = function(selection, x, y, p, event) {
  16858. zoom.transform(selection, function() {
  16859. var e = extent.apply(this, arguments),
  16860. t = this.__zoom,
  16861. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  16862. return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
  16863. typeof x === "function" ? -x.apply(this, arguments) : -x,
  16864. typeof y === "function" ? -y.apply(this, arguments) : -y
  16865. ), e, translateExtent);
  16866. }, p, event);
  16867. };
  16868. function scale(transform, k) {
  16869. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  16870. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  16871. }
  16872. function translate(transform, p0, p1) {
  16873. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  16874. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  16875. }
  16876. function centroid(extent) {
  16877. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  16878. }
  16879. function schedule(transition, transform, point, event) {
  16880. transition
  16881. .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
  16882. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
  16883. .tween("zoom", function() {
  16884. var that = this,
  16885. args = arguments,
  16886. g = gesture(that, args).event(event),
  16887. e = extent.apply(that, args),
  16888. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  16889. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  16890. a = that.__zoom,
  16891. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  16892. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  16893. return function(t) {
  16894. if (t === 1) t = b; // Avoid rounding error on end.
  16895. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  16896. g.zoom(null, t);
  16897. };
  16898. });
  16899. }
  16900. function gesture(that, args, clean) {
  16901. return (!clean && that.__zooming) || new Gesture(that, args);
  16902. }
  16903. function Gesture(that, args) {
  16904. this.that = that;
  16905. this.args = args;
  16906. this.active = 0;
  16907. this.sourceEvent = null;
  16908. this.extent = extent.apply(that, args);
  16909. this.taps = 0;
  16910. }
  16911. Gesture.prototype = {
  16912. event: function(event) {
  16913. if (event) this.sourceEvent = event;
  16914. return this;
  16915. },
  16916. start: function() {
  16917. if (++this.active === 1) {
  16918. this.that.__zooming = this;
  16919. this.emit("start");
  16920. }
  16921. return this;
  16922. },
  16923. zoom: function(key, transform) {
  16924. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  16925. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  16926. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  16927. this.that.__zoom = transform;
  16928. this.emit("zoom");
  16929. return this;
  16930. },
  16931. end: function() {
  16932. if (--this.active === 0) {
  16933. delete this.that.__zooming;
  16934. this.emit("end");
  16935. }
  16936. return this;
  16937. },
  16938. emit: function(type) {
  16939. var d = select(this.that).datum();
  16940. listeners.call(
  16941. type,
  16942. this.that,
  16943. new ZoomEvent(type, {
  16944. sourceEvent: this.sourceEvent,
  16945. target: zoom,
  16946. type,
  16947. transform: this.that.__zoom,
  16948. dispatch: listeners
  16949. }),
  16950. d
  16951. );
  16952. }
  16953. };
  16954. function wheeled(event, ...args) {
  16955. if (!filter.apply(this, arguments)) return;
  16956. var g = gesture(this, args).event(event),
  16957. t = this.__zoom,
  16958. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  16959. p = pointer(event);
  16960. // If the mouse is in the same location as before, reuse it.
  16961. // If there were recent wheel events, reset the wheel idle timeout.
  16962. if (g.wheel) {
  16963. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  16964. g.mouse[1] = t.invert(g.mouse[0] = p);
  16965. }
  16966. clearTimeout(g.wheel);
  16967. }
  16968. // If this wheel event won’t trigger a transform change, ignore it.
  16969. else if (t.k === k) return;
  16970. // Otherwise, capture the mouse point and location at the start.
  16971. else {
  16972. g.mouse = [p, t.invert(p)];
  16973. interrupt(this);
  16974. g.start();
  16975. }
  16976. noevent(event);
  16977. g.wheel = setTimeout(wheelidled, wheelDelay);
  16978. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  16979. function wheelidled() {
  16980. g.wheel = null;
  16981. g.end();
  16982. }
  16983. }
  16984. function mousedowned(event, ...args) {
  16985. if (touchending || !filter.apply(this, arguments)) return;
  16986. var currentTarget = event.currentTarget,
  16987. g = gesture(this, args, true).event(event),
  16988. v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  16989. p = pointer(event, currentTarget),
  16990. x0 = event.clientX,
  16991. y0 = event.clientY;
  16992. dragDisable(event.view);
  16993. nopropagation(event);
  16994. g.mouse = [p, this.__zoom.invert(p)];
  16995. interrupt(this);
  16996. g.start();
  16997. function mousemoved(event) {
  16998. noevent(event);
  16999. if (!g.moved) {
  17000. var dx = event.clientX - x0, dy = event.clientY - y0;
  17001. g.moved = dx * dx + dy * dy > clickDistance2;
  17002. }
  17003. g.event(event)
  17004. .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
  17005. }
  17006. function mouseupped(event) {
  17007. v.on("mousemove.zoom mouseup.zoom", null);
  17008. yesdrag(event.view, g.moved);
  17009. noevent(event);
  17010. g.event(event).end();
  17011. }
  17012. }
  17013. function dblclicked(event, ...args) {
  17014. if (!filter.apply(this, arguments)) return;
  17015. var t0 = this.__zoom,
  17016. p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
  17017. p1 = t0.invert(p0),
  17018. k1 = t0.k * (event.shiftKey ? 0.5 : 2),
  17019. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
  17020. noevent(event);
  17021. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
  17022. else select(this).call(zoom.transform, t1, p0, event);
  17023. }
  17024. function touchstarted(event, ...args) {
  17025. if (!filter.apply(this, arguments)) return;
  17026. var touches = event.touches,
  17027. n = touches.length,
  17028. g = gesture(this, args, event.changedTouches.length === n).event(event),
  17029. started, i, t, p;
  17030. nopropagation(event);
  17031. for (i = 0; i < n; ++i) {
  17032. t = touches[i], p = pointer(t, this);
  17033. p = [p, this.__zoom.invert(p), t.identifier];
  17034. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  17035. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  17036. }
  17037. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  17038. if (started) {
  17039. if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  17040. interrupt(this);
  17041. g.start();
  17042. }
  17043. }
  17044. function touchmoved(event, ...args) {
  17045. if (!this.__zooming) return;
  17046. var g = gesture(this, args).event(event),
  17047. touches = event.changedTouches,
  17048. n = touches.length, i, t, p, l;
  17049. noevent(event);
  17050. for (i = 0; i < n; ++i) {
  17051. t = touches[i], p = pointer(t, this);
  17052. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  17053. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  17054. }
  17055. t = g.that.__zoom;
  17056. if (g.touch1) {
  17057. var p0 = g.touch0[0], l0 = g.touch0[1],
  17058. p1 = g.touch1[0], l1 = g.touch1[1],
  17059. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  17060. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  17061. t = scale(t, Math.sqrt(dp / dl));
  17062. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  17063. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  17064. }
  17065. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  17066. else return;
  17067. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  17068. }
  17069. function touchended(event, ...args) {
  17070. if (!this.__zooming) return;
  17071. var g = gesture(this, args).event(event),
  17072. touches = event.changedTouches,
  17073. n = touches.length, i, t;
  17074. nopropagation(event);
  17075. if (touchending) clearTimeout(touchending);
  17076. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  17077. for (i = 0; i < n; ++i) {
  17078. t = touches[i];
  17079. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  17080. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  17081. }
  17082. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  17083. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  17084. else {
  17085. g.end();
  17086. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  17087. if (g.taps === 2) {
  17088. t = pointer(t, this);
  17089. if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
  17090. var p = select(this).on("dblclick.zoom");
  17091. if (p) p.apply(this, arguments);
  17092. }
  17093. }
  17094. }
  17095. }
  17096. zoom.wheelDelta = function(_) {
  17097. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
  17098. };
  17099. zoom.filter = function(_) {
  17100. return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
  17101. };
  17102. zoom.touchable = function(_) {
  17103. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
  17104. };
  17105. zoom.extent = function(_) {
  17106. return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  17107. };
  17108. zoom.scaleExtent = function(_) {
  17109. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  17110. };
  17111. zoom.translateExtent = function(_) {
  17112. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  17113. };
  17114. zoom.constrain = function(_) {
  17115. return arguments.length ? (constrain = _, zoom) : constrain;
  17116. };
  17117. zoom.duration = function(_) {
  17118. return arguments.length ? (duration = +_, zoom) : duration;
  17119. };
  17120. zoom.interpolate = function(_) {
  17121. return arguments.length ? (interpolate = _, zoom) : interpolate;
  17122. };
  17123. zoom.on = function() {
  17124. var value = listeners.on.apply(listeners, arguments);
  17125. return value === listeners ? zoom : value;
  17126. };
  17127. zoom.clickDistance = function(_) {
  17128. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  17129. };
  17130. zoom.tapDistance = function(_) {
  17131. return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
  17132. };
  17133. return zoom;
  17134. }
  17135. exports.Adder = Adder;
  17136. exports.Delaunay = Delaunay;
  17137. exports.FormatSpecifier = FormatSpecifier;
  17138. exports.InternMap = InternMap;
  17139. exports.InternSet = InternSet;
  17140. exports.Node = Node$1;
  17141. exports.Path = Path$1;
  17142. exports.Voronoi = Voronoi;
  17143. exports.ZoomTransform = Transform;
  17144. exports.active = active;
  17145. exports.arc = arc;
  17146. exports.area = area;
  17147. exports.areaRadial = areaRadial;
  17148. exports.ascending = ascending$3;
  17149. exports.autoType = autoType;
  17150. exports.axisBottom = axisBottom;
  17151. exports.axisLeft = axisLeft;
  17152. exports.axisRight = axisRight;
  17153. exports.axisTop = axisTop;
  17154. exports.bin = bin;
  17155. exports.bisect = bisect;
  17156. exports.bisectCenter = bisectCenter;
  17157. exports.bisectLeft = bisectLeft;
  17158. exports.bisectRight = bisectRight;
  17159. exports.bisector = bisector;
  17160. exports.blob = blob;
  17161. exports.blur = blur;
  17162. exports.blur2 = blur2;
  17163. exports.blurImage = blurImage;
  17164. exports.brush = brush;
  17165. exports.brushSelection = brushSelection;
  17166. exports.brushX = brushX;
  17167. exports.brushY = brushY;
  17168. exports.buffer = buffer;
  17169. exports.chord = chord;
  17170. exports.chordDirected = chordDirected;
  17171. exports.chordTranspose = chordTranspose;
  17172. exports.cluster = cluster;
  17173. exports.color = color;
  17174. exports.contourDensity = density;
  17175. exports.contours = Contours;
  17176. exports.count = count$1;
  17177. exports.create = create$1;
  17178. exports.creator = creator;
  17179. exports.cross = cross$2;
  17180. exports.csv = csv;
  17181. exports.csvFormat = csvFormat;
  17182. exports.csvFormatBody = csvFormatBody;
  17183. exports.csvFormatRow = csvFormatRow;
  17184. exports.csvFormatRows = csvFormatRows;
  17185. exports.csvFormatValue = csvFormatValue;
  17186. exports.csvParse = csvParse;
  17187. exports.csvParseRows = csvParseRows;
  17188. exports.cubehelix = cubehelix$3;
  17189. exports.cumsum = cumsum;
  17190. exports.curveBasis = basis;
  17191. exports.curveBasisClosed = basisClosed;
  17192. exports.curveBasisOpen = basisOpen;
  17193. exports.curveBumpX = bumpX;
  17194. exports.curveBumpY = bumpY;
  17195. exports.curveBundle = bundle;
  17196. exports.curveCardinal = cardinal;
  17197. exports.curveCardinalClosed = cardinalClosed;
  17198. exports.curveCardinalOpen = cardinalOpen;
  17199. exports.curveCatmullRom = catmullRom;
  17200. exports.curveCatmullRomClosed = catmullRomClosed;
  17201. exports.curveCatmullRomOpen = catmullRomOpen;
  17202. exports.curveLinear = curveLinear;
  17203. exports.curveLinearClosed = linearClosed;
  17204. exports.curveMonotoneX = monotoneX;
  17205. exports.curveMonotoneY = monotoneY;
  17206. exports.curveNatural = natural;
  17207. exports.curveStep = step;
  17208. exports.curveStepAfter = stepAfter;
  17209. exports.curveStepBefore = stepBefore;
  17210. exports.descending = descending$2;
  17211. exports.deviation = deviation;
  17212. exports.difference = difference;
  17213. exports.disjoint = disjoint;
  17214. exports.dispatch = dispatch;
  17215. exports.drag = drag;
  17216. exports.dragDisable = dragDisable;
  17217. exports.dragEnable = yesdrag;
  17218. exports.dsv = dsv;
  17219. exports.dsvFormat = dsvFormat;
  17220. exports.easeBack = backInOut;
  17221. exports.easeBackIn = backIn;
  17222. exports.easeBackInOut = backInOut;
  17223. exports.easeBackOut = backOut;
  17224. exports.easeBounce = bounceOut;
  17225. exports.easeBounceIn = bounceIn;
  17226. exports.easeBounceInOut = bounceInOut;
  17227. exports.easeBounceOut = bounceOut;
  17228. exports.easeCircle = circleInOut;
  17229. exports.easeCircleIn = circleIn;
  17230. exports.easeCircleInOut = circleInOut;
  17231. exports.easeCircleOut = circleOut;
  17232. exports.easeCubic = cubicInOut;
  17233. exports.easeCubicIn = cubicIn;
  17234. exports.easeCubicInOut = cubicInOut;
  17235. exports.easeCubicOut = cubicOut;
  17236. exports.easeElastic = elasticOut;
  17237. exports.easeElasticIn = elasticIn;
  17238. exports.easeElasticInOut = elasticInOut;
  17239. exports.easeElasticOut = elasticOut;
  17240. exports.easeExp = expInOut;
  17241. exports.easeExpIn = expIn;
  17242. exports.easeExpInOut = expInOut;
  17243. exports.easeExpOut = expOut;
  17244. exports.easeLinear = linear$1;
  17245. exports.easePoly = polyInOut;
  17246. exports.easePolyIn = polyIn;
  17247. exports.easePolyInOut = polyInOut;
  17248. exports.easePolyOut = polyOut;
  17249. exports.easeQuad = quadInOut;
  17250. exports.easeQuadIn = quadIn;
  17251. exports.easeQuadInOut = quadInOut;
  17252. exports.easeQuadOut = quadOut;
  17253. exports.easeSin = sinInOut;
  17254. exports.easeSinIn = sinIn;
  17255. exports.easeSinInOut = sinInOut;
  17256. exports.easeSinOut = sinOut;
  17257. exports.every = every;
  17258. exports.extent = extent$1;
  17259. exports.fcumsum = fcumsum;
  17260. exports.filter = filter$1;
  17261. exports.flatGroup = flatGroup;
  17262. exports.flatRollup = flatRollup;
  17263. exports.forceCenter = center;
  17264. exports.forceCollide = collide;
  17265. exports.forceLink = link$2;
  17266. exports.forceManyBody = manyBody;
  17267. exports.forceRadial = radial$1;
  17268. exports.forceSimulation = simulation;
  17269. exports.forceX = x$1;
  17270. exports.forceY = y$1;
  17271. exports.formatDefaultLocale = defaultLocale$1;
  17272. exports.formatLocale = formatLocale$1;
  17273. exports.formatSpecifier = formatSpecifier;
  17274. exports.fsum = fsum;
  17275. exports.geoAlbers = albers;
  17276. exports.geoAlbersUsa = albersUsa;
  17277. exports.geoArea = area$2;
  17278. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  17279. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  17280. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  17281. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  17282. exports.geoBounds = bounds;
  17283. exports.geoCentroid = centroid$1;
  17284. exports.geoCircle = circle$1;
  17285. exports.geoClipAntimeridian = clipAntimeridian;
  17286. exports.geoClipCircle = clipCircle;
  17287. exports.geoClipExtent = extent;
  17288. exports.geoClipRectangle = clipRectangle;
  17289. exports.geoConicConformal = conicConformal;
  17290. exports.geoConicConformalRaw = conicConformalRaw;
  17291. exports.geoConicEqualArea = conicEqualArea;
  17292. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  17293. exports.geoConicEquidistant = conicEquidistant;
  17294. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  17295. exports.geoContains = contains$1;
  17296. exports.geoDistance = distance;
  17297. exports.geoEqualEarth = equalEarth;
  17298. exports.geoEqualEarthRaw = equalEarthRaw;
  17299. exports.geoEquirectangular = equirectangular;
  17300. exports.geoEquirectangularRaw = equirectangularRaw;
  17301. exports.geoGnomonic = gnomonic;
  17302. exports.geoGnomonicRaw = gnomonicRaw;
  17303. exports.geoGraticule = graticule;
  17304. exports.geoGraticule10 = graticule10;
  17305. exports.geoIdentity = identity$4;
  17306. exports.geoInterpolate = interpolate;
  17307. exports.geoLength = length$1;
  17308. exports.geoMercator = mercator;
  17309. exports.geoMercatorRaw = mercatorRaw;
  17310. exports.geoNaturalEarth1 = naturalEarth1;
  17311. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  17312. exports.geoOrthographic = orthographic;
  17313. exports.geoOrthographicRaw = orthographicRaw;
  17314. exports.geoPath = index$2;
  17315. exports.geoProjection = projection;
  17316. exports.geoProjectionMutator = projectionMutator;
  17317. exports.geoRotation = rotation;
  17318. exports.geoStereographic = stereographic;
  17319. exports.geoStereographicRaw = stereographicRaw;
  17320. exports.geoStream = geoStream;
  17321. exports.geoTransform = transform$1;
  17322. exports.geoTransverseMercator = transverseMercator;
  17323. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  17324. exports.gray = gray;
  17325. exports.greatest = greatest;
  17326. exports.greatestIndex = greatestIndex;
  17327. exports.group = group;
  17328. exports.groupSort = groupSort;
  17329. exports.groups = groups;
  17330. exports.hcl = hcl$2;
  17331. exports.hierarchy = hierarchy;
  17332. exports.histogram = bin;
  17333. exports.hsl = hsl$2;
  17334. exports.html = html;
  17335. exports.image = image;
  17336. exports.index = index$4;
  17337. exports.indexes = indexes;
  17338. exports.interpolate = interpolate$2;
  17339. exports.interpolateArray = array$3;
  17340. exports.interpolateBasis = basis$2;
  17341. exports.interpolateBasisClosed = basisClosed$1;
  17342. exports.interpolateBlues = Blues;
  17343. exports.interpolateBrBG = BrBG;
  17344. exports.interpolateBuGn = BuGn;
  17345. exports.interpolateBuPu = BuPu;
  17346. exports.interpolateCividis = cividis;
  17347. exports.interpolateCool = cool;
  17348. exports.interpolateCubehelix = cubehelix$2;
  17349. exports.interpolateCubehelixDefault = cubehelix;
  17350. exports.interpolateCubehelixLong = cubehelixLong;
  17351. exports.interpolateDate = date$1;
  17352. exports.interpolateDiscrete = discrete;
  17353. exports.interpolateGnBu = GnBu;
  17354. exports.interpolateGreens = Greens;
  17355. exports.interpolateGreys = Greys;
  17356. exports.interpolateHcl = hcl$1;
  17357. exports.interpolateHclLong = hclLong;
  17358. exports.interpolateHsl = hsl$1;
  17359. exports.interpolateHslLong = hslLong;
  17360. exports.interpolateHue = hue;
  17361. exports.interpolateInferno = inferno;
  17362. exports.interpolateLab = lab;
  17363. exports.interpolateMagma = magma;
  17364. exports.interpolateNumber = interpolateNumber;
  17365. exports.interpolateNumberArray = numberArray;
  17366. exports.interpolateObject = object$1;
  17367. exports.interpolateOrRd = OrRd;
  17368. exports.interpolateOranges = Oranges;
  17369. exports.interpolatePRGn = PRGn;
  17370. exports.interpolatePiYG = PiYG;
  17371. exports.interpolatePlasma = plasma;
  17372. exports.interpolatePuBu = PuBu;
  17373. exports.interpolatePuBuGn = PuBuGn;
  17374. exports.interpolatePuOr = PuOr;
  17375. exports.interpolatePuRd = PuRd;
  17376. exports.interpolatePurples = Purples;
  17377. exports.interpolateRainbow = rainbow;
  17378. exports.interpolateRdBu = RdBu;
  17379. exports.interpolateRdGy = RdGy;
  17380. exports.interpolateRdPu = RdPu;
  17381. exports.interpolateRdYlBu = RdYlBu;
  17382. exports.interpolateRdYlGn = RdYlGn;
  17383. exports.interpolateReds = Reds;
  17384. exports.interpolateRgb = interpolateRgb;
  17385. exports.interpolateRgbBasis = rgbBasis;
  17386. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  17387. exports.interpolateRound = interpolateRound;
  17388. exports.interpolateSinebow = sinebow;
  17389. exports.interpolateSpectral = Spectral;
  17390. exports.interpolateString = interpolateString;
  17391. exports.interpolateTransformCss = interpolateTransformCss;
  17392. exports.interpolateTransformSvg = interpolateTransformSvg;
  17393. exports.interpolateTurbo = turbo;
  17394. exports.interpolateViridis = viridis;
  17395. exports.interpolateWarm = warm;
  17396. exports.interpolateYlGn = YlGn;
  17397. exports.interpolateYlGnBu = YlGnBu;
  17398. exports.interpolateYlOrBr = YlOrBr;
  17399. exports.interpolateYlOrRd = YlOrRd;
  17400. exports.interpolateZoom = interpolateZoom;
  17401. exports.interrupt = interrupt;
  17402. exports.intersection = intersection;
  17403. exports.interval = interval;
  17404. exports.isoFormat = formatIso$1;
  17405. exports.isoParse = parseIso$1;
  17406. exports.json = json;
  17407. exports.lab = lab$1;
  17408. exports.lch = lch;
  17409. exports.least = least;
  17410. exports.leastIndex = leastIndex;
  17411. exports.line = line;
  17412. exports.lineRadial = lineRadial$1;
  17413. exports.link = link;
  17414. exports.linkHorizontal = linkHorizontal;
  17415. exports.linkRadial = linkRadial;
  17416. exports.linkVertical = linkVertical;
  17417. exports.local = local$1;
  17418. exports.map = map$1;
  17419. exports.matcher = matcher;
  17420. exports.max = max$3;
  17421. exports.maxIndex = maxIndex;
  17422. exports.mean = mean;
  17423. exports.median = median;
  17424. exports.medianIndex = medianIndex;
  17425. exports.merge = merge;
  17426. exports.min = min$2;
  17427. exports.minIndex = minIndex;
  17428. exports.mode = mode;
  17429. exports.namespace = namespace;
  17430. exports.namespaces = namespaces;
  17431. exports.nice = nice$1;
  17432. exports.now = now;
  17433. exports.pack = index$1;
  17434. exports.packEnclose = enclose;
  17435. exports.packSiblings = siblings;
  17436. exports.pairs = pairs;
  17437. exports.partition = partition;
  17438. exports.path = path;
  17439. exports.pathRound = pathRound;
  17440. exports.permute = permute;
  17441. exports.pie = pie;
  17442. exports.piecewise = piecewise;
  17443. exports.pointRadial = pointRadial;
  17444. exports.pointer = pointer;
  17445. exports.pointers = pointers;
  17446. exports.polygonArea = area$1;
  17447. exports.polygonCentroid = centroid;
  17448. exports.polygonContains = contains;
  17449. exports.polygonHull = hull;
  17450. exports.polygonLength = length;
  17451. exports.precisionFixed = precisionFixed;
  17452. exports.precisionPrefix = precisionPrefix;
  17453. exports.precisionRound = precisionRound;
  17454. exports.quadtree = quadtree;
  17455. exports.quantile = quantile$1;
  17456. exports.quantileIndex = quantileIndex;
  17457. exports.quantileSorted = quantileSorted;
  17458. exports.quantize = quantize$1;
  17459. exports.quickselect = quickselect;
  17460. exports.radialArea = areaRadial;
  17461. exports.radialLine = lineRadial$1;
  17462. exports.randomBates = bates;
  17463. exports.randomBernoulli = bernoulli;
  17464. exports.randomBeta = beta;
  17465. exports.randomBinomial = binomial;
  17466. exports.randomCauchy = cauchy;
  17467. exports.randomExponential = exponential;
  17468. exports.randomGamma = gamma;
  17469. exports.randomGeometric = geometric;
  17470. exports.randomInt = int;
  17471. exports.randomIrwinHall = irwinHall;
  17472. exports.randomLcg = lcg;
  17473. exports.randomLogNormal = logNormal;
  17474. exports.randomLogistic = logistic;
  17475. exports.randomNormal = normal;
  17476. exports.randomPareto = pareto;
  17477. exports.randomPoisson = poisson;
  17478. exports.randomUniform = uniform;
  17479. exports.randomWeibull = weibull;
  17480. exports.range = range$2;
  17481. exports.rank = rank;
  17482. exports.reduce = reduce;
  17483. exports.reverse = reverse$1;
  17484. exports.rgb = rgb;
  17485. exports.ribbon = ribbon$1;
  17486. exports.ribbonArrow = ribbonArrow;
  17487. exports.rollup = rollup;
  17488. exports.rollups = rollups;
  17489. exports.scaleBand = band;
  17490. exports.scaleDiverging = diverging$1;
  17491. exports.scaleDivergingLog = divergingLog;
  17492. exports.scaleDivergingPow = divergingPow;
  17493. exports.scaleDivergingSqrt = divergingSqrt;
  17494. exports.scaleDivergingSymlog = divergingSymlog;
  17495. exports.scaleIdentity = identity$2;
  17496. exports.scaleImplicit = implicit;
  17497. exports.scaleLinear = linear;
  17498. exports.scaleLog = log;
  17499. exports.scaleOrdinal = ordinal;
  17500. exports.scalePoint = point$4;
  17501. exports.scalePow = pow;
  17502. exports.scaleQuantile = quantile;
  17503. exports.scaleQuantize = quantize;
  17504. exports.scaleRadial = radial;
  17505. exports.scaleSequential = sequential;
  17506. exports.scaleSequentialLog = sequentialLog;
  17507. exports.scaleSequentialPow = sequentialPow;
  17508. exports.scaleSequentialQuantile = sequentialQuantile;
  17509. exports.scaleSequentialSqrt = sequentialSqrt;
  17510. exports.scaleSequentialSymlog = sequentialSymlog;
  17511. exports.scaleSqrt = sqrt$1;
  17512. exports.scaleSymlog = symlog;
  17513. exports.scaleThreshold = threshold;
  17514. exports.scaleTime = time;
  17515. exports.scaleUtc = utcTime;
  17516. exports.scan = scan;
  17517. exports.schemeAccent = Accent;
  17518. exports.schemeBlues = scheme$5;
  17519. exports.schemeBrBG = scheme$q;
  17520. exports.schemeBuGn = scheme$h;
  17521. exports.schemeBuPu = scheme$g;
  17522. exports.schemeCategory10 = category10;
  17523. exports.schemeDark2 = Dark2;
  17524. exports.schemeGnBu = scheme$f;
  17525. exports.schemeGreens = scheme$4;
  17526. exports.schemeGreys = scheme$3;
  17527. exports.schemeOrRd = scheme$e;
  17528. exports.schemeOranges = scheme;
  17529. exports.schemePRGn = scheme$p;
  17530. exports.schemePaired = Paired;
  17531. exports.schemePastel1 = Pastel1;
  17532. exports.schemePastel2 = Pastel2;
  17533. exports.schemePiYG = scheme$o;
  17534. exports.schemePuBu = scheme$c;
  17535. exports.schemePuBuGn = scheme$d;
  17536. exports.schemePuOr = scheme$n;
  17537. exports.schemePuRd = scheme$b;
  17538. exports.schemePurples = scheme$2;
  17539. exports.schemeRdBu = scheme$m;
  17540. exports.schemeRdGy = scheme$l;
  17541. exports.schemeRdPu = scheme$a;
  17542. exports.schemeRdYlBu = scheme$k;
  17543. exports.schemeRdYlGn = scheme$j;
  17544. exports.schemeReds = scheme$1;
  17545. exports.schemeSet1 = Set1;
  17546. exports.schemeSet2 = Set2;
  17547. exports.schemeSet3 = Set3;
  17548. exports.schemeSpectral = scheme$i;
  17549. exports.schemeTableau10 = Tableau10;
  17550. exports.schemeYlGn = scheme$8;
  17551. exports.schemeYlGnBu = scheme$9;
  17552. exports.schemeYlOrBr = scheme$7;
  17553. exports.schemeYlOrRd = scheme$6;
  17554. exports.select = select;
  17555. exports.selectAll = selectAll;
  17556. exports.selection = selection;
  17557. exports.selector = selector;
  17558. exports.selectorAll = selectorAll;
  17559. exports.shuffle = shuffle$1;
  17560. exports.shuffler = shuffler;
  17561. exports.some = some;
  17562. exports.sort = sort;
  17563. exports.stack = stack;
  17564. exports.stackOffsetDiverging = diverging;
  17565. exports.stackOffsetExpand = expand;
  17566. exports.stackOffsetNone = none$1;
  17567. exports.stackOffsetSilhouette = silhouette;
  17568. exports.stackOffsetWiggle = wiggle;
  17569. exports.stackOrderAppearance = appearance;
  17570. exports.stackOrderAscending = ascending;
  17571. exports.stackOrderDescending = descending;
  17572. exports.stackOrderInsideOut = insideOut;
  17573. exports.stackOrderNone = none;
  17574. exports.stackOrderReverse = reverse;
  17575. exports.stratify = stratify;
  17576. exports.style = styleValue;
  17577. exports.subset = subset;
  17578. exports.sum = sum$2;
  17579. exports.superset = superset;
  17580. exports.svg = svg;
  17581. exports.symbol = Symbol$1;
  17582. exports.symbolAsterisk = asterisk;
  17583. exports.symbolCircle = circle;
  17584. exports.symbolCross = cross;
  17585. exports.symbolDiamond = diamond;
  17586. exports.symbolDiamond2 = diamond2;
  17587. exports.symbolPlus = plus;
  17588. exports.symbolSquare = square;
  17589. exports.symbolSquare2 = square2;
  17590. exports.symbolStar = star;
  17591. exports.symbolTimes = times;
  17592. exports.symbolTriangle = triangle;
  17593. exports.symbolTriangle2 = triangle2;
  17594. exports.symbolWye = wye;
  17595. exports.symbolX = times;
  17596. exports.symbols = symbolsFill;
  17597. exports.symbolsFill = symbolsFill;
  17598. exports.symbolsStroke = symbolsStroke;
  17599. exports.text = text;
  17600. exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
  17601. exports.thresholdScott = thresholdScott;
  17602. exports.thresholdSturges = thresholdSturges;
  17603. exports.tickFormat = tickFormat;
  17604. exports.tickIncrement = tickIncrement;
  17605. exports.tickStep = tickStep;
  17606. exports.ticks = ticks;
  17607. exports.timeDay = timeDay;
  17608. exports.timeDays = timeDays;
  17609. exports.timeFormatDefaultLocale = defaultLocale;
  17610. exports.timeFormatLocale = formatLocale;
  17611. exports.timeFriday = timeFriday;
  17612. exports.timeFridays = timeFridays;
  17613. exports.timeHour = timeHour;
  17614. exports.timeHours = timeHours;
  17615. exports.timeInterval = timeInterval;
  17616. exports.timeMillisecond = millisecond;
  17617. exports.timeMilliseconds = milliseconds;
  17618. exports.timeMinute = timeMinute;
  17619. exports.timeMinutes = timeMinutes;
  17620. exports.timeMonday = timeMonday;
  17621. exports.timeMondays = timeMondays;
  17622. exports.timeMonth = timeMonth;
  17623. exports.timeMonths = timeMonths;
  17624. exports.timeSaturday = timeSaturday;
  17625. exports.timeSaturdays = timeSaturdays;
  17626. exports.timeSecond = second;
  17627. exports.timeSeconds = seconds;
  17628. exports.timeSunday = timeSunday;
  17629. exports.timeSundays = timeSundays;
  17630. exports.timeThursday = timeThursday;
  17631. exports.timeThursdays = timeThursdays;
  17632. exports.timeTickInterval = timeTickInterval;
  17633. exports.timeTicks = timeTicks;
  17634. exports.timeTuesday = timeTuesday;
  17635. exports.timeTuesdays = timeTuesdays;
  17636. exports.timeWednesday = timeWednesday;
  17637. exports.timeWednesdays = timeWednesdays;
  17638. exports.timeWeek = timeSunday;
  17639. exports.timeWeeks = timeSundays;
  17640. exports.timeYear = timeYear;
  17641. exports.timeYears = timeYears;
  17642. exports.timeout = timeout;
  17643. exports.timer = timer;
  17644. exports.timerFlush = timerFlush;
  17645. exports.transition = transition;
  17646. exports.transpose = transpose;
  17647. exports.tree = tree;
  17648. exports.treemap = index;
  17649. exports.treemapBinary = binary;
  17650. exports.treemapDice = treemapDice;
  17651. exports.treemapResquarify = resquarify;
  17652. exports.treemapSlice = treemapSlice;
  17653. exports.treemapSliceDice = sliceDice;
  17654. exports.treemapSquarify = squarify;
  17655. exports.tsv = tsv;
  17656. exports.tsvFormat = tsvFormat;
  17657. exports.tsvFormatBody = tsvFormatBody;
  17658. exports.tsvFormatRow = tsvFormatRow;
  17659. exports.tsvFormatRows = tsvFormatRows;
  17660. exports.tsvFormatValue = tsvFormatValue;
  17661. exports.tsvParse = tsvParse;
  17662. exports.tsvParseRows = tsvParseRows;
  17663. exports.union = union;
  17664. exports.unixDay = unixDay;
  17665. exports.unixDays = unixDays;
  17666. exports.utcDay = utcDay;
  17667. exports.utcDays = utcDays;
  17668. exports.utcFriday = utcFriday;
  17669. exports.utcFridays = utcFridays;
  17670. exports.utcHour = utcHour;
  17671. exports.utcHours = utcHours;
  17672. exports.utcMillisecond = millisecond;
  17673. exports.utcMilliseconds = milliseconds;
  17674. exports.utcMinute = utcMinute;
  17675. exports.utcMinutes = utcMinutes;
  17676. exports.utcMonday = utcMonday;
  17677. exports.utcMondays = utcMondays;
  17678. exports.utcMonth = utcMonth;
  17679. exports.utcMonths = utcMonths;
  17680. exports.utcSaturday = utcSaturday;
  17681. exports.utcSaturdays = utcSaturdays;
  17682. exports.utcSecond = second;
  17683. exports.utcSeconds = seconds;
  17684. exports.utcSunday = utcSunday;
  17685. exports.utcSundays = utcSundays;
  17686. exports.utcThursday = utcThursday;
  17687. exports.utcThursdays = utcThursdays;
  17688. exports.utcTickInterval = utcTickInterval;
  17689. exports.utcTicks = utcTicks;
  17690. exports.utcTuesday = utcTuesday;
  17691. exports.utcTuesdays = utcTuesdays;
  17692. exports.utcWednesday = utcWednesday;
  17693. exports.utcWednesdays = utcWednesdays;
  17694. exports.utcWeek = utcSunday;
  17695. exports.utcWeeks = utcSundays;
  17696. exports.utcYear = utcYear;
  17697. exports.utcYears = utcYears;
  17698. exports.variance = variance;
  17699. exports.version = version;
  17700. exports.window = defaultView;
  17701. exports.xml = xml;
  17702. exports.zip = zip;
  17703. exports.zoom = zoom;
  17704. exports.zoomIdentity = identity;
  17705. exports.zoomTransform = transform;
  17706. }));