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.

17911 lines
485 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. // https://d3js.org v5.7.0 Copyright 2018 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. (factory((global.d3 = global.d3 || {})));
  6. }(this, (function (exports) { 'use strict';
  7. var version = "5.7.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50),
  163. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "currentColor"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "currentColor")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "currentColor")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
  548. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. var matcher = function(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. };
  755. if (typeof document !== "undefined") {
  756. var element = document.documentElement;
  757. if (!element.matches) {
  758. var vendorMatches = element.webkitMatchesSelector
  759. || element.msMatchesSelector
  760. || element.mozMatchesSelector
  761. || element.oMatchesSelector;
  762. matcher = function(selector) {
  763. return function() {
  764. return vendorMatches.call(this, selector);
  765. };
  766. };
  767. }
  768. }
  769. var matcher$1 = matcher;
  770. function selection_filter(match) {
  771. if (typeof match !== "function") match = matcher$1(match);
  772. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  773. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  774. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  775. subgroup.push(node);
  776. }
  777. }
  778. }
  779. return new Selection(subgroups, this._parents);
  780. }
  781. function sparse(update) {
  782. return new Array(update.length);
  783. }
  784. function selection_enter() {
  785. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  786. }
  787. function EnterNode(parent, datum) {
  788. this.ownerDocument = parent.ownerDocument;
  789. this.namespaceURI = parent.namespaceURI;
  790. this._next = null;
  791. this._parent = parent;
  792. this.__data__ = datum;
  793. }
  794. EnterNode.prototype = {
  795. constructor: EnterNode,
  796. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  797. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  798. querySelector: function(selector) { return this._parent.querySelector(selector); },
  799. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  800. };
  801. function constant$1(x) {
  802. return function() {
  803. return x;
  804. };
  805. }
  806. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  807. function bindIndex(parent, group, enter, update, exit, data) {
  808. var i = 0,
  809. node,
  810. groupLength = group.length,
  811. dataLength = data.length;
  812. // Put any non-null nodes that fit into update.
  813. // Put any null nodes into enter.
  814. // Put any remaining data into enter.
  815. for (; i < dataLength; ++i) {
  816. if (node = group[i]) {
  817. node.__data__ = data[i];
  818. update[i] = node;
  819. } else {
  820. enter[i] = new EnterNode(parent, data[i]);
  821. }
  822. }
  823. // Put any non-null nodes that don’t fit into exit.
  824. for (; i < groupLength; ++i) {
  825. if (node = group[i]) {
  826. exit[i] = node;
  827. }
  828. }
  829. }
  830. function bindKey(parent, group, enter, update, exit, data, key) {
  831. var i,
  832. node,
  833. nodeByKeyValue = {},
  834. groupLength = group.length,
  835. dataLength = data.length,
  836. keyValues = new Array(groupLength),
  837. keyValue;
  838. // Compute the key for each node.
  839. // If multiple nodes have the same key, the duplicates are added to exit.
  840. for (i = 0; i < groupLength; ++i) {
  841. if (node = group[i]) {
  842. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  843. if (keyValue in nodeByKeyValue) {
  844. exit[i] = node;
  845. } else {
  846. nodeByKeyValue[keyValue] = node;
  847. }
  848. }
  849. }
  850. // Compute the key for each datum.
  851. // If there a node associated with this key, join and add it to update.
  852. // If there is not (or the key is a duplicate), add it to enter.
  853. for (i = 0; i < dataLength; ++i) {
  854. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  855. if (node = nodeByKeyValue[keyValue]) {
  856. update[i] = node;
  857. node.__data__ = data[i];
  858. nodeByKeyValue[keyValue] = null;
  859. } else {
  860. enter[i] = new EnterNode(parent, data[i]);
  861. }
  862. }
  863. // Add any remaining nodes that were not bound to data to exit.
  864. for (i = 0; i < groupLength; ++i) {
  865. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  866. exit[i] = node;
  867. }
  868. }
  869. }
  870. function selection_data(value, key) {
  871. if (!value) {
  872. data = new Array(this.size()), j = -1;
  873. this.each(function(d) { data[++j] = d; });
  874. return data;
  875. }
  876. var bind = key ? bindKey : bindIndex,
  877. parents = this._parents,
  878. groups = this._groups;
  879. if (typeof value !== "function") value = constant$1(value);
  880. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  881. var parent = parents[j],
  882. group = groups[j],
  883. groupLength = group.length,
  884. data = value.call(parent, parent && parent.__data__, j, parents),
  885. dataLength = data.length,
  886. enterGroup = enter[j] = new Array(dataLength),
  887. updateGroup = update[j] = new Array(dataLength),
  888. exitGroup = exit[j] = new Array(groupLength);
  889. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  890. // Now connect the enter nodes to their following update node, such that
  891. // appendChild can insert the materialized enter node before this node,
  892. // rather than at the end of the parent node.
  893. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  894. if (previous = enterGroup[i0]) {
  895. if (i0 >= i1) i1 = i0 + 1;
  896. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  897. previous._next = next || null;
  898. }
  899. }
  900. }
  901. update = new Selection(update, parents);
  902. update._enter = enter;
  903. update._exit = exit;
  904. return update;
  905. }
  906. function selection_exit() {
  907. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  908. }
  909. function selection_merge(selection$$1) {
  910. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  911. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  912. if (node = group0[i] || group1[i]) {
  913. merge[i] = node;
  914. }
  915. }
  916. }
  917. for (; j < m0; ++j) {
  918. merges[j] = groups0[j];
  919. }
  920. return new Selection(merges, this._parents);
  921. }
  922. function selection_order() {
  923. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  924. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  925. if (node = group[i]) {
  926. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  927. next = node;
  928. }
  929. }
  930. }
  931. return this;
  932. }
  933. function selection_sort(compare) {
  934. if (!compare) compare = ascending$1;
  935. function compareNode(a, b) {
  936. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  937. }
  938. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  939. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  940. if (node = group[i]) {
  941. sortgroup[i] = node;
  942. }
  943. }
  944. sortgroup.sort(compareNode);
  945. }
  946. return new Selection(sortgroups, this._parents).order();
  947. }
  948. function ascending$1(a, b) {
  949. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  950. }
  951. function selection_call() {
  952. var callback = arguments[0];
  953. arguments[0] = this;
  954. callback.apply(null, arguments);
  955. return this;
  956. }
  957. function selection_nodes() {
  958. var nodes = new Array(this.size()), i = -1;
  959. this.each(function() { nodes[++i] = this; });
  960. return nodes;
  961. }
  962. function selection_node() {
  963. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  964. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  965. var node = group[i];
  966. if (node) return node;
  967. }
  968. }
  969. return null;
  970. }
  971. function selection_size() {
  972. var size = 0;
  973. this.each(function() { ++size; });
  974. return size;
  975. }
  976. function selection_empty() {
  977. return !this.node();
  978. }
  979. function selection_each(callback) {
  980. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  981. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  982. if (node = group[i]) callback.call(node, node.__data__, i, group);
  983. }
  984. }
  985. return this;
  986. }
  987. function attrRemove(name) {
  988. return function() {
  989. this.removeAttribute(name);
  990. };
  991. }
  992. function attrRemoveNS(fullname) {
  993. return function() {
  994. this.removeAttributeNS(fullname.space, fullname.local);
  995. };
  996. }
  997. function attrConstant(name, value) {
  998. return function() {
  999. this.setAttribute(name, value);
  1000. };
  1001. }
  1002. function attrConstantNS(fullname, value) {
  1003. return function() {
  1004. this.setAttributeNS(fullname.space, fullname.local, value);
  1005. };
  1006. }
  1007. function attrFunction(name, value) {
  1008. return function() {
  1009. var v = value.apply(this, arguments);
  1010. if (v == null) this.removeAttribute(name);
  1011. else this.setAttribute(name, v);
  1012. };
  1013. }
  1014. function attrFunctionNS(fullname, value) {
  1015. return function() {
  1016. var v = value.apply(this, arguments);
  1017. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1018. else this.setAttributeNS(fullname.space, fullname.local, v);
  1019. };
  1020. }
  1021. function selection_attr(name, value) {
  1022. var fullname = namespace(name);
  1023. if (arguments.length < 2) {
  1024. var node = this.node();
  1025. return fullname.local
  1026. ? node.getAttributeNS(fullname.space, fullname.local)
  1027. : node.getAttribute(fullname);
  1028. }
  1029. return this.each((value == null
  1030. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1031. ? (fullname.local ? attrFunctionNS : attrFunction)
  1032. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1033. }
  1034. function defaultView(node) {
  1035. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1036. || (node.document && node) // node is a Window
  1037. || node.defaultView; // node is a Document
  1038. }
  1039. function styleRemove(name) {
  1040. return function() {
  1041. this.style.removeProperty(name);
  1042. };
  1043. }
  1044. function styleConstant(name, value, priority) {
  1045. return function() {
  1046. this.style.setProperty(name, value, priority);
  1047. };
  1048. }
  1049. function styleFunction(name, value, priority) {
  1050. return function() {
  1051. var v = value.apply(this, arguments);
  1052. if (v == null) this.style.removeProperty(name);
  1053. else this.style.setProperty(name, v, priority);
  1054. };
  1055. }
  1056. function selection_style(name, value, priority) {
  1057. return arguments.length > 1
  1058. ? this.each((value == null
  1059. ? styleRemove : typeof value === "function"
  1060. ? styleFunction
  1061. : styleConstant)(name, value, priority == null ? "" : priority))
  1062. : styleValue(this.node(), name);
  1063. }
  1064. function styleValue(node, name) {
  1065. return node.style.getPropertyValue(name)
  1066. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1067. }
  1068. function propertyRemove(name) {
  1069. return function() {
  1070. delete this[name];
  1071. };
  1072. }
  1073. function propertyConstant(name, value) {
  1074. return function() {
  1075. this[name] = value;
  1076. };
  1077. }
  1078. function propertyFunction(name, value) {
  1079. return function() {
  1080. var v = value.apply(this, arguments);
  1081. if (v == null) delete this[name];
  1082. else this[name] = v;
  1083. };
  1084. }
  1085. function selection_property(name, value) {
  1086. return arguments.length > 1
  1087. ? this.each((value == null
  1088. ? propertyRemove : typeof value === "function"
  1089. ? propertyFunction
  1090. : propertyConstant)(name, value))
  1091. : this.node()[name];
  1092. }
  1093. function classArray(string) {
  1094. return string.trim().split(/^|\s+/);
  1095. }
  1096. function classList(node) {
  1097. return node.classList || new ClassList(node);
  1098. }
  1099. function ClassList(node) {
  1100. this._node = node;
  1101. this._names = classArray(node.getAttribute("class") || "");
  1102. }
  1103. ClassList.prototype = {
  1104. add: function(name) {
  1105. var i = this._names.indexOf(name);
  1106. if (i < 0) {
  1107. this._names.push(name);
  1108. this._node.setAttribute("class", this._names.join(" "));
  1109. }
  1110. },
  1111. remove: function(name) {
  1112. var i = this._names.indexOf(name);
  1113. if (i >= 0) {
  1114. this._names.splice(i, 1);
  1115. this._node.setAttribute("class", this._names.join(" "));
  1116. }
  1117. },
  1118. contains: function(name) {
  1119. return this._names.indexOf(name) >= 0;
  1120. }
  1121. };
  1122. function classedAdd(node, names) {
  1123. var list = classList(node), i = -1, n = names.length;
  1124. while (++i < n) list.add(names[i]);
  1125. }
  1126. function classedRemove(node, names) {
  1127. var list = classList(node), i = -1, n = names.length;
  1128. while (++i < n) list.remove(names[i]);
  1129. }
  1130. function classedTrue(names) {
  1131. return function() {
  1132. classedAdd(this, names);
  1133. };
  1134. }
  1135. function classedFalse(names) {
  1136. return function() {
  1137. classedRemove(this, names);
  1138. };
  1139. }
  1140. function classedFunction(names, value) {
  1141. return function() {
  1142. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1143. };
  1144. }
  1145. function selection_classed(name, value) {
  1146. var names = classArray(name + "");
  1147. if (arguments.length < 2) {
  1148. var list = classList(this.node()), i = -1, n = names.length;
  1149. while (++i < n) if (!list.contains(names[i])) return false;
  1150. return true;
  1151. }
  1152. return this.each((typeof value === "function"
  1153. ? classedFunction : value
  1154. ? classedTrue
  1155. : classedFalse)(names, value));
  1156. }
  1157. function textRemove() {
  1158. this.textContent = "";
  1159. }
  1160. function textConstant(value) {
  1161. return function() {
  1162. this.textContent = value;
  1163. };
  1164. }
  1165. function textFunction(value) {
  1166. return function() {
  1167. var v = value.apply(this, arguments);
  1168. this.textContent = v == null ? "" : v;
  1169. };
  1170. }
  1171. function selection_text(value) {
  1172. return arguments.length
  1173. ? this.each(value == null
  1174. ? textRemove : (typeof value === "function"
  1175. ? textFunction
  1176. : textConstant)(value))
  1177. : this.node().textContent;
  1178. }
  1179. function htmlRemove() {
  1180. this.innerHTML = "";
  1181. }
  1182. function htmlConstant(value) {
  1183. return function() {
  1184. this.innerHTML = value;
  1185. };
  1186. }
  1187. function htmlFunction(value) {
  1188. return function() {
  1189. var v = value.apply(this, arguments);
  1190. this.innerHTML = v == null ? "" : v;
  1191. };
  1192. }
  1193. function selection_html(value) {
  1194. return arguments.length
  1195. ? this.each(value == null
  1196. ? htmlRemove : (typeof value === "function"
  1197. ? htmlFunction
  1198. : htmlConstant)(value))
  1199. : this.node().innerHTML;
  1200. }
  1201. function raise() {
  1202. if (this.nextSibling) this.parentNode.appendChild(this);
  1203. }
  1204. function selection_raise() {
  1205. return this.each(raise);
  1206. }
  1207. function lower() {
  1208. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1209. }
  1210. function selection_lower() {
  1211. return this.each(lower);
  1212. }
  1213. function selection_append(name) {
  1214. var create = typeof name === "function" ? name : creator(name);
  1215. return this.select(function() {
  1216. return this.appendChild(create.apply(this, arguments));
  1217. });
  1218. }
  1219. function constantNull() {
  1220. return null;
  1221. }
  1222. function selection_insert(name, before) {
  1223. var create = typeof name === "function" ? name : creator(name),
  1224. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1225. return this.select(function() {
  1226. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1227. });
  1228. }
  1229. function remove() {
  1230. var parent = this.parentNode;
  1231. if (parent) parent.removeChild(this);
  1232. }
  1233. function selection_remove() {
  1234. return this.each(remove);
  1235. }
  1236. function selection_cloneShallow() {
  1237. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1238. }
  1239. function selection_cloneDeep() {
  1240. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1241. }
  1242. function selection_clone(deep) {
  1243. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1244. }
  1245. function selection_datum(value) {
  1246. return arguments.length
  1247. ? this.property("__data__", value)
  1248. : this.node().__data__;
  1249. }
  1250. var filterEvents = {};
  1251. exports.event = null;
  1252. if (typeof document !== "undefined") {
  1253. var element$1 = document.documentElement;
  1254. if (!("onmouseenter" in element$1)) {
  1255. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1256. }
  1257. }
  1258. function filterContextListener(listener, index, group) {
  1259. listener = contextListener(listener, index, group);
  1260. return function(event) {
  1261. var related = event.relatedTarget;
  1262. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1263. listener.call(this, event);
  1264. }
  1265. };
  1266. }
  1267. function contextListener(listener, index, group) {
  1268. return function(event1) {
  1269. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1270. exports.event = event1;
  1271. try {
  1272. listener.call(this, this.__data__, index, group);
  1273. } finally {
  1274. exports.event = event0;
  1275. }
  1276. };
  1277. }
  1278. function parseTypenames$1(typenames) {
  1279. return typenames.trim().split(/^|\s+/).map(function(t) {
  1280. var name = "", i = t.indexOf(".");
  1281. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1282. return {type: t, name: name};
  1283. });
  1284. }
  1285. function onRemove(typename) {
  1286. return function() {
  1287. var on = this.__on;
  1288. if (!on) return;
  1289. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1290. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1291. this.removeEventListener(o.type, o.listener, o.capture);
  1292. } else {
  1293. on[++i] = o;
  1294. }
  1295. }
  1296. if (++i) on.length = i;
  1297. else delete this.__on;
  1298. };
  1299. }
  1300. function onAdd(typename, value, capture) {
  1301. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1302. return function(d, i, group) {
  1303. var on = this.__on, o, listener = wrap(value, i, group);
  1304. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1305. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1306. this.removeEventListener(o.type, o.listener, o.capture);
  1307. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1308. o.value = value;
  1309. return;
  1310. }
  1311. }
  1312. this.addEventListener(typename.type, listener, capture);
  1313. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1314. if (!on) this.__on = [o];
  1315. else on.push(o);
  1316. };
  1317. }
  1318. function selection_on(typename, value, capture) {
  1319. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1320. if (arguments.length < 2) {
  1321. var on = this.node().__on;
  1322. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1323. for (i = 0, o = on[j]; i < n; ++i) {
  1324. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1325. return o.value;
  1326. }
  1327. }
  1328. }
  1329. return;
  1330. }
  1331. on = value ? onAdd : onRemove;
  1332. if (capture == null) capture = false;
  1333. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1334. return this;
  1335. }
  1336. function customEvent(event1, listener, that, args) {
  1337. var event0 = exports.event;
  1338. event1.sourceEvent = exports.event;
  1339. exports.event = event1;
  1340. try {
  1341. return listener.apply(that, args);
  1342. } finally {
  1343. exports.event = event0;
  1344. }
  1345. }
  1346. function dispatchEvent(node, type, params) {
  1347. var window = defaultView(node),
  1348. event = window.CustomEvent;
  1349. if (typeof event === "function") {
  1350. event = new event(type, params);
  1351. } else {
  1352. event = window.document.createEvent("Event");
  1353. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1354. else event.initEvent(type, false, false);
  1355. }
  1356. node.dispatchEvent(event);
  1357. }
  1358. function dispatchConstant(type, params) {
  1359. return function() {
  1360. return dispatchEvent(this, type, params);
  1361. };
  1362. }
  1363. function dispatchFunction(type, params) {
  1364. return function() {
  1365. return dispatchEvent(this, type, params.apply(this, arguments));
  1366. };
  1367. }
  1368. function selection_dispatch(type, params) {
  1369. return this.each((typeof params === "function"
  1370. ? dispatchFunction
  1371. : dispatchConstant)(type, params));
  1372. }
  1373. var root = [null];
  1374. function Selection(groups, parents) {
  1375. this._groups = groups;
  1376. this._parents = parents;
  1377. }
  1378. function selection() {
  1379. return new Selection([[document.documentElement]], root);
  1380. }
  1381. Selection.prototype = selection.prototype = {
  1382. constructor: Selection,
  1383. select: selection_select,
  1384. selectAll: selection_selectAll,
  1385. filter: selection_filter,
  1386. data: selection_data,
  1387. enter: selection_enter,
  1388. exit: selection_exit,
  1389. merge: selection_merge,
  1390. order: selection_order,
  1391. sort: selection_sort,
  1392. call: selection_call,
  1393. nodes: selection_nodes,
  1394. node: selection_node,
  1395. size: selection_size,
  1396. empty: selection_empty,
  1397. each: selection_each,
  1398. attr: selection_attr,
  1399. style: selection_style,
  1400. property: selection_property,
  1401. classed: selection_classed,
  1402. text: selection_text,
  1403. html: selection_html,
  1404. raise: selection_raise,
  1405. lower: selection_lower,
  1406. append: selection_append,
  1407. insert: selection_insert,
  1408. remove: selection_remove,
  1409. clone: selection_clone,
  1410. datum: selection_datum,
  1411. on: selection_on,
  1412. dispatch: selection_dispatch
  1413. };
  1414. function select(selector) {
  1415. return typeof selector === "string"
  1416. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1417. : new Selection([[selector]], root);
  1418. }
  1419. function create(name) {
  1420. return select(creator(name).call(document.documentElement));
  1421. }
  1422. var nextId = 0;
  1423. function local() {
  1424. return new Local;
  1425. }
  1426. function Local() {
  1427. this._ = "@" + (++nextId).toString(36);
  1428. }
  1429. Local.prototype = local.prototype = {
  1430. constructor: Local,
  1431. get: function(node) {
  1432. var id = this._;
  1433. while (!(id in node)) if (!(node = node.parentNode)) return;
  1434. return node[id];
  1435. },
  1436. set: function(node, value) {
  1437. return node[this._] = value;
  1438. },
  1439. remove: function(node) {
  1440. return this._ in node && delete node[this._];
  1441. },
  1442. toString: function() {
  1443. return this._;
  1444. }
  1445. };
  1446. function sourceEvent() {
  1447. var current = exports.event, source;
  1448. while (source = current.sourceEvent) current = source;
  1449. return current;
  1450. }
  1451. function point(node, event) {
  1452. var svg = node.ownerSVGElement || node;
  1453. if (svg.createSVGPoint) {
  1454. var point = svg.createSVGPoint();
  1455. point.x = event.clientX, point.y = event.clientY;
  1456. point = point.matrixTransform(node.getScreenCTM().inverse());
  1457. return [point.x, point.y];
  1458. }
  1459. var rect = node.getBoundingClientRect();
  1460. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1461. }
  1462. function mouse(node) {
  1463. var event = sourceEvent();
  1464. if (event.changedTouches) event = event.changedTouches[0];
  1465. return point(node, event);
  1466. }
  1467. function selectAll(selector) {
  1468. return typeof selector === "string"
  1469. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1470. : new Selection([selector == null ? [] : selector], root);
  1471. }
  1472. function touch(node, touches, identifier) {
  1473. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1474. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1475. if ((touch = touches[i]).identifier === identifier) {
  1476. return point(node, touch);
  1477. }
  1478. }
  1479. return null;
  1480. }
  1481. function touches(node, touches) {
  1482. if (touches == null) touches = sourceEvent().touches;
  1483. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1484. points[i] = point(node, touches[i]);
  1485. }
  1486. return points;
  1487. }
  1488. function nopropagation() {
  1489. exports.event.stopImmediatePropagation();
  1490. }
  1491. function noevent() {
  1492. exports.event.preventDefault();
  1493. exports.event.stopImmediatePropagation();
  1494. }
  1495. function dragDisable(view) {
  1496. var root = view.document.documentElement,
  1497. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  1498. if ("onselectstart" in root) {
  1499. selection$$1.on("selectstart.drag", noevent, true);
  1500. } else {
  1501. root.__noselect = root.style.MozUserSelect;
  1502. root.style.MozUserSelect = "none";
  1503. }
  1504. }
  1505. function yesdrag(view, noclick) {
  1506. var root = view.document.documentElement,
  1507. selection$$1 = select(view).on("dragstart.drag", null);
  1508. if (noclick) {
  1509. selection$$1.on("click.drag", noevent, true);
  1510. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  1511. }
  1512. if ("onselectstart" in root) {
  1513. selection$$1.on("selectstart.drag", null);
  1514. } else {
  1515. root.style.MozUserSelect = root.__noselect;
  1516. delete root.__noselect;
  1517. }
  1518. }
  1519. function constant$2(x) {
  1520. return function() {
  1521. return x;
  1522. };
  1523. }
  1524. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1525. this.target = target;
  1526. this.type = type;
  1527. this.subject = subject;
  1528. this.identifier = id;
  1529. this.active = active;
  1530. this.x = x;
  1531. this.y = y;
  1532. this.dx = dx;
  1533. this.dy = dy;
  1534. this._ = dispatch;
  1535. }
  1536. DragEvent.prototype.on = function() {
  1537. var value = this._.on.apply(this._, arguments);
  1538. return value === this._ ? this : value;
  1539. };
  1540. // Ignore right-click, since that should open the context menu.
  1541. function defaultFilter() {
  1542. return !exports.event.button;
  1543. }
  1544. function defaultContainer() {
  1545. return this.parentNode;
  1546. }
  1547. function defaultSubject(d) {
  1548. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1549. }
  1550. function defaultTouchable() {
  1551. return "ontouchstart" in this;
  1552. }
  1553. function drag() {
  1554. var filter = defaultFilter,
  1555. container = defaultContainer,
  1556. subject = defaultSubject,
  1557. touchable = defaultTouchable,
  1558. gestures = {},
  1559. listeners = dispatch("start", "drag", "end"),
  1560. active = 0,
  1561. mousedownx,
  1562. mousedowny,
  1563. mousemoving,
  1564. touchending,
  1565. clickDistance2 = 0;
  1566. function drag(selection$$1) {
  1567. selection$$1
  1568. .on("mousedown.drag", mousedowned)
  1569. .filter(touchable)
  1570. .on("touchstart.drag", touchstarted)
  1571. .on("touchmove.drag", touchmoved)
  1572. .on("touchend.drag touchcancel.drag", touchended)
  1573. .style("touch-action", "none")
  1574. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1575. }
  1576. function mousedowned() {
  1577. if (touchending || !filter.apply(this, arguments)) return;
  1578. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1579. if (!gesture) return;
  1580. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1581. dragDisable(exports.event.view);
  1582. nopropagation();
  1583. mousemoving = false;
  1584. mousedownx = exports.event.clientX;
  1585. mousedowny = exports.event.clientY;
  1586. gesture("start");
  1587. }
  1588. function mousemoved() {
  1589. noevent();
  1590. if (!mousemoving) {
  1591. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1592. mousemoving = dx * dx + dy * dy > clickDistance2;
  1593. }
  1594. gestures.mouse("drag");
  1595. }
  1596. function mouseupped() {
  1597. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1598. yesdrag(exports.event.view, mousemoving);
  1599. noevent();
  1600. gestures.mouse("end");
  1601. }
  1602. function touchstarted() {
  1603. if (!filter.apply(this, arguments)) return;
  1604. var touches$$1 = exports.event.changedTouches,
  1605. c = container.apply(this, arguments),
  1606. n = touches$$1.length, i, gesture;
  1607. for (i = 0; i < n; ++i) {
  1608. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  1609. nopropagation();
  1610. gesture("start");
  1611. }
  1612. }
  1613. }
  1614. function touchmoved() {
  1615. var touches$$1 = exports.event.changedTouches,
  1616. n = touches$$1.length, i, gesture;
  1617. for (i = 0; i < n; ++i) {
  1618. if (gesture = gestures[touches$$1[i].identifier]) {
  1619. noevent();
  1620. gesture("drag");
  1621. }
  1622. }
  1623. }
  1624. function touchended() {
  1625. var touches$$1 = exports.event.changedTouches,
  1626. n = touches$$1.length, i, gesture;
  1627. if (touchending) clearTimeout(touchending);
  1628. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1629. for (i = 0; i < n; ++i) {
  1630. if (gesture = gestures[touches$$1[i].identifier]) {
  1631. nopropagation();
  1632. gesture("end");
  1633. }
  1634. }
  1635. }
  1636. function beforestart(id, container, point$$1, that, args) {
  1637. var p = point$$1(container, id), s, dx, dy,
  1638. sublisteners = listeners.copy();
  1639. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1640. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1641. dx = s.x - p[0] || 0;
  1642. dy = s.y - p[1] || 0;
  1643. return true;
  1644. })) return;
  1645. return function gesture(type) {
  1646. var p0 = p, n;
  1647. switch (type) {
  1648. case "start": gestures[id] = gesture, n = active++; break;
  1649. case "end": delete gestures[id], --active; // nobreak
  1650. case "drag": p = point$$1(container, id), n = active; break;
  1651. }
  1652. customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
  1653. };
  1654. }
  1655. drag.filter = function(_) {
  1656. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1657. };
  1658. drag.container = function(_) {
  1659. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1660. };
  1661. drag.subject = function(_) {
  1662. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1663. };
  1664. drag.touchable = function(_) {
  1665. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1666. };
  1667. drag.on = function() {
  1668. var value = listeners.on.apply(listeners, arguments);
  1669. return value === listeners ? drag : value;
  1670. };
  1671. drag.clickDistance = function(_) {
  1672. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1673. };
  1674. return drag;
  1675. }
  1676. function define(constructor, factory, prototype) {
  1677. constructor.prototype = factory.prototype = prototype;
  1678. prototype.constructor = constructor;
  1679. }
  1680. function extend(parent, definition) {
  1681. var prototype = Object.create(parent.prototype);
  1682. for (var key in definition) prototype[key] = definition[key];
  1683. return prototype;
  1684. }
  1685. function Color() {}
  1686. var darker = 0.7;
  1687. var brighter = 1 / darker;
  1688. var reI = "\\s*([+-]?\\d+)\\s*",
  1689. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1690. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1691. reHex3 = /^#([0-9a-f]{3})$/,
  1692. reHex6 = /^#([0-9a-f]{6})$/,
  1693. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1694. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1695. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1696. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1697. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1698. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1699. var named = {
  1700. aliceblue: 0xf0f8ff,
  1701. antiquewhite: 0xfaebd7,
  1702. aqua: 0x00ffff,
  1703. aquamarine: 0x7fffd4,
  1704. azure: 0xf0ffff,
  1705. beige: 0xf5f5dc,
  1706. bisque: 0xffe4c4,
  1707. black: 0x000000,
  1708. blanchedalmond: 0xffebcd,
  1709. blue: 0x0000ff,
  1710. blueviolet: 0x8a2be2,
  1711. brown: 0xa52a2a,
  1712. burlywood: 0xdeb887,
  1713. cadetblue: 0x5f9ea0,
  1714. chartreuse: 0x7fff00,
  1715. chocolate: 0xd2691e,
  1716. coral: 0xff7f50,
  1717. cornflowerblue: 0x6495ed,
  1718. cornsilk: 0xfff8dc,
  1719. crimson: 0xdc143c,
  1720. cyan: 0x00ffff,
  1721. darkblue: 0x00008b,
  1722. darkcyan: 0x008b8b,
  1723. darkgoldenrod: 0xb8860b,
  1724. darkgray: 0xa9a9a9,
  1725. darkgreen: 0x006400,
  1726. darkgrey: 0xa9a9a9,
  1727. darkkhaki: 0xbdb76b,
  1728. darkmagenta: 0x8b008b,
  1729. darkolivegreen: 0x556b2f,
  1730. darkorange: 0xff8c00,
  1731. darkorchid: 0x9932cc,
  1732. darkred: 0x8b0000,
  1733. darksalmon: 0xe9967a,
  1734. darkseagreen: 0x8fbc8f,
  1735. darkslateblue: 0x483d8b,
  1736. darkslategray: 0x2f4f4f,
  1737. darkslategrey: 0x2f4f4f,
  1738. darkturquoise: 0x00ced1,
  1739. darkviolet: 0x9400d3,
  1740. deeppink: 0xff1493,
  1741. deepskyblue: 0x00bfff,
  1742. dimgray: 0x696969,
  1743. dimgrey: 0x696969,
  1744. dodgerblue: 0x1e90ff,
  1745. firebrick: 0xb22222,
  1746. floralwhite: 0xfffaf0,
  1747. forestgreen: 0x228b22,
  1748. fuchsia: 0xff00ff,
  1749. gainsboro: 0xdcdcdc,
  1750. ghostwhite: 0xf8f8ff,
  1751. gold: 0xffd700,
  1752. goldenrod: 0xdaa520,
  1753. gray: 0x808080,
  1754. green: 0x008000,
  1755. greenyellow: 0xadff2f,
  1756. grey: 0x808080,
  1757. honeydew: 0xf0fff0,
  1758. hotpink: 0xff69b4,
  1759. indianred: 0xcd5c5c,
  1760. indigo: 0x4b0082,
  1761. ivory: 0xfffff0,
  1762. khaki: 0xf0e68c,
  1763. lavender: 0xe6e6fa,
  1764. lavenderblush: 0xfff0f5,
  1765. lawngreen: 0x7cfc00,
  1766. lemonchiffon: 0xfffacd,
  1767. lightblue: 0xadd8e6,
  1768. lightcoral: 0xf08080,
  1769. lightcyan: 0xe0ffff,
  1770. lightgoldenrodyellow: 0xfafad2,
  1771. lightgray: 0xd3d3d3,
  1772. lightgreen: 0x90ee90,
  1773. lightgrey: 0xd3d3d3,
  1774. lightpink: 0xffb6c1,
  1775. lightsalmon: 0xffa07a,
  1776. lightseagreen: 0x20b2aa,
  1777. lightskyblue: 0x87cefa,
  1778. lightslategray: 0x778899,
  1779. lightslategrey: 0x778899,
  1780. lightsteelblue: 0xb0c4de,
  1781. lightyellow: 0xffffe0,
  1782. lime: 0x00ff00,
  1783. limegreen: 0x32cd32,
  1784. linen: 0xfaf0e6,
  1785. magenta: 0xff00ff,
  1786. maroon: 0x800000,
  1787. mediumaquamarine: 0x66cdaa,
  1788. mediumblue: 0x0000cd,
  1789. mediumorchid: 0xba55d3,
  1790. mediumpurple: 0x9370db,
  1791. mediumseagreen: 0x3cb371,
  1792. mediumslateblue: 0x7b68ee,
  1793. mediumspringgreen: 0x00fa9a,
  1794. mediumturquoise: 0x48d1cc,
  1795. mediumvioletred: 0xc71585,
  1796. midnightblue: 0x191970,
  1797. mintcream: 0xf5fffa,
  1798. mistyrose: 0xffe4e1,
  1799. moccasin: 0xffe4b5,
  1800. navajowhite: 0xffdead,
  1801. navy: 0x000080,
  1802. oldlace: 0xfdf5e6,
  1803. olive: 0x808000,
  1804. olivedrab: 0x6b8e23,
  1805. orange: 0xffa500,
  1806. orangered: 0xff4500,
  1807. orchid: 0xda70d6,
  1808. palegoldenrod: 0xeee8aa,
  1809. palegreen: 0x98fb98,
  1810. paleturquoise: 0xafeeee,
  1811. palevioletred: 0xdb7093,
  1812. papayawhip: 0xffefd5,
  1813. peachpuff: 0xffdab9,
  1814. peru: 0xcd853f,
  1815. pink: 0xffc0cb,
  1816. plum: 0xdda0dd,
  1817. powderblue: 0xb0e0e6,
  1818. purple: 0x800080,
  1819. rebeccapurple: 0x663399,
  1820. red: 0xff0000,
  1821. rosybrown: 0xbc8f8f,
  1822. royalblue: 0x4169e1,
  1823. saddlebrown: 0x8b4513,
  1824. salmon: 0xfa8072,
  1825. sandybrown: 0xf4a460,
  1826. seagreen: 0x2e8b57,
  1827. seashell: 0xfff5ee,
  1828. sienna: 0xa0522d,
  1829. silver: 0xc0c0c0,
  1830. skyblue: 0x87ceeb,
  1831. slateblue: 0x6a5acd,
  1832. slategray: 0x708090,
  1833. slategrey: 0x708090,
  1834. snow: 0xfffafa,
  1835. springgreen: 0x00ff7f,
  1836. steelblue: 0x4682b4,
  1837. tan: 0xd2b48c,
  1838. teal: 0x008080,
  1839. thistle: 0xd8bfd8,
  1840. tomato: 0xff6347,
  1841. turquoise: 0x40e0d0,
  1842. violet: 0xee82ee,
  1843. wheat: 0xf5deb3,
  1844. white: 0xffffff,
  1845. whitesmoke: 0xf5f5f5,
  1846. yellow: 0xffff00,
  1847. yellowgreen: 0x9acd32
  1848. };
  1849. define(Color, color, {
  1850. displayable: function() {
  1851. return this.rgb().displayable();
  1852. },
  1853. hex: function() {
  1854. return this.rgb().hex();
  1855. },
  1856. toString: function() {
  1857. return this.rgb() + "";
  1858. }
  1859. });
  1860. function color(format) {
  1861. var m;
  1862. format = (format + "").trim().toLowerCase();
  1863. return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
  1864. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1865. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1866. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1867. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1868. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1869. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1870. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1871. : named.hasOwnProperty(format) ? rgbn(named[format])
  1872. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1873. : null;
  1874. }
  1875. function rgbn(n) {
  1876. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1877. }
  1878. function rgba(r, g, b, a) {
  1879. if (a <= 0) r = g = b = NaN;
  1880. return new Rgb(r, g, b, a);
  1881. }
  1882. function rgbConvert(o) {
  1883. if (!(o instanceof Color)) o = color(o);
  1884. if (!o) return new Rgb;
  1885. o = o.rgb();
  1886. return new Rgb(o.r, o.g, o.b, o.opacity);
  1887. }
  1888. function rgb(r, g, b, opacity) {
  1889. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1890. }
  1891. function Rgb(r, g, b, opacity) {
  1892. this.r = +r;
  1893. this.g = +g;
  1894. this.b = +b;
  1895. this.opacity = +opacity;
  1896. }
  1897. define(Rgb, rgb, extend(Color, {
  1898. brighter: function(k) {
  1899. k = k == null ? brighter : Math.pow(brighter, k);
  1900. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1901. },
  1902. darker: function(k) {
  1903. k = k == null ? darker : Math.pow(darker, k);
  1904. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1905. },
  1906. rgb: function() {
  1907. return this;
  1908. },
  1909. displayable: function() {
  1910. return (0 <= this.r && this.r <= 255)
  1911. && (0 <= this.g && this.g <= 255)
  1912. && (0 <= this.b && this.b <= 255)
  1913. && (0 <= this.opacity && this.opacity <= 1);
  1914. },
  1915. hex: function() {
  1916. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1917. },
  1918. toString: function() {
  1919. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1920. return (a === 1 ? "rgb(" : "rgba(")
  1921. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1922. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1923. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1924. + (a === 1 ? ")" : ", " + a + ")");
  1925. }
  1926. }));
  1927. function hex(value) {
  1928. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1929. return (value < 16 ? "0" : "") + value.toString(16);
  1930. }
  1931. function hsla(h, s, l, a) {
  1932. if (a <= 0) h = s = l = NaN;
  1933. else if (l <= 0 || l >= 1) h = s = NaN;
  1934. else if (s <= 0) h = NaN;
  1935. return new Hsl(h, s, l, a);
  1936. }
  1937. function hslConvert(o) {
  1938. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1939. if (!(o instanceof Color)) o = color(o);
  1940. if (!o) return new Hsl;
  1941. if (o instanceof Hsl) return o;
  1942. o = o.rgb();
  1943. var r = o.r / 255,
  1944. g = o.g / 255,
  1945. b = o.b / 255,
  1946. min = Math.min(r, g, b),
  1947. max = Math.max(r, g, b),
  1948. h = NaN,
  1949. s = max - min,
  1950. l = (max + min) / 2;
  1951. if (s) {
  1952. if (r === max) h = (g - b) / s + (g < b) * 6;
  1953. else if (g === max) h = (b - r) / s + 2;
  1954. else h = (r - g) / s + 4;
  1955. s /= l < 0.5 ? max + min : 2 - max - min;
  1956. h *= 60;
  1957. } else {
  1958. s = l > 0 && l < 1 ? 0 : h;
  1959. }
  1960. return new Hsl(h, s, l, o.opacity);
  1961. }
  1962. function hsl(h, s, l, opacity) {
  1963. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1964. }
  1965. function Hsl(h, s, l, opacity) {
  1966. this.h = +h;
  1967. this.s = +s;
  1968. this.l = +l;
  1969. this.opacity = +opacity;
  1970. }
  1971. define(Hsl, hsl, extend(Color, {
  1972. brighter: function(k) {
  1973. k = k == null ? brighter : Math.pow(brighter, k);
  1974. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1975. },
  1976. darker: function(k) {
  1977. k = k == null ? darker : Math.pow(darker, k);
  1978. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1979. },
  1980. rgb: function() {
  1981. var h = this.h % 360 + (this.h < 0) * 360,
  1982. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1983. l = this.l,
  1984. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1985. m1 = 2 * l - m2;
  1986. return new Rgb(
  1987. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1988. hsl2rgb(h, m1, m2),
  1989. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1990. this.opacity
  1991. );
  1992. },
  1993. displayable: function() {
  1994. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1995. && (0 <= this.l && this.l <= 1)
  1996. && (0 <= this.opacity && this.opacity <= 1);
  1997. }
  1998. }));
  1999. /* From FvD 13.37, CSS Color Module Level 3 */
  2000. function hsl2rgb(h, m1, m2) {
  2001. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2002. : h < 180 ? m2
  2003. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2004. : m1) * 255;
  2005. }
  2006. var deg2rad = Math.PI / 180;
  2007. var rad2deg = 180 / Math.PI;
  2008. // https://beta.observablehq.com/@mbostock/lab-and-rgb
  2009. var K = 18,
  2010. Xn = 0.96422,
  2011. Yn = 1,
  2012. Zn = 0.82521,
  2013. t0 = 4 / 29,
  2014. t1 = 6 / 29,
  2015. t2 = 3 * t1 * t1,
  2016. t3 = t1 * t1 * t1;
  2017. function labConvert(o) {
  2018. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2019. if (o instanceof Hcl) {
  2020. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2021. var h = o.h * deg2rad;
  2022. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2023. }
  2024. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2025. var r = rgb2lrgb(o.r),
  2026. g = rgb2lrgb(o.g),
  2027. b = rgb2lrgb(o.b),
  2028. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2029. if (r === g && g === b) x = z = y; else {
  2030. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2031. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2032. }
  2033. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2034. }
  2035. function gray(l, opacity) {
  2036. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2037. }
  2038. function lab(l, a, b, opacity) {
  2039. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2040. }
  2041. function Lab(l, a, b, opacity) {
  2042. this.l = +l;
  2043. this.a = +a;
  2044. this.b = +b;
  2045. this.opacity = +opacity;
  2046. }
  2047. define(Lab, lab, extend(Color, {
  2048. brighter: function(k) {
  2049. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2050. },
  2051. darker: function(k) {
  2052. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2053. },
  2054. rgb: function() {
  2055. var y = (this.l + 16) / 116,
  2056. x = isNaN(this.a) ? y : y + this.a / 500,
  2057. z = isNaN(this.b) ? y : y - this.b / 200;
  2058. x = Xn * lab2xyz(x);
  2059. y = Yn * lab2xyz(y);
  2060. z = Zn * lab2xyz(z);
  2061. return new Rgb(
  2062. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2063. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2064. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2065. this.opacity
  2066. );
  2067. }
  2068. }));
  2069. function xyz2lab(t) {
  2070. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2071. }
  2072. function lab2xyz(t) {
  2073. return t > t1 ? t * t * t : t2 * (t - t0);
  2074. }
  2075. function lrgb2rgb(x) {
  2076. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2077. }
  2078. function rgb2lrgb(x) {
  2079. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2080. }
  2081. function hclConvert(o) {
  2082. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2083. if (!(o instanceof Lab)) o = labConvert(o);
  2084. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
  2085. var h = Math.atan2(o.b, o.a) * rad2deg;
  2086. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2087. }
  2088. function lch(l, c, h, opacity) {
  2089. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2090. }
  2091. function hcl(h, c, l, opacity) {
  2092. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2093. }
  2094. function Hcl(h, c, l, opacity) {
  2095. this.h = +h;
  2096. this.c = +c;
  2097. this.l = +l;
  2098. this.opacity = +opacity;
  2099. }
  2100. define(Hcl, hcl, extend(Color, {
  2101. brighter: function(k) {
  2102. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2103. },
  2104. darker: function(k) {
  2105. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2106. },
  2107. rgb: function() {
  2108. return labConvert(this).rgb();
  2109. }
  2110. }));
  2111. var A = -0.14861,
  2112. B = +1.78277,
  2113. C = -0.29227,
  2114. D = -0.90649,
  2115. E = +1.97294,
  2116. ED = E * D,
  2117. EB = E * B,
  2118. BC_DA = B * C - D * A;
  2119. function cubehelixConvert(o) {
  2120. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2121. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2122. var r = o.r / 255,
  2123. g = o.g / 255,
  2124. b = o.b / 255,
  2125. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2126. bl = b - l,
  2127. k = (E * (g - l) - C * bl) / D,
  2128. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2129. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2130. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2131. }
  2132. function cubehelix(h, s, l, opacity) {
  2133. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2134. }
  2135. function Cubehelix(h, s, l, opacity) {
  2136. this.h = +h;
  2137. this.s = +s;
  2138. this.l = +l;
  2139. this.opacity = +opacity;
  2140. }
  2141. define(Cubehelix, cubehelix, extend(Color, {
  2142. brighter: function(k) {
  2143. k = k == null ? brighter : Math.pow(brighter, k);
  2144. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2145. },
  2146. darker: function(k) {
  2147. k = k == null ? darker : Math.pow(darker, k);
  2148. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2149. },
  2150. rgb: function() {
  2151. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2152. l = +this.l,
  2153. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2154. cosh = Math.cos(h),
  2155. sinh = Math.sin(h);
  2156. return new Rgb(
  2157. 255 * (l + a * (A * cosh + B * sinh)),
  2158. 255 * (l + a * (C * cosh + D * sinh)),
  2159. 255 * (l + a * (E * cosh)),
  2160. this.opacity
  2161. );
  2162. }
  2163. }));
  2164. function basis(t1, v0, v1, v2, v3) {
  2165. var t2 = t1 * t1, t3 = t2 * t1;
  2166. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2167. + (4 - 6 * t2 + 3 * t3) * v1
  2168. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2169. + t3 * v3) / 6;
  2170. }
  2171. function basis$1(values) {
  2172. var n = values.length - 1;
  2173. return function(t) {
  2174. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2175. v1 = values[i],
  2176. v2 = values[i + 1],
  2177. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2178. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2179. return basis((t - i / n) * n, v0, v1, v2, v3);
  2180. };
  2181. }
  2182. function basisClosed(values) {
  2183. var n = values.length;
  2184. return function(t) {
  2185. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2186. v0 = values[(i + n - 1) % n],
  2187. v1 = values[i % n],
  2188. v2 = values[(i + 1) % n],
  2189. v3 = values[(i + 2) % n];
  2190. return basis((t - i / n) * n, v0, v1, v2, v3);
  2191. };
  2192. }
  2193. function constant$3(x) {
  2194. return function() {
  2195. return x;
  2196. };
  2197. }
  2198. function linear(a, d) {
  2199. return function(t) {
  2200. return a + t * d;
  2201. };
  2202. }
  2203. function exponential(a, b, y) {
  2204. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2205. return Math.pow(a + t * b, y);
  2206. };
  2207. }
  2208. function hue(a, b) {
  2209. var d = b - a;
  2210. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2211. }
  2212. function gamma(y) {
  2213. return (y = +y) === 1 ? nogamma : function(a, b) {
  2214. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2215. };
  2216. }
  2217. function nogamma(a, b) {
  2218. var d = b - a;
  2219. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2220. }
  2221. var interpolateRgb = (function rgbGamma(y) {
  2222. var color$$1 = gamma(y);
  2223. function rgb$$1(start, end) {
  2224. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2225. g = color$$1(start.g, end.g),
  2226. b = color$$1(start.b, end.b),
  2227. opacity = nogamma(start.opacity, end.opacity);
  2228. return function(t) {
  2229. start.r = r(t);
  2230. start.g = g(t);
  2231. start.b = b(t);
  2232. start.opacity = opacity(t);
  2233. return start + "";
  2234. };
  2235. }
  2236. rgb$$1.gamma = rgbGamma;
  2237. return rgb$$1;
  2238. })(1);
  2239. function rgbSpline(spline) {
  2240. return function(colors) {
  2241. var n = colors.length,
  2242. r = new Array(n),
  2243. g = new Array(n),
  2244. b = new Array(n),
  2245. i, color$$1;
  2246. for (i = 0; i < n; ++i) {
  2247. color$$1 = rgb(colors[i]);
  2248. r[i] = color$$1.r || 0;
  2249. g[i] = color$$1.g || 0;
  2250. b[i] = color$$1.b || 0;
  2251. }
  2252. r = spline(r);
  2253. g = spline(g);
  2254. b = spline(b);
  2255. color$$1.opacity = 1;
  2256. return function(t) {
  2257. color$$1.r = r(t);
  2258. color$$1.g = g(t);
  2259. color$$1.b = b(t);
  2260. return color$$1 + "";
  2261. };
  2262. };
  2263. }
  2264. var rgbBasis = rgbSpline(basis$1);
  2265. var rgbBasisClosed = rgbSpline(basisClosed);
  2266. function array$1(a, b) {
  2267. var nb = b ? b.length : 0,
  2268. na = a ? Math.min(nb, a.length) : 0,
  2269. x = new Array(na),
  2270. c = new Array(nb),
  2271. i;
  2272. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2273. for (; i < nb; ++i) c[i] = b[i];
  2274. return function(t) {
  2275. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2276. return c;
  2277. };
  2278. }
  2279. function date(a, b) {
  2280. var d = new Date;
  2281. return a = +a, b -= a, function(t) {
  2282. return d.setTime(a + b * t), d;
  2283. };
  2284. }
  2285. function interpolateNumber(a, b) {
  2286. return a = +a, b -= a, function(t) {
  2287. return a + b * t;
  2288. };
  2289. }
  2290. function object(a, b) {
  2291. var i = {},
  2292. c = {},
  2293. k;
  2294. if (a === null || typeof a !== "object") a = {};
  2295. if (b === null || typeof b !== "object") b = {};
  2296. for (k in b) {
  2297. if (k in a) {
  2298. i[k] = interpolateValue(a[k], b[k]);
  2299. } else {
  2300. c[k] = b[k];
  2301. }
  2302. }
  2303. return function(t) {
  2304. for (k in i) c[k] = i[k](t);
  2305. return c;
  2306. };
  2307. }
  2308. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2309. reB = new RegExp(reA.source, "g");
  2310. function zero(b) {
  2311. return function() {
  2312. return b;
  2313. };
  2314. }
  2315. function one(b) {
  2316. return function(t) {
  2317. return b(t) + "";
  2318. };
  2319. }
  2320. function interpolateString(a, b) {
  2321. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2322. am, // current match in a
  2323. bm, // current match in b
  2324. bs, // string preceding current number in b, if any
  2325. i = -1, // index in s
  2326. s = [], // string constants and placeholders
  2327. q = []; // number interpolators
  2328. // Coerce inputs to strings.
  2329. a = a + "", b = b + "";
  2330. // Interpolate pairs of numbers in a & b.
  2331. while ((am = reA.exec(a))
  2332. && (bm = reB.exec(b))) {
  2333. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2334. bs = b.slice(bi, bs);
  2335. if (s[i]) s[i] += bs; // coalesce with previous string
  2336. else s[++i] = bs;
  2337. }
  2338. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2339. if (s[i]) s[i] += bm; // coalesce with previous string
  2340. else s[++i] = bm;
  2341. } else { // interpolate non-matching numbers
  2342. s[++i] = null;
  2343. q.push({i: i, x: interpolateNumber(am, bm)});
  2344. }
  2345. bi = reB.lastIndex;
  2346. }
  2347. // Add remains of b.
  2348. if (bi < b.length) {
  2349. bs = b.slice(bi);
  2350. if (s[i]) s[i] += bs; // coalesce with previous string
  2351. else s[++i] = bs;
  2352. }
  2353. // Special optimization for only a single match.
  2354. // Otherwise, interpolate each of the numbers and rejoin the string.
  2355. return s.length < 2 ? (q[0]
  2356. ? one(q[0].x)
  2357. : zero(b))
  2358. : (b = q.length, function(t) {
  2359. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2360. return s.join("");
  2361. });
  2362. }
  2363. function interpolateValue(a, b) {
  2364. var t = typeof b, c;
  2365. return b == null || t === "boolean" ? constant$3(b)
  2366. : (t === "number" ? interpolateNumber
  2367. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2368. : b instanceof color ? interpolateRgb
  2369. : b instanceof Date ? date
  2370. : Array.isArray(b) ? array$1
  2371. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2372. : interpolateNumber)(a, b);
  2373. }
  2374. function discrete(range) {
  2375. var n = range.length;
  2376. return function(t) {
  2377. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2378. };
  2379. }
  2380. function hue$1(a, b) {
  2381. var i = hue(+a, +b);
  2382. return function(t) {
  2383. var x = i(t);
  2384. return x - 360 * Math.floor(x / 360);
  2385. };
  2386. }
  2387. function interpolateRound(a, b) {
  2388. return a = +a, b -= a, function(t) {
  2389. return Math.round(a + b * t);
  2390. };
  2391. }
  2392. var degrees = 180 / Math.PI;
  2393. var identity$2 = {
  2394. translateX: 0,
  2395. translateY: 0,
  2396. rotate: 0,
  2397. skewX: 0,
  2398. scaleX: 1,
  2399. scaleY: 1
  2400. };
  2401. function decompose(a, b, c, d, e, f) {
  2402. var scaleX, scaleY, skewX;
  2403. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2404. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2405. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2406. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2407. return {
  2408. translateX: e,
  2409. translateY: f,
  2410. rotate: Math.atan2(b, a) * degrees,
  2411. skewX: Math.atan(skewX) * degrees,
  2412. scaleX: scaleX,
  2413. scaleY: scaleY
  2414. };
  2415. }
  2416. var cssNode,
  2417. cssRoot,
  2418. cssView,
  2419. svgNode;
  2420. function parseCss(value) {
  2421. if (value === "none") return identity$2;
  2422. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2423. cssNode.style.transform = value;
  2424. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2425. cssRoot.removeChild(cssNode);
  2426. value = value.slice(7, -1).split(",");
  2427. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2428. }
  2429. function parseSvg(value) {
  2430. if (value == null) return identity$2;
  2431. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2432. svgNode.setAttribute("transform", value);
  2433. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2434. value = value.matrix;
  2435. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2436. }
  2437. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2438. function pop(s) {
  2439. return s.length ? s.pop() + " " : "";
  2440. }
  2441. function translate(xa, ya, xb, yb, s, q) {
  2442. if (xa !== xb || ya !== yb) {
  2443. var i = s.push("translate(", null, pxComma, null, pxParen);
  2444. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2445. } else if (xb || yb) {
  2446. s.push("translate(" + xb + pxComma + yb + pxParen);
  2447. }
  2448. }
  2449. function rotate(a, b, s, q) {
  2450. if (a !== b) {
  2451. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2452. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2453. } else if (b) {
  2454. s.push(pop(s) + "rotate(" + b + degParen);
  2455. }
  2456. }
  2457. function skewX(a, b, s, q) {
  2458. if (a !== b) {
  2459. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2460. } else if (b) {
  2461. s.push(pop(s) + "skewX(" + b + degParen);
  2462. }
  2463. }
  2464. function scale(xa, ya, xb, yb, s, q) {
  2465. if (xa !== xb || ya !== yb) {
  2466. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2467. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2468. } else if (xb !== 1 || yb !== 1) {
  2469. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2470. }
  2471. }
  2472. return function(a, b) {
  2473. var s = [], // string constants and placeholders
  2474. q = []; // number interpolators
  2475. a = parse(a), b = parse(b);
  2476. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2477. rotate(a.rotate, b.rotate, s, q);
  2478. skewX(a.skewX, b.skewX, s, q);
  2479. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2480. a = b = null; // gc
  2481. return function(t) {
  2482. var i = -1, n = q.length, o;
  2483. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2484. return s.join("");
  2485. };
  2486. };
  2487. }
  2488. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2489. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2490. var rho = Math.SQRT2,
  2491. rho2 = 2,
  2492. rho4 = 4,
  2493. epsilon2 = 1e-12;
  2494. function cosh(x) {
  2495. return ((x = Math.exp(x)) + 1 / x) / 2;
  2496. }
  2497. function sinh(x) {
  2498. return ((x = Math.exp(x)) - 1 / x) / 2;
  2499. }
  2500. function tanh(x) {
  2501. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2502. }
  2503. // p0 = [ux0, uy0, w0]
  2504. // p1 = [ux1, uy1, w1]
  2505. function interpolateZoom(p0, p1) {
  2506. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2507. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2508. dx = ux1 - ux0,
  2509. dy = uy1 - uy0,
  2510. d2 = dx * dx + dy * dy,
  2511. i,
  2512. S;
  2513. // Special case for u0 ≅ u1.
  2514. if (d2 < epsilon2) {
  2515. S = Math.log(w1 / w0) / rho;
  2516. i = function(t) {
  2517. return [
  2518. ux0 + t * dx,
  2519. uy0 + t * dy,
  2520. w0 * Math.exp(rho * t * S)
  2521. ];
  2522. };
  2523. }
  2524. // General case.
  2525. else {
  2526. var d1 = Math.sqrt(d2),
  2527. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2528. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2529. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2530. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2531. S = (r1 - r0) / rho;
  2532. i = function(t) {
  2533. var s = t * S,
  2534. coshr0 = cosh(r0),
  2535. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2536. return [
  2537. ux0 + u * dx,
  2538. uy0 + u * dy,
  2539. w0 * coshr0 / cosh(rho * s + r0)
  2540. ];
  2541. };
  2542. }
  2543. i.duration = S * 1000;
  2544. return i;
  2545. }
  2546. function hsl$1(hue$$1) {
  2547. return function(start, end) {
  2548. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2549. s = nogamma(start.s, end.s),
  2550. l = nogamma(start.l, end.l),
  2551. opacity = nogamma(start.opacity, end.opacity);
  2552. return function(t) {
  2553. start.h = h(t);
  2554. start.s = s(t);
  2555. start.l = l(t);
  2556. start.opacity = opacity(t);
  2557. return start + "";
  2558. };
  2559. }
  2560. }
  2561. var hsl$2 = hsl$1(hue);
  2562. var hslLong = hsl$1(nogamma);
  2563. function lab$1(start, end) {
  2564. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2565. a = nogamma(start.a, end.a),
  2566. b = nogamma(start.b, end.b),
  2567. opacity = nogamma(start.opacity, end.opacity);
  2568. return function(t) {
  2569. start.l = l(t);
  2570. start.a = a(t);
  2571. start.b = b(t);
  2572. start.opacity = opacity(t);
  2573. return start + "";
  2574. };
  2575. }
  2576. function hcl$1(hue$$1) {
  2577. return function(start, end) {
  2578. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2579. c = nogamma(start.c, end.c),
  2580. l = nogamma(start.l, end.l),
  2581. opacity = nogamma(start.opacity, end.opacity);
  2582. return function(t) {
  2583. start.h = h(t);
  2584. start.c = c(t);
  2585. start.l = l(t);
  2586. start.opacity = opacity(t);
  2587. return start + "";
  2588. };
  2589. }
  2590. }
  2591. var hcl$2 = hcl$1(hue);
  2592. var hclLong = hcl$1(nogamma);
  2593. function cubehelix$1(hue$$1) {
  2594. return (function cubehelixGamma(y) {
  2595. y = +y;
  2596. function cubehelix$$1(start, end) {
  2597. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2598. s = nogamma(start.s, end.s),
  2599. l = nogamma(start.l, end.l),
  2600. opacity = nogamma(start.opacity, end.opacity);
  2601. return function(t) {
  2602. start.h = h(t);
  2603. start.s = s(t);
  2604. start.l = l(Math.pow(t, y));
  2605. start.opacity = opacity(t);
  2606. return start + "";
  2607. };
  2608. }
  2609. cubehelix$$1.gamma = cubehelixGamma;
  2610. return cubehelix$$1;
  2611. })(1);
  2612. }
  2613. var cubehelix$2 = cubehelix$1(hue);
  2614. var cubehelixLong = cubehelix$1(nogamma);
  2615. function piecewise(interpolate, values) {
  2616. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2617. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2618. return function(t) {
  2619. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2620. return I[i](t - i);
  2621. };
  2622. }
  2623. function quantize(interpolator, n) {
  2624. var samples = new Array(n);
  2625. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2626. return samples;
  2627. }
  2628. var frame = 0, // is an animation frame pending?
  2629. timeout = 0, // is a timeout pending?
  2630. interval = 0, // are any timers active?
  2631. pokeDelay = 1000, // how frequently we check for clock skew
  2632. taskHead,
  2633. taskTail,
  2634. clockLast = 0,
  2635. clockNow = 0,
  2636. clockSkew = 0,
  2637. clock = typeof performance === "object" && performance.now ? performance : Date,
  2638. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2639. function now() {
  2640. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2641. }
  2642. function clearNow() {
  2643. clockNow = 0;
  2644. }
  2645. function Timer() {
  2646. this._call =
  2647. this._time =
  2648. this._next = null;
  2649. }
  2650. Timer.prototype = timer.prototype = {
  2651. constructor: Timer,
  2652. restart: function(callback, delay, time) {
  2653. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2654. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2655. if (!this._next && taskTail !== this) {
  2656. if (taskTail) taskTail._next = this;
  2657. else taskHead = this;
  2658. taskTail = this;
  2659. }
  2660. this._call = callback;
  2661. this._time = time;
  2662. sleep();
  2663. },
  2664. stop: function() {
  2665. if (this._call) {
  2666. this._call = null;
  2667. this._time = Infinity;
  2668. sleep();
  2669. }
  2670. }
  2671. };
  2672. function timer(callback, delay, time) {
  2673. var t = new Timer;
  2674. t.restart(callback, delay, time);
  2675. return t;
  2676. }
  2677. function timerFlush() {
  2678. now(); // Get the current time, if not already set.
  2679. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2680. var t = taskHead, e;
  2681. while (t) {
  2682. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2683. t = t._next;
  2684. }
  2685. --frame;
  2686. }
  2687. function wake() {
  2688. clockNow = (clockLast = clock.now()) + clockSkew;
  2689. frame = timeout = 0;
  2690. try {
  2691. timerFlush();
  2692. } finally {
  2693. frame = 0;
  2694. nap();
  2695. clockNow = 0;
  2696. }
  2697. }
  2698. function poke() {
  2699. var now = clock.now(), delay = now - clockLast;
  2700. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2701. }
  2702. function nap() {
  2703. var t0, t1 = taskHead, t2, time = Infinity;
  2704. while (t1) {
  2705. if (t1._call) {
  2706. if (time > t1._time) time = t1._time;
  2707. t0 = t1, t1 = t1._next;
  2708. } else {
  2709. t2 = t1._next, t1._next = null;
  2710. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2711. }
  2712. }
  2713. taskTail = t0;
  2714. sleep(time);
  2715. }
  2716. function sleep(time) {
  2717. if (frame) return; // Soonest alarm already set, or will be.
  2718. if (timeout) timeout = clearTimeout(timeout);
  2719. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2720. if (delay > 24) {
  2721. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2722. if (interval) interval = clearInterval(interval);
  2723. } else {
  2724. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2725. frame = 1, setFrame(wake);
  2726. }
  2727. }
  2728. function timeout$1(callback, delay, time) {
  2729. var t = new Timer;
  2730. delay = delay == null ? 0 : +delay;
  2731. t.restart(function(elapsed) {
  2732. t.stop();
  2733. callback(elapsed + delay);
  2734. }, delay, time);
  2735. return t;
  2736. }
  2737. function interval$1(callback, delay, time) {
  2738. var t = new Timer, total = delay;
  2739. if (delay == null) return t.restart(callback, delay, time), t;
  2740. delay = +delay, time = time == null ? now() : +time;
  2741. t.restart(function tick(elapsed) {
  2742. elapsed += total;
  2743. t.restart(tick, total += delay, time);
  2744. callback(elapsed);
  2745. }, delay, time);
  2746. return t;
  2747. }
  2748. var emptyOn = dispatch("start", "end", "interrupt");
  2749. var emptyTween = [];
  2750. var CREATED = 0;
  2751. var SCHEDULED = 1;
  2752. var STARTING = 2;
  2753. var STARTED = 3;
  2754. var RUNNING = 4;
  2755. var ENDING = 5;
  2756. var ENDED = 6;
  2757. function schedule(node, name, id, index, group, timing) {
  2758. var schedules = node.__transition;
  2759. if (!schedules) node.__transition = {};
  2760. else if (id in schedules) return;
  2761. create$1(node, id, {
  2762. name: name,
  2763. index: index, // For context during callback.
  2764. group: group, // For context during callback.
  2765. on: emptyOn,
  2766. tween: emptyTween,
  2767. time: timing.time,
  2768. delay: timing.delay,
  2769. duration: timing.duration,
  2770. ease: timing.ease,
  2771. timer: null,
  2772. state: CREATED
  2773. });
  2774. }
  2775. function init(node, id) {
  2776. var schedule = get$1(node, id);
  2777. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2778. return schedule;
  2779. }
  2780. function set$1(node, id) {
  2781. var schedule = get$1(node, id);
  2782. if (schedule.state > STARTING) throw new Error("too late; already started");
  2783. return schedule;
  2784. }
  2785. function get$1(node, id) {
  2786. var schedule = node.__transition;
  2787. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2788. return schedule;
  2789. }
  2790. function create$1(node, id, self) {
  2791. var schedules = node.__transition,
  2792. tween;
  2793. // Initialize the self timer when the transition is created.
  2794. // Note the actual delay is not known until the first callback!
  2795. schedules[id] = self;
  2796. self.timer = timer(schedule, 0, self.time);
  2797. function schedule(elapsed) {
  2798. self.state = SCHEDULED;
  2799. self.timer.restart(start, self.delay, self.time);
  2800. // If the elapsed delay is less than our first sleep, start immediately.
  2801. if (self.delay <= elapsed) start(elapsed - self.delay);
  2802. }
  2803. function start(elapsed) {
  2804. var i, j, n, o;
  2805. // If the state is not SCHEDULED, then we previously errored on start.
  2806. if (self.state !== SCHEDULED) return stop();
  2807. for (i in schedules) {
  2808. o = schedules[i];
  2809. if (o.name !== self.name) continue;
  2810. // While this element already has a starting transition during this frame,
  2811. // defer starting an interrupting transition until that transition has a
  2812. // chance to tick (and possibly end); see d3/d3-transition#54!
  2813. if (o.state === STARTED) return timeout$1(start);
  2814. // Interrupt the active transition, if any.
  2815. // Dispatch the interrupt event.
  2816. if (o.state === RUNNING) {
  2817. o.state = ENDED;
  2818. o.timer.stop();
  2819. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2820. delete schedules[i];
  2821. }
  2822. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2823. // because the cancelled transitions never started. Note that this also
  2824. // removes this transition from the pending list!
  2825. else if (+i < id) {
  2826. o.state = ENDED;
  2827. o.timer.stop();
  2828. delete schedules[i];
  2829. }
  2830. }
  2831. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2832. // Note the transition may be canceled after start and before the first tick!
  2833. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2834. // Assuming this is successful, subsequent callbacks go straight to tick.
  2835. timeout$1(function() {
  2836. if (self.state === STARTED) {
  2837. self.state = RUNNING;
  2838. self.timer.restart(tick, self.delay, self.time);
  2839. tick(elapsed);
  2840. }
  2841. });
  2842. // Dispatch the start event.
  2843. // Note this must be done before the tween are initialized.
  2844. self.state = STARTING;
  2845. self.on.call("start", node, node.__data__, self.index, self.group);
  2846. if (self.state !== STARTING) return; // interrupted
  2847. self.state = STARTED;
  2848. // Initialize the tween, deleting null tween.
  2849. tween = new Array(n = self.tween.length);
  2850. for (i = 0, j = -1; i < n; ++i) {
  2851. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2852. tween[++j] = o;
  2853. }
  2854. }
  2855. tween.length = j + 1;
  2856. }
  2857. function tick(elapsed) {
  2858. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2859. i = -1,
  2860. n = tween.length;
  2861. while (++i < n) {
  2862. tween[i].call(null, t);
  2863. }
  2864. // Dispatch the end event.
  2865. if (self.state === ENDING) {
  2866. self.on.call("end", node, node.__data__, self.index, self.group);
  2867. stop();
  2868. }
  2869. }
  2870. function stop() {
  2871. self.state = ENDED;
  2872. self.timer.stop();
  2873. delete schedules[id];
  2874. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2875. delete node.__transition;
  2876. }
  2877. }
  2878. function interrupt(node, name) {
  2879. var schedules = node.__transition,
  2880. schedule$$1,
  2881. active,
  2882. empty = true,
  2883. i;
  2884. if (!schedules) return;
  2885. name = name == null ? null : name + "";
  2886. for (i in schedules) {
  2887. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2888. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2889. schedule$$1.state = ENDED;
  2890. schedule$$1.timer.stop();
  2891. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2892. delete schedules[i];
  2893. }
  2894. if (empty) delete node.__transition;
  2895. }
  2896. function selection_interrupt(name) {
  2897. return this.each(function() {
  2898. interrupt(this, name);
  2899. });
  2900. }
  2901. function tweenRemove(id, name) {
  2902. var tween0, tween1;
  2903. return function() {
  2904. var schedule$$1 = set$1(this, id),
  2905. tween = schedule$$1.tween;
  2906. // If this node shared tween with the previous node,
  2907. // just assign the updated shared tween and we’re done!
  2908. // Otherwise, copy-on-write.
  2909. if (tween !== tween0) {
  2910. tween1 = tween0 = tween;
  2911. for (var i = 0, n = tween1.length; i < n; ++i) {
  2912. if (tween1[i].name === name) {
  2913. tween1 = tween1.slice();
  2914. tween1.splice(i, 1);
  2915. break;
  2916. }
  2917. }
  2918. }
  2919. schedule$$1.tween = tween1;
  2920. };
  2921. }
  2922. function tweenFunction(id, name, value) {
  2923. var tween0, tween1;
  2924. if (typeof value !== "function") throw new Error;
  2925. return function() {
  2926. var schedule$$1 = set$1(this, id),
  2927. tween = schedule$$1.tween;
  2928. // If this node shared tween with the previous node,
  2929. // just assign the updated shared tween and we’re done!
  2930. // Otherwise, copy-on-write.
  2931. if (tween !== tween0) {
  2932. tween1 = (tween0 = tween).slice();
  2933. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2934. if (tween1[i].name === name) {
  2935. tween1[i] = t;
  2936. break;
  2937. }
  2938. }
  2939. if (i === n) tween1.push(t);
  2940. }
  2941. schedule$$1.tween = tween1;
  2942. };
  2943. }
  2944. function transition_tween(name, value) {
  2945. var id = this._id;
  2946. name += "";
  2947. if (arguments.length < 2) {
  2948. var tween = get$1(this.node(), id).tween;
  2949. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2950. if ((t = tween[i]).name === name) {
  2951. return t.value;
  2952. }
  2953. }
  2954. return null;
  2955. }
  2956. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2957. }
  2958. function tweenValue(transition, name, value) {
  2959. var id = transition._id;
  2960. transition.each(function() {
  2961. var schedule$$1 = set$1(this, id);
  2962. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2963. });
  2964. return function(node) {
  2965. return get$1(node, id).value[name];
  2966. };
  2967. }
  2968. function interpolate(a, b) {
  2969. var c;
  2970. return (typeof b === "number" ? interpolateNumber
  2971. : b instanceof color ? interpolateRgb
  2972. : (c = color(b)) ? (b = c, interpolateRgb)
  2973. : interpolateString)(a, b);
  2974. }
  2975. function attrRemove$1(name) {
  2976. return function() {
  2977. this.removeAttribute(name);
  2978. };
  2979. }
  2980. function attrRemoveNS$1(fullname) {
  2981. return function() {
  2982. this.removeAttributeNS(fullname.space, fullname.local);
  2983. };
  2984. }
  2985. function attrConstant$1(name, interpolate$$1, value1) {
  2986. var value00,
  2987. interpolate0;
  2988. return function() {
  2989. var value0 = this.getAttribute(name);
  2990. return value0 === value1 ? null
  2991. : value0 === value00 ? interpolate0
  2992. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2993. };
  2994. }
  2995. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2996. var value00,
  2997. interpolate0;
  2998. return function() {
  2999. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  3000. return value0 === value1 ? null
  3001. : value0 === value00 ? interpolate0
  3002. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3003. };
  3004. }
  3005. function attrFunction$1(name, interpolate$$1, value) {
  3006. var value00,
  3007. value10,
  3008. interpolate0;
  3009. return function() {
  3010. var value0, value1 = value(this);
  3011. if (value1 == null) return void this.removeAttribute(name);
  3012. value0 = this.getAttribute(name);
  3013. return value0 === value1 ? null
  3014. : value0 === value00 && value1 === value10 ? interpolate0
  3015. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3016. };
  3017. }
  3018. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  3019. var value00,
  3020. value10,
  3021. interpolate0;
  3022. return function() {
  3023. var value0, value1 = value(this);
  3024. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3025. value0 = this.getAttributeNS(fullname.space, fullname.local);
  3026. return value0 === value1 ? null
  3027. : value0 === value00 && value1 === value10 ? interpolate0
  3028. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3029. };
  3030. }
  3031. function transition_attr(name, value) {
  3032. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3033. return this.attrTween(name, typeof value === "function"
  3034. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3035. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3036. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  3037. }
  3038. function attrTweenNS(fullname, value) {
  3039. function tween() {
  3040. var node = this, i = value.apply(node, arguments);
  3041. return i && function(t) {
  3042. node.setAttributeNS(fullname.space, fullname.local, i(t));
  3043. };
  3044. }
  3045. tween._value = value;
  3046. return tween;
  3047. }
  3048. function attrTween(name, value) {
  3049. function tween() {
  3050. var node = this, i = value.apply(node, arguments);
  3051. return i && function(t) {
  3052. node.setAttribute(name, i(t));
  3053. };
  3054. }
  3055. tween._value = value;
  3056. return tween;
  3057. }
  3058. function transition_attrTween(name, value) {
  3059. var key = "attr." + name;
  3060. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3061. if (value == null) return this.tween(key, null);
  3062. if (typeof value !== "function") throw new Error;
  3063. var fullname = namespace(name);
  3064. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3065. }
  3066. function delayFunction(id, value) {
  3067. return function() {
  3068. init(this, id).delay = +value.apply(this, arguments);
  3069. };
  3070. }
  3071. function delayConstant(id, value) {
  3072. return value = +value, function() {
  3073. init(this, id).delay = value;
  3074. };
  3075. }
  3076. function transition_delay(value) {
  3077. var id = this._id;
  3078. return arguments.length
  3079. ? this.each((typeof value === "function"
  3080. ? delayFunction
  3081. : delayConstant)(id, value))
  3082. : get$1(this.node(), id).delay;
  3083. }
  3084. function durationFunction(id, value) {
  3085. return function() {
  3086. set$1(this, id).duration = +value.apply(this, arguments);
  3087. };
  3088. }
  3089. function durationConstant(id, value) {
  3090. return value = +value, function() {
  3091. set$1(this, id).duration = value;
  3092. };
  3093. }
  3094. function transition_duration(value) {
  3095. var id = this._id;
  3096. return arguments.length
  3097. ? this.each((typeof value === "function"
  3098. ? durationFunction
  3099. : durationConstant)(id, value))
  3100. : get$1(this.node(), id).duration;
  3101. }
  3102. function easeConstant(id, value) {
  3103. if (typeof value !== "function") throw new Error;
  3104. return function() {
  3105. set$1(this, id).ease = value;
  3106. };
  3107. }
  3108. function transition_ease(value) {
  3109. var id = this._id;
  3110. return arguments.length
  3111. ? this.each(easeConstant(id, value))
  3112. : get$1(this.node(), id).ease;
  3113. }
  3114. function transition_filter(match) {
  3115. if (typeof match !== "function") match = matcher$1(match);
  3116. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3117. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3118. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3119. subgroup.push(node);
  3120. }
  3121. }
  3122. }
  3123. return new Transition(subgroups, this._parents, this._name, this._id);
  3124. }
  3125. function transition_merge(transition$$1) {
  3126. if (transition$$1._id !== this._id) throw new Error;
  3127. for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3128. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3129. if (node = group0[i] || group1[i]) {
  3130. merge[i] = node;
  3131. }
  3132. }
  3133. }
  3134. for (; j < m0; ++j) {
  3135. merges[j] = groups0[j];
  3136. }
  3137. return new Transition(merges, this._parents, this._name, this._id);
  3138. }
  3139. function start(name) {
  3140. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3141. var i = t.indexOf(".");
  3142. if (i >= 0) t = t.slice(0, i);
  3143. return !t || t === "start";
  3144. });
  3145. }
  3146. function onFunction(id, name, listener) {
  3147. var on0, on1, sit = start(name) ? init : set$1;
  3148. return function() {
  3149. var schedule$$1 = sit(this, id),
  3150. on = schedule$$1.on;
  3151. // If this node shared a dispatch with the previous node,
  3152. // just assign the updated shared dispatch and we’re done!
  3153. // Otherwise, copy-on-write.
  3154. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3155. schedule$$1.on = on1;
  3156. };
  3157. }
  3158. function transition_on(name, listener) {
  3159. var id = this._id;
  3160. return arguments.length < 2
  3161. ? get$1(this.node(), id).on.on(name)
  3162. : this.each(onFunction(id, name, listener));
  3163. }
  3164. function removeFunction(id) {
  3165. return function() {
  3166. var parent = this.parentNode;
  3167. for (var i in this.__transition) if (+i !== id) return;
  3168. if (parent) parent.removeChild(this);
  3169. };
  3170. }
  3171. function transition_remove() {
  3172. return this.on("end.remove", removeFunction(this._id));
  3173. }
  3174. function transition_select(select$$1) {
  3175. var name = this._name,
  3176. id = this._id;
  3177. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  3178. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3179. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3180. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  3181. if ("__data__" in node) subnode.__data__ = node.__data__;
  3182. subgroup[i] = subnode;
  3183. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3184. }
  3185. }
  3186. }
  3187. return new Transition(subgroups, this._parents, name, id);
  3188. }
  3189. function transition_selectAll(select$$1) {
  3190. var name = this._name,
  3191. id = this._id;
  3192. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  3193. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3194. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3195. if (node = group[i]) {
  3196. for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3197. if (child = children[k]) {
  3198. schedule(child, name, id, k, children, inherit);
  3199. }
  3200. }
  3201. subgroups.push(children);
  3202. parents.push(node);
  3203. }
  3204. }
  3205. }
  3206. return new Transition(subgroups, parents, name, id);
  3207. }
  3208. var Selection$1 = selection.prototype.constructor;
  3209. function transition_selection() {
  3210. return new Selection$1(this._groups, this._parents);
  3211. }
  3212. function styleRemove$1(name, interpolate$$1) {
  3213. var value00,
  3214. value10,
  3215. interpolate0;
  3216. return function() {
  3217. var value0 = styleValue(this, name),
  3218. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3219. return value0 === value1 ? null
  3220. : value0 === value00 && value1 === value10 ? interpolate0
  3221. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3222. };
  3223. }
  3224. function styleRemoveEnd(name) {
  3225. return function() {
  3226. this.style.removeProperty(name);
  3227. };
  3228. }
  3229. function styleConstant$1(name, interpolate$$1, value1) {
  3230. var value00,
  3231. interpolate0;
  3232. return function() {
  3233. var value0 = styleValue(this, name);
  3234. return value0 === value1 ? null
  3235. : value0 === value00 ? interpolate0
  3236. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3237. };
  3238. }
  3239. function styleFunction$1(name, interpolate$$1, value) {
  3240. var value00,
  3241. value10,
  3242. interpolate0;
  3243. return function() {
  3244. var value0 = styleValue(this, name),
  3245. value1 = value(this);
  3246. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3247. return value0 === value1 ? null
  3248. : value0 === value00 && value1 === value10 ? interpolate0
  3249. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3250. };
  3251. }
  3252. function transition_style(name, value, priority) {
  3253. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3254. return value == null ? this
  3255. .styleTween(name, styleRemove$1(name, i))
  3256. .on("end.style." + name, styleRemoveEnd(name))
  3257. : this.styleTween(name, typeof value === "function"
  3258. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3259. : styleConstant$1(name, i, value + ""), priority);
  3260. }
  3261. function styleTween(name, value, priority) {
  3262. function tween() {
  3263. var node = this, i = value.apply(node, arguments);
  3264. return i && function(t) {
  3265. node.style.setProperty(name, i(t), priority);
  3266. };
  3267. }
  3268. tween._value = value;
  3269. return tween;
  3270. }
  3271. function transition_styleTween(name, value, priority) {
  3272. var key = "style." + (name += "");
  3273. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3274. if (value == null) return this.tween(key, null);
  3275. if (typeof value !== "function") throw new Error;
  3276. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3277. }
  3278. function textConstant$1(value) {
  3279. return function() {
  3280. this.textContent = value;
  3281. };
  3282. }
  3283. function textFunction$1(value) {
  3284. return function() {
  3285. var value1 = value(this);
  3286. this.textContent = value1 == null ? "" : value1;
  3287. };
  3288. }
  3289. function transition_text(value) {
  3290. return this.tween("text", typeof value === "function"
  3291. ? textFunction$1(tweenValue(this, "text", value))
  3292. : textConstant$1(value == null ? "" : value + ""));
  3293. }
  3294. function transition_transition() {
  3295. var name = this._name,
  3296. id0 = this._id,
  3297. id1 = newId();
  3298. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3299. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3300. if (node = group[i]) {
  3301. var inherit = get$1(node, id0);
  3302. schedule(node, name, id1, i, group, {
  3303. time: inherit.time + inherit.delay + inherit.duration,
  3304. delay: 0,
  3305. duration: inherit.duration,
  3306. ease: inherit.ease
  3307. });
  3308. }
  3309. }
  3310. }
  3311. return new Transition(groups, this._parents, name, id1);
  3312. }
  3313. var id = 0;
  3314. function Transition(groups, parents, name, id) {
  3315. this._groups = groups;
  3316. this._parents = parents;
  3317. this._name = name;
  3318. this._id = id;
  3319. }
  3320. function transition(name) {
  3321. return selection().transition(name);
  3322. }
  3323. function newId() {
  3324. return ++id;
  3325. }
  3326. var selection_prototype = selection.prototype;
  3327. Transition.prototype = transition.prototype = {
  3328. constructor: Transition,
  3329. select: transition_select,
  3330. selectAll: transition_selectAll,
  3331. filter: transition_filter,
  3332. merge: transition_merge,
  3333. selection: transition_selection,
  3334. transition: transition_transition,
  3335. call: selection_prototype.call,
  3336. nodes: selection_prototype.nodes,
  3337. node: selection_prototype.node,
  3338. size: selection_prototype.size,
  3339. empty: selection_prototype.empty,
  3340. each: selection_prototype.each,
  3341. on: transition_on,
  3342. attr: transition_attr,
  3343. attrTween: transition_attrTween,
  3344. style: transition_style,
  3345. styleTween: transition_styleTween,
  3346. text: transition_text,
  3347. remove: transition_remove,
  3348. tween: transition_tween,
  3349. delay: transition_delay,
  3350. duration: transition_duration,
  3351. ease: transition_ease
  3352. };
  3353. function linear$1(t) {
  3354. return +t;
  3355. }
  3356. function quadIn(t) {
  3357. return t * t;
  3358. }
  3359. function quadOut(t) {
  3360. return t * (2 - t);
  3361. }
  3362. function quadInOut(t) {
  3363. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3364. }
  3365. function cubicIn(t) {
  3366. return t * t * t;
  3367. }
  3368. function cubicOut(t) {
  3369. return --t * t * t + 1;
  3370. }
  3371. function cubicInOut(t) {
  3372. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3373. }
  3374. var exponent = 3;
  3375. var polyIn = (function custom(e) {
  3376. e = +e;
  3377. function polyIn(t) {
  3378. return Math.pow(t, e);
  3379. }
  3380. polyIn.exponent = custom;
  3381. return polyIn;
  3382. })(exponent);
  3383. var polyOut = (function custom(e) {
  3384. e = +e;
  3385. function polyOut(t) {
  3386. return 1 - Math.pow(1 - t, e);
  3387. }
  3388. polyOut.exponent = custom;
  3389. return polyOut;
  3390. })(exponent);
  3391. var polyInOut = (function custom(e) {
  3392. e = +e;
  3393. function polyInOut(t) {
  3394. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3395. }
  3396. polyInOut.exponent = custom;
  3397. return polyInOut;
  3398. })(exponent);
  3399. var pi = Math.PI,
  3400. halfPi = pi / 2;
  3401. function sinIn(t) {
  3402. return 1 - Math.cos(t * halfPi);
  3403. }
  3404. function sinOut(t) {
  3405. return Math.sin(t * halfPi);
  3406. }
  3407. function sinInOut(t) {
  3408. return (1 - Math.cos(pi * t)) / 2;
  3409. }
  3410. function expIn(t) {
  3411. return Math.pow(2, 10 * t - 10);
  3412. }
  3413. function expOut(t) {
  3414. return 1 - Math.pow(2, -10 * t);
  3415. }
  3416. function expInOut(t) {
  3417. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3418. }
  3419. function circleIn(t) {
  3420. return 1 - Math.sqrt(1 - t * t);
  3421. }
  3422. function circleOut(t) {
  3423. return Math.sqrt(1 - --t * t);
  3424. }
  3425. function circleInOut(t) {
  3426. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3427. }
  3428. var b1 = 4 / 11,
  3429. b2 = 6 / 11,
  3430. b3 = 8 / 11,
  3431. b4 = 3 / 4,
  3432. b5 = 9 / 11,
  3433. b6 = 10 / 11,
  3434. b7 = 15 / 16,
  3435. b8 = 21 / 22,
  3436. b9 = 63 / 64,
  3437. b0 = 1 / b1 / b1;
  3438. function bounceIn(t) {
  3439. return 1 - bounceOut(1 - t);
  3440. }
  3441. function bounceOut(t) {
  3442. 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;
  3443. }
  3444. function bounceInOut(t) {
  3445. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3446. }
  3447. var overshoot = 1.70158;
  3448. var backIn = (function custom(s) {
  3449. s = +s;
  3450. function backIn(t) {
  3451. return t * t * ((s + 1) * t - s);
  3452. }
  3453. backIn.overshoot = custom;
  3454. return backIn;
  3455. })(overshoot);
  3456. var backOut = (function custom(s) {
  3457. s = +s;
  3458. function backOut(t) {
  3459. return --t * t * ((s + 1) * t + s) + 1;
  3460. }
  3461. backOut.overshoot = custom;
  3462. return backOut;
  3463. })(overshoot);
  3464. var backInOut = (function custom(s) {
  3465. s = +s;
  3466. function backInOut(t) {
  3467. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3468. }
  3469. backInOut.overshoot = custom;
  3470. return backInOut;
  3471. })(overshoot);
  3472. var tau = 2 * Math.PI,
  3473. amplitude = 1,
  3474. period = 0.3;
  3475. var elasticIn = (function custom(a, p) {
  3476. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3477. function elasticIn(t) {
  3478. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3479. }
  3480. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3481. elasticIn.period = function(p) { return custom(a, p); };
  3482. return elasticIn;
  3483. })(amplitude, period);
  3484. var elasticOut = (function custom(a, p) {
  3485. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3486. function elasticOut(t) {
  3487. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3488. }
  3489. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3490. elasticOut.period = function(p) { return custom(a, p); };
  3491. return elasticOut;
  3492. })(amplitude, period);
  3493. var elasticInOut = (function custom(a, p) {
  3494. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3495. function elasticInOut(t) {
  3496. return ((t = t * 2 - 1) < 0
  3497. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3498. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3499. }
  3500. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3501. elasticInOut.period = function(p) { return custom(a, p); };
  3502. return elasticInOut;
  3503. })(amplitude, period);
  3504. var defaultTiming = {
  3505. time: null, // Set on use.
  3506. delay: 0,
  3507. duration: 250,
  3508. ease: cubicInOut
  3509. };
  3510. function inherit(node, id) {
  3511. var timing;
  3512. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3513. if (!(node = node.parentNode)) {
  3514. return defaultTiming.time = now(), defaultTiming;
  3515. }
  3516. }
  3517. return timing;
  3518. }
  3519. function selection_transition(name) {
  3520. var id,
  3521. timing;
  3522. if (name instanceof Transition) {
  3523. id = name._id, name = name._name;
  3524. } else {
  3525. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3526. }
  3527. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3528. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3529. if (node = group[i]) {
  3530. schedule(node, name, id, i, group, timing || inherit(node, id));
  3531. }
  3532. }
  3533. }
  3534. return new Transition(groups, this._parents, name, id);
  3535. }
  3536. selection.prototype.interrupt = selection_interrupt;
  3537. selection.prototype.transition = selection_transition;
  3538. var root$1 = [null];
  3539. function active(node, name) {
  3540. var schedules = node.__transition,
  3541. schedule$$1,
  3542. i;
  3543. if (schedules) {
  3544. name = name == null ? null : name + "";
  3545. for (i in schedules) {
  3546. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3547. return new Transition([[node]], root$1, name, +i);
  3548. }
  3549. }
  3550. }
  3551. return null;
  3552. }
  3553. function constant$4(x) {
  3554. return function() {
  3555. return x;
  3556. };
  3557. }
  3558. function BrushEvent(target, type, selection) {
  3559. this.target = target;
  3560. this.type = type;
  3561. this.selection = selection;
  3562. }
  3563. function nopropagation$1() {
  3564. exports.event.stopImmediatePropagation();
  3565. }
  3566. function noevent$1() {
  3567. exports.event.preventDefault();
  3568. exports.event.stopImmediatePropagation();
  3569. }
  3570. var MODE_DRAG = {name: "drag"},
  3571. MODE_SPACE = {name: "space"},
  3572. MODE_HANDLE = {name: "handle"},
  3573. MODE_CENTER = {name: "center"};
  3574. var X = {
  3575. name: "x",
  3576. handles: ["e", "w"].map(type),
  3577. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3578. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3579. };
  3580. var Y = {
  3581. name: "y",
  3582. handles: ["n", "s"].map(type),
  3583. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3584. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3585. };
  3586. var XY = {
  3587. name: "xy",
  3588. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3589. input: function(xy) { return xy; },
  3590. output: function(xy) { return xy; }
  3591. };
  3592. var cursors = {
  3593. overlay: "crosshair",
  3594. selection: "move",
  3595. n: "ns-resize",
  3596. e: "ew-resize",
  3597. s: "ns-resize",
  3598. w: "ew-resize",
  3599. nw: "nwse-resize",
  3600. ne: "nesw-resize",
  3601. se: "nwse-resize",
  3602. sw: "nesw-resize"
  3603. };
  3604. var flipX = {
  3605. e: "w",
  3606. w: "e",
  3607. nw: "ne",
  3608. ne: "nw",
  3609. se: "sw",
  3610. sw: "se"
  3611. };
  3612. var flipY = {
  3613. n: "s",
  3614. s: "n",
  3615. nw: "sw",
  3616. ne: "se",
  3617. se: "ne",
  3618. sw: "nw"
  3619. };
  3620. var signsX = {
  3621. overlay: +1,
  3622. selection: +1,
  3623. n: null,
  3624. e: +1,
  3625. s: null,
  3626. w: -1,
  3627. nw: -1,
  3628. ne: +1,
  3629. se: +1,
  3630. sw: -1
  3631. };
  3632. var signsY = {
  3633. overlay: +1,
  3634. selection: +1,
  3635. n: -1,
  3636. e: null,
  3637. s: +1,
  3638. w: null,
  3639. nw: -1,
  3640. ne: -1,
  3641. se: +1,
  3642. sw: +1
  3643. };
  3644. function type(t) {
  3645. return {type: t};
  3646. }
  3647. // Ignore right-click, since that should open the context menu.
  3648. function defaultFilter$1() {
  3649. return !exports.event.button;
  3650. }
  3651. function defaultExtent() {
  3652. var svg = this.ownerSVGElement || this;
  3653. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3654. }
  3655. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3656. function local$1(node) {
  3657. while (!node.__brush) if (!(node = node.parentNode)) return;
  3658. return node.__brush;
  3659. }
  3660. function empty$1(extent) {
  3661. return extent[0][0] === extent[1][0]
  3662. || extent[0][1] === extent[1][1];
  3663. }
  3664. function brushSelection(node) {
  3665. var state = node.__brush;
  3666. return state ? state.dim.output(state.selection) : null;
  3667. }
  3668. function brushX() {
  3669. return brush$1(X);
  3670. }
  3671. function brushY() {
  3672. return brush$1(Y);
  3673. }
  3674. function brush() {
  3675. return brush$1(XY);
  3676. }
  3677. function brush$1(dim) {
  3678. var extent = defaultExtent,
  3679. filter = defaultFilter$1,
  3680. listeners = dispatch(brush, "start", "brush", "end"),
  3681. handleSize = 6,
  3682. touchending;
  3683. function brush(group) {
  3684. var overlay = group
  3685. .property("__brush", initialize)
  3686. .selectAll(".overlay")
  3687. .data([type("overlay")]);
  3688. overlay.enter().append("rect")
  3689. .attr("class", "overlay")
  3690. .attr("pointer-events", "all")
  3691. .attr("cursor", cursors.overlay)
  3692. .merge(overlay)
  3693. .each(function() {
  3694. var extent = local$1(this).extent;
  3695. select(this)
  3696. .attr("x", extent[0][0])
  3697. .attr("y", extent[0][1])
  3698. .attr("width", extent[1][0] - extent[0][0])
  3699. .attr("height", extent[1][1] - extent[0][1]);
  3700. });
  3701. group.selectAll(".selection")
  3702. .data([type("selection")])
  3703. .enter().append("rect")
  3704. .attr("class", "selection")
  3705. .attr("cursor", cursors.selection)
  3706. .attr("fill", "#777")
  3707. .attr("fill-opacity", 0.3)
  3708. .attr("stroke", "#fff")
  3709. .attr("shape-rendering", "crispEdges");
  3710. var handle = group.selectAll(".handle")
  3711. .data(dim.handles, function(d) { return d.type; });
  3712. handle.exit().remove();
  3713. handle.enter().append("rect")
  3714. .attr("class", function(d) { return "handle handle--" + d.type; })
  3715. .attr("cursor", function(d) { return cursors[d.type]; });
  3716. group
  3717. .each(redraw)
  3718. .attr("fill", "none")
  3719. .attr("pointer-events", "all")
  3720. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3721. .on("mousedown.brush touchstart.brush", started);
  3722. }
  3723. brush.move = function(group, selection$$1) {
  3724. if (group.selection) {
  3725. group
  3726. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3727. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3728. .tween("brush", function() {
  3729. var that = this,
  3730. state = that.__brush,
  3731. emit = emitter(that, arguments),
  3732. selection0 = state.selection,
  3733. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  3734. i = interpolateValue(selection0, selection1);
  3735. function tween(t) {
  3736. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  3737. redraw.call(that);
  3738. emit.brush();
  3739. }
  3740. return selection0 && selection1 ? tween : tween(1);
  3741. });
  3742. } else {
  3743. group
  3744. .each(function() {
  3745. var that = this,
  3746. args = arguments,
  3747. state = that.__brush,
  3748. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  3749. emit = emitter(that, args).beforestart();
  3750. interrupt(that);
  3751. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  3752. redraw.call(that);
  3753. emit.start().brush().end();
  3754. });
  3755. }
  3756. };
  3757. function redraw() {
  3758. var group = select(this),
  3759. selection$$1 = local$1(this).selection;
  3760. if (selection$$1) {
  3761. group.selectAll(".selection")
  3762. .style("display", null)
  3763. .attr("x", selection$$1[0][0])
  3764. .attr("y", selection$$1[0][1])
  3765. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  3766. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  3767. group.selectAll(".handle")
  3768. .style("display", null)
  3769. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  3770. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  3771. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  3772. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  3773. }
  3774. else {
  3775. group.selectAll(".selection,.handle")
  3776. .style("display", "none")
  3777. .attr("x", null)
  3778. .attr("y", null)
  3779. .attr("width", null)
  3780. .attr("height", null);
  3781. }
  3782. }
  3783. function emitter(that, args) {
  3784. return that.__brush.emitter || new Emitter(that, args);
  3785. }
  3786. function Emitter(that, args) {
  3787. this.that = that;
  3788. this.args = args;
  3789. this.state = that.__brush;
  3790. this.active = 0;
  3791. }
  3792. Emitter.prototype = {
  3793. beforestart: function() {
  3794. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3795. return this;
  3796. },
  3797. start: function() {
  3798. if (this.starting) this.starting = false, this.emit("start");
  3799. return this;
  3800. },
  3801. brush: function() {
  3802. this.emit("brush");
  3803. return this;
  3804. },
  3805. end: function() {
  3806. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3807. return this;
  3808. },
  3809. emit: function(type) {
  3810. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3811. }
  3812. };
  3813. function started() {
  3814. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3815. else if (touchending) return;
  3816. if (!filter.apply(this, arguments)) return;
  3817. var that = this,
  3818. type = exports.event.target.__data__.type,
  3819. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3820. signX = dim === Y ? null : signsX[type],
  3821. signY = dim === X ? null : signsY[type],
  3822. state = local$1(that),
  3823. extent = state.extent,
  3824. selection$$1 = state.selection,
  3825. W = extent[0][0], w0, w1,
  3826. N = extent[0][1], n0, n1,
  3827. E = extent[1][0], e0, e1,
  3828. S = extent[1][1], s0, s1,
  3829. dx,
  3830. dy,
  3831. moving,
  3832. shifting = signX && signY && exports.event.shiftKey,
  3833. lockX,
  3834. lockY,
  3835. point0 = mouse(that),
  3836. point$$1 = point0,
  3837. emit = emitter(that, arguments).beforestart();
  3838. if (type === "overlay") {
  3839. state.selection = selection$$1 = [
  3840. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3841. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3842. ];
  3843. } else {
  3844. w0 = selection$$1[0][0];
  3845. n0 = selection$$1[0][1];
  3846. e0 = selection$$1[1][0];
  3847. s0 = selection$$1[1][1];
  3848. }
  3849. w1 = w0;
  3850. n1 = n0;
  3851. e1 = e0;
  3852. s1 = s0;
  3853. var group = select(that)
  3854. .attr("pointer-events", "none");
  3855. var overlay = group.selectAll(".overlay")
  3856. .attr("cursor", cursors[type]);
  3857. if (exports.event.touches) {
  3858. group
  3859. .on("touchmove.brush", moved, true)
  3860. .on("touchend.brush touchcancel.brush", ended, true);
  3861. } else {
  3862. var view = select(exports.event.view)
  3863. .on("keydown.brush", keydowned, true)
  3864. .on("keyup.brush", keyupped, true)
  3865. .on("mousemove.brush", moved, true)
  3866. .on("mouseup.brush", ended, true);
  3867. dragDisable(exports.event.view);
  3868. }
  3869. nopropagation$1();
  3870. interrupt(that);
  3871. redraw.call(that);
  3872. emit.start();
  3873. function moved() {
  3874. var point1 = mouse(that);
  3875. if (shifting && !lockX && !lockY) {
  3876. if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
  3877. else lockX = true;
  3878. }
  3879. point$$1 = point1;
  3880. moving = true;
  3881. noevent$1();
  3882. move();
  3883. }
  3884. function move() {
  3885. var t;
  3886. dx = point$$1[0] - point0[0];
  3887. dy = point$$1[1] - point0[1];
  3888. switch (mode) {
  3889. case MODE_SPACE:
  3890. case MODE_DRAG: {
  3891. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3892. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3893. break;
  3894. }
  3895. case MODE_HANDLE: {
  3896. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3897. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3898. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3899. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3900. break;
  3901. }
  3902. case MODE_CENTER: {
  3903. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3904. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3905. break;
  3906. }
  3907. }
  3908. if (e1 < w1) {
  3909. signX *= -1;
  3910. t = w0, w0 = e0, e0 = t;
  3911. t = w1, w1 = e1, e1 = t;
  3912. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3913. }
  3914. if (s1 < n1) {
  3915. signY *= -1;
  3916. t = n0, n0 = s0, s0 = t;
  3917. t = n1, n1 = s1, s1 = t;
  3918. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3919. }
  3920. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  3921. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  3922. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  3923. if (selection$$1[0][0] !== w1
  3924. || selection$$1[0][1] !== n1
  3925. || selection$$1[1][0] !== e1
  3926. || selection$$1[1][1] !== s1) {
  3927. state.selection = [[w1, n1], [e1, s1]];
  3928. redraw.call(that);
  3929. emit.brush();
  3930. }
  3931. }
  3932. function ended() {
  3933. nopropagation$1();
  3934. if (exports.event.touches) {
  3935. if (exports.event.touches.length) return;
  3936. if (touchending) clearTimeout(touchending);
  3937. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3938. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3939. } else {
  3940. yesdrag(exports.event.view, moving);
  3941. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3942. }
  3943. group.attr("pointer-events", "all");
  3944. overlay.attr("cursor", cursors.overlay);
  3945. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  3946. if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
  3947. emit.end();
  3948. }
  3949. function keydowned() {
  3950. switch (exports.event.keyCode) {
  3951. case 16: { // SHIFT
  3952. shifting = signX && signY;
  3953. break;
  3954. }
  3955. case 18: { // ALT
  3956. if (mode === MODE_HANDLE) {
  3957. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3958. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3959. mode = MODE_CENTER;
  3960. move();
  3961. }
  3962. break;
  3963. }
  3964. case 32: { // SPACE; takes priority over ALT
  3965. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3966. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3967. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3968. mode = MODE_SPACE;
  3969. overlay.attr("cursor", cursors.selection);
  3970. move();
  3971. }
  3972. break;
  3973. }
  3974. default: return;
  3975. }
  3976. noevent$1();
  3977. }
  3978. function keyupped() {
  3979. switch (exports.event.keyCode) {
  3980. case 16: { // SHIFT
  3981. if (shifting) {
  3982. lockX = lockY = shifting = false;
  3983. move();
  3984. }
  3985. break;
  3986. }
  3987. case 18: { // ALT
  3988. if (mode === MODE_CENTER) {
  3989. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3990. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3991. mode = MODE_HANDLE;
  3992. move();
  3993. }
  3994. break;
  3995. }
  3996. case 32: { // SPACE
  3997. if (mode === MODE_SPACE) {
  3998. if (exports.event.altKey) {
  3999. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4000. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4001. mode = MODE_CENTER;
  4002. } else {
  4003. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4004. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4005. mode = MODE_HANDLE;
  4006. }
  4007. overlay.attr("cursor", cursors[type]);
  4008. move();
  4009. }
  4010. break;
  4011. }
  4012. default: return;
  4013. }
  4014. noevent$1();
  4015. }
  4016. }
  4017. function initialize() {
  4018. var state = this.__brush || {selection: null};
  4019. state.extent = extent.apply(this, arguments);
  4020. state.dim = dim;
  4021. return state;
  4022. }
  4023. brush.extent = function(_) {
  4024. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  4025. };
  4026. brush.filter = function(_) {
  4027. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4028. };
  4029. brush.handleSize = function(_) {
  4030. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4031. };
  4032. brush.on = function() {
  4033. var value = listeners.on.apply(listeners, arguments);
  4034. return value === listeners ? brush : value;
  4035. };
  4036. return brush;
  4037. }
  4038. var cos = Math.cos;
  4039. var sin = Math.sin;
  4040. var pi$1 = Math.PI;
  4041. var halfPi$1 = pi$1 / 2;
  4042. var tau$1 = pi$1 * 2;
  4043. var max$1 = Math.max;
  4044. function compareValue(compare) {
  4045. return function(a, b) {
  4046. return compare(
  4047. a.source.value + a.target.value,
  4048. b.source.value + b.target.value
  4049. );
  4050. };
  4051. }
  4052. function chord() {
  4053. var padAngle = 0,
  4054. sortGroups = null,
  4055. sortSubgroups = null,
  4056. sortChords = null;
  4057. function chord(matrix) {
  4058. var n = matrix.length,
  4059. groupSums = [],
  4060. groupIndex = sequence(n),
  4061. subgroupIndex = [],
  4062. chords = [],
  4063. groups = chords.groups = new Array(n),
  4064. subgroups = new Array(n * n),
  4065. k,
  4066. x,
  4067. x0,
  4068. dx,
  4069. i,
  4070. j;
  4071. // Compute the sum.
  4072. k = 0, i = -1; while (++i < n) {
  4073. x = 0, j = -1; while (++j < n) {
  4074. x += matrix[i][j];
  4075. }
  4076. groupSums.push(x);
  4077. subgroupIndex.push(sequence(n));
  4078. k += x;
  4079. }
  4080. // Sort groups…
  4081. if (sortGroups) groupIndex.sort(function(a, b) {
  4082. return sortGroups(groupSums[a], groupSums[b]);
  4083. });
  4084. // Sort subgroups…
  4085. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4086. d.sort(function(a, b) {
  4087. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4088. });
  4089. });
  4090. // Convert the sum to scaling factor for [0, 2pi].
  4091. // TODO Allow start and end angle to be specified?
  4092. // TODO Allow padding to be specified as percentage?
  4093. k = max$1(0, tau$1 - padAngle * n) / k;
  4094. dx = k ? padAngle : tau$1 / n;
  4095. // Compute the start and end angle for each group and subgroup.
  4096. // Note: Opera has a bug reordering object literal properties!
  4097. x = 0, i = -1; while (++i < n) {
  4098. x0 = x, j = -1; while (++j < n) {
  4099. var di = groupIndex[i],
  4100. dj = subgroupIndex[di][j],
  4101. v = matrix[di][dj],
  4102. a0 = x,
  4103. a1 = x += v * k;
  4104. subgroups[dj * n + di] = {
  4105. index: di,
  4106. subindex: dj,
  4107. startAngle: a0,
  4108. endAngle: a1,
  4109. value: v
  4110. };
  4111. }
  4112. groups[di] = {
  4113. index: di,
  4114. startAngle: x0,
  4115. endAngle: x,
  4116. value: groupSums[di]
  4117. };
  4118. x += dx;
  4119. }
  4120. // Generate chords for each (non-empty) subgroup-subgroup link.
  4121. i = -1; while (++i < n) {
  4122. j = i - 1; while (++j < n) {
  4123. var source = subgroups[j * n + i],
  4124. target = subgroups[i * n + j];
  4125. if (source.value || target.value) {
  4126. chords.push(source.value < target.value
  4127. ? {source: target, target: source}
  4128. : {source: source, target: target});
  4129. }
  4130. }
  4131. }
  4132. return sortChords ? chords.sort(sortChords) : chords;
  4133. }
  4134. chord.padAngle = function(_) {
  4135. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4136. };
  4137. chord.sortGroups = function(_) {
  4138. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4139. };
  4140. chord.sortSubgroups = function(_) {
  4141. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4142. };
  4143. chord.sortChords = function(_) {
  4144. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4145. };
  4146. return chord;
  4147. }
  4148. var slice$2 = Array.prototype.slice;
  4149. function constant$5(x) {
  4150. return function() {
  4151. return x;
  4152. };
  4153. }
  4154. var pi$2 = Math.PI,
  4155. tau$2 = 2 * pi$2,
  4156. epsilon$1 = 1e-6,
  4157. tauEpsilon = tau$2 - epsilon$1;
  4158. function Path() {
  4159. this._x0 = this._y0 = // start of current subpath
  4160. this._x1 = this._y1 = null; // end of current subpath
  4161. this._ = "";
  4162. }
  4163. function path() {
  4164. return new Path;
  4165. }
  4166. Path.prototype = path.prototype = {
  4167. constructor: Path,
  4168. moveTo: function(x, y) {
  4169. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4170. },
  4171. closePath: function() {
  4172. if (this._x1 !== null) {
  4173. this._x1 = this._x0, this._y1 = this._y0;
  4174. this._ += "Z";
  4175. }
  4176. },
  4177. lineTo: function(x, y) {
  4178. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4179. },
  4180. quadraticCurveTo: function(x1, y1, x, y) {
  4181. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4182. },
  4183. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4184. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4185. },
  4186. arcTo: function(x1, y1, x2, y2, r) {
  4187. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4188. var x0 = this._x1,
  4189. y0 = this._y1,
  4190. x21 = x2 - x1,
  4191. y21 = y2 - y1,
  4192. x01 = x0 - x1,
  4193. y01 = y0 - y1,
  4194. l01_2 = x01 * x01 + y01 * y01;
  4195. // Is the radius negative? Error.
  4196. if (r < 0) throw new Error("negative radius: " + r);
  4197. // Is this path empty? Move to (x1,y1).
  4198. if (this._x1 === null) {
  4199. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4200. }
  4201. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4202. else if (!(l01_2 > epsilon$1));
  4203. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4204. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4205. // Or, is the radius zero? Line to (x1,y1).
  4206. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4207. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4208. }
  4209. // Otherwise, draw an arc!
  4210. else {
  4211. var x20 = x2 - x0,
  4212. y20 = y2 - y0,
  4213. l21_2 = x21 * x21 + y21 * y21,
  4214. l20_2 = x20 * x20 + y20 * y20,
  4215. l21 = Math.sqrt(l21_2),
  4216. l01 = Math.sqrt(l01_2),
  4217. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4218. t01 = l / l01,
  4219. t21 = l / l21;
  4220. // If the start tangent is not coincident with (x0,y0), line to.
  4221. if (Math.abs(t01 - 1) > epsilon$1) {
  4222. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4223. }
  4224. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4225. }
  4226. },
  4227. arc: function(x, y, r, a0, a1, ccw) {
  4228. x = +x, y = +y, r = +r;
  4229. var dx = r * Math.cos(a0),
  4230. dy = r * Math.sin(a0),
  4231. x0 = x + dx,
  4232. y0 = y + dy,
  4233. cw = 1 ^ ccw,
  4234. da = ccw ? a0 - a1 : a1 - a0;
  4235. // Is the radius negative? Error.
  4236. if (r < 0) throw new Error("negative radius: " + r);
  4237. // Is this path empty? Move to (x0,y0).
  4238. if (this._x1 === null) {
  4239. this._ += "M" + x0 + "," + y0;
  4240. }
  4241. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4242. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4243. this._ += "L" + x0 + "," + y0;
  4244. }
  4245. // Is this arc empty? We’re done.
  4246. if (!r) return;
  4247. // Does the angle go the wrong way? Flip the direction.
  4248. if (da < 0) da = da % tau$2 + tau$2;
  4249. // Is this a complete circle? Draw two arcs to complete the circle.
  4250. if (da > tauEpsilon) {
  4251. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4252. }
  4253. // Is this arc non-empty? Draw an arc!
  4254. else if (da > epsilon$1) {
  4255. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4256. }
  4257. },
  4258. rect: function(x, y, w, h) {
  4259. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4260. },
  4261. toString: function() {
  4262. return this._;
  4263. }
  4264. };
  4265. function defaultSource(d) {
  4266. return d.source;
  4267. }
  4268. function defaultTarget(d) {
  4269. return d.target;
  4270. }
  4271. function defaultRadius(d) {
  4272. return d.radius;
  4273. }
  4274. function defaultStartAngle(d) {
  4275. return d.startAngle;
  4276. }
  4277. function defaultEndAngle(d) {
  4278. return d.endAngle;
  4279. }
  4280. function ribbon() {
  4281. var source = defaultSource,
  4282. target = defaultTarget,
  4283. radius = defaultRadius,
  4284. startAngle = defaultStartAngle,
  4285. endAngle = defaultEndAngle,
  4286. context = null;
  4287. function ribbon() {
  4288. var buffer,
  4289. argv = slice$2.call(arguments),
  4290. s = source.apply(this, argv),
  4291. t = target.apply(this, argv),
  4292. sr = +radius.apply(this, (argv[0] = s, argv)),
  4293. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4294. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4295. sx0 = sr * cos(sa0),
  4296. sy0 = sr * sin(sa0),
  4297. tr = +radius.apply(this, (argv[0] = t, argv)),
  4298. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4299. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4300. if (!context) context = buffer = path();
  4301. context.moveTo(sx0, sy0);
  4302. context.arc(0, 0, sr, sa0, sa1);
  4303. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4304. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4305. context.arc(0, 0, tr, ta0, ta1);
  4306. }
  4307. context.quadraticCurveTo(0, 0, sx0, sy0);
  4308. context.closePath();
  4309. if (buffer) return context = null, buffer + "" || null;
  4310. }
  4311. ribbon.radius = function(_) {
  4312. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4313. };
  4314. ribbon.startAngle = function(_) {
  4315. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4316. };
  4317. ribbon.endAngle = function(_) {
  4318. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4319. };
  4320. ribbon.source = function(_) {
  4321. return arguments.length ? (source = _, ribbon) : source;
  4322. };
  4323. ribbon.target = function(_) {
  4324. return arguments.length ? (target = _, ribbon) : target;
  4325. };
  4326. ribbon.context = function(_) {
  4327. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4328. };
  4329. return ribbon;
  4330. }
  4331. var prefix = "$";
  4332. function Map() {}
  4333. Map.prototype = map$1.prototype = {
  4334. constructor: Map,
  4335. has: function(key) {
  4336. return (prefix + key) in this;
  4337. },
  4338. get: function(key) {
  4339. return this[prefix + key];
  4340. },
  4341. set: function(key, value) {
  4342. this[prefix + key] = value;
  4343. return this;
  4344. },
  4345. remove: function(key) {
  4346. var property = prefix + key;
  4347. return property in this && delete this[property];
  4348. },
  4349. clear: function() {
  4350. for (var property in this) if (property[0] === prefix) delete this[property];
  4351. },
  4352. keys: function() {
  4353. var keys = [];
  4354. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4355. return keys;
  4356. },
  4357. values: function() {
  4358. var values = [];
  4359. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4360. return values;
  4361. },
  4362. entries: function() {
  4363. var entries = [];
  4364. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4365. return entries;
  4366. },
  4367. size: function() {
  4368. var size = 0;
  4369. for (var property in this) if (property[0] === prefix) ++size;
  4370. return size;
  4371. },
  4372. empty: function() {
  4373. for (var property in this) if (property[0] === prefix) return false;
  4374. return true;
  4375. },
  4376. each: function(f) {
  4377. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4378. }
  4379. };
  4380. function map$1(object, f) {
  4381. var map = new Map;
  4382. // Copy constructor.
  4383. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4384. // Index array by numeric index or specified key function.
  4385. else if (Array.isArray(object)) {
  4386. var i = -1,
  4387. n = object.length,
  4388. o;
  4389. if (f == null) while (++i < n) map.set(i, object[i]);
  4390. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4391. }
  4392. // Convert object to map.
  4393. else if (object) for (var key in object) map.set(key, object[key]);
  4394. return map;
  4395. }
  4396. function nest() {
  4397. var keys = [],
  4398. sortKeys = [],
  4399. sortValues,
  4400. rollup,
  4401. nest;
  4402. function apply(array, depth, createResult, setResult) {
  4403. if (depth >= keys.length) {
  4404. if (sortValues != null) array.sort(sortValues);
  4405. return rollup != null ? rollup(array) : array;
  4406. }
  4407. var i = -1,
  4408. n = array.length,
  4409. key = keys[depth++],
  4410. keyValue,
  4411. value,
  4412. valuesByKey = map$1(),
  4413. values,
  4414. result = createResult();
  4415. while (++i < n) {
  4416. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4417. values.push(value);
  4418. } else {
  4419. valuesByKey.set(keyValue, [value]);
  4420. }
  4421. }
  4422. valuesByKey.each(function(values, key) {
  4423. setResult(result, key, apply(values, depth, createResult, setResult));
  4424. });
  4425. return result;
  4426. }
  4427. function entries(map, depth) {
  4428. if (++depth > keys.length) return map;
  4429. var array, sortKey = sortKeys[depth - 1];
  4430. if (rollup != null && depth >= keys.length) array = map.entries();
  4431. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4432. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4433. }
  4434. return nest = {
  4435. object: function(array) { return apply(array, 0, createObject, setObject); },
  4436. map: function(array) { return apply(array, 0, createMap, setMap); },
  4437. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4438. key: function(d) { keys.push(d); return nest; },
  4439. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4440. sortValues: function(order) { sortValues = order; return nest; },
  4441. rollup: function(f) { rollup = f; return nest; }
  4442. };
  4443. }
  4444. function createObject() {
  4445. return {};
  4446. }
  4447. function setObject(object, key, value) {
  4448. object[key] = value;
  4449. }
  4450. function createMap() {
  4451. return map$1();
  4452. }
  4453. function setMap(map, key, value) {
  4454. map.set(key, value);
  4455. }
  4456. function Set() {}
  4457. var proto = map$1.prototype;
  4458. Set.prototype = set$2.prototype = {
  4459. constructor: Set,
  4460. has: proto.has,
  4461. add: function(value) {
  4462. value += "";
  4463. this[prefix + value] = value;
  4464. return this;
  4465. },
  4466. remove: proto.remove,
  4467. clear: proto.clear,
  4468. values: proto.keys,
  4469. size: proto.size,
  4470. empty: proto.empty,
  4471. each: proto.each
  4472. };
  4473. function set$2(object, f) {
  4474. var set = new Set;
  4475. // Copy constructor.
  4476. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4477. // Otherwise, assume it’s an array.
  4478. else if (object) {
  4479. var i = -1, n = object.length;
  4480. if (f == null) while (++i < n) set.add(object[i]);
  4481. else while (++i < n) set.add(f(object[i], i, object));
  4482. }
  4483. return set;
  4484. }
  4485. function keys(map) {
  4486. var keys = [];
  4487. for (var key in map) keys.push(key);
  4488. return keys;
  4489. }
  4490. function values(map) {
  4491. var values = [];
  4492. for (var key in map) values.push(map[key]);
  4493. return values;
  4494. }
  4495. function entries(map) {
  4496. var entries = [];
  4497. for (var key in map) entries.push({key: key, value: map[key]});
  4498. return entries;
  4499. }
  4500. var array$2 = Array.prototype;
  4501. var slice$3 = array$2.slice;
  4502. function ascending$2(a, b) {
  4503. return a - b;
  4504. }
  4505. function area(ring) {
  4506. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4507. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4508. return area;
  4509. }
  4510. function constant$6(x) {
  4511. return function() {
  4512. return x;
  4513. };
  4514. }
  4515. function contains(ring, hole) {
  4516. var i = -1, n = hole.length, c;
  4517. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4518. return 0;
  4519. }
  4520. function ringContains(ring, point) {
  4521. var x = point[0], y = point[1], contains = -1;
  4522. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4523. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4524. if (segmentContains(pi, pj, point)) return 0;
  4525. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4526. }
  4527. return contains;
  4528. }
  4529. function segmentContains(a, b, c) {
  4530. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4531. }
  4532. function collinear(a, b, c) {
  4533. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4534. }
  4535. function within(p, q, r) {
  4536. return p <= q && q <= r || r <= q && q <= p;
  4537. }
  4538. function noop$1() {}
  4539. var cases = [
  4540. [],
  4541. [[[1.0, 1.5], [0.5, 1.0]]],
  4542. [[[1.5, 1.0], [1.0, 1.5]]],
  4543. [[[1.5, 1.0], [0.5, 1.0]]],
  4544. [[[1.0, 0.5], [1.5, 1.0]]],
  4545. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4546. [[[1.0, 0.5], [1.0, 1.5]]],
  4547. [[[1.0, 0.5], [0.5, 1.0]]],
  4548. [[[0.5, 1.0], [1.0, 0.5]]],
  4549. [[[1.0, 1.5], [1.0, 0.5]]],
  4550. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4551. [[[1.5, 1.0], [1.0, 0.5]]],
  4552. [[[0.5, 1.0], [1.5, 1.0]]],
  4553. [[[1.0, 1.5], [1.5, 1.0]]],
  4554. [[[0.5, 1.0], [1.0, 1.5]]],
  4555. []
  4556. ];
  4557. function contours() {
  4558. var dx = 1,
  4559. dy = 1,
  4560. threshold$$1 = thresholdSturges,
  4561. smooth = smoothLinear;
  4562. function contours(values) {
  4563. var tz = threshold$$1(values);
  4564. // Convert number of thresholds into uniform thresholds.
  4565. if (!Array.isArray(tz)) {
  4566. var domain = extent(values), start = domain[0], stop = domain[1];
  4567. tz = tickStep(start, stop, tz);
  4568. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4569. } else {
  4570. tz = tz.slice().sort(ascending$2);
  4571. }
  4572. return tz.map(function(value) {
  4573. return contour(values, value);
  4574. });
  4575. }
  4576. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4577. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4578. function contour(values, value) {
  4579. var polygons = [],
  4580. holes = [];
  4581. isorings(values, value, function(ring) {
  4582. smooth(ring, values, value);
  4583. if (area(ring) > 0) polygons.push([ring]);
  4584. else holes.push(ring);
  4585. });
  4586. holes.forEach(function(hole) {
  4587. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4588. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4589. polygon.push(hole);
  4590. return;
  4591. }
  4592. }
  4593. });
  4594. return {
  4595. type: "MultiPolygon",
  4596. value: value,
  4597. coordinates: polygons
  4598. };
  4599. }
  4600. // Marching squares with isolines stitched into rings.
  4601. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4602. function isorings(values, value, callback) {
  4603. var fragmentByStart = new Array,
  4604. fragmentByEnd = new Array,
  4605. x, y, t0, t1, t2, t3;
  4606. // Special case for the first row (y = -1, t2 = t3 = 0).
  4607. x = y = -1;
  4608. t1 = values[0] >= value;
  4609. cases[t1 << 1].forEach(stitch);
  4610. while (++x < dx - 1) {
  4611. t0 = t1, t1 = values[x + 1] >= value;
  4612. cases[t0 | t1 << 1].forEach(stitch);
  4613. }
  4614. cases[t1 << 0].forEach(stitch);
  4615. // General case for the intermediate rows.
  4616. while (++y < dy - 1) {
  4617. x = -1;
  4618. t1 = values[y * dx + dx] >= value;
  4619. t2 = values[y * dx] >= value;
  4620. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4621. while (++x < dx - 1) {
  4622. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4623. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4624. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4625. }
  4626. cases[t1 | t2 << 3].forEach(stitch);
  4627. }
  4628. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4629. x = -1;
  4630. t2 = values[y * dx] >= value;
  4631. cases[t2 << 2].forEach(stitch);
  4632. while (++x < dx - 1) {
  4633. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4634. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4635. }
  4636. cases[t2 << 3].forEach(stitch);
  4637. function stitch(line) {
  4638. var start = [line[0][0] + x, line[0][1] + y],
  4639. end = [line[1][0] + x, line[1][1] + y],
  4640. startIndex = index(start),
  4641. endIndex = index(end),
  4642. f, g;
  4643. if (f = fragmentByEnd[startIndex]) {
  4644. if (g = fragmentByStart[endIndex]) {
  4645. delete fragmentByEnd[f.end];
  4646. delete fragmentByStart[g.start];
  4647. if (f === g) {
  4648. f.ring.push(end);
  4649. callback(f.ring);
  4650. } else {
  4651. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4652. }
  4653. } else {
  4654. delete fragmentByEnd[f.end];
  4655. f.ring.push(end);
  4656. fragmentByEnd[f.end = endIndex] = f;
  4657. }
  4658. } else if (f = fragmentByStart[endIndex]) {
  4659. if (g = fragmentByEnd[startIndex]) {
  4660. delete fragmentByStart[f.start];
  4661. delete fragmentByEnd[g.end];
  4662. if (f === g) {
  4663. f.ring.push(end);
  4664. callback(f.ring);
  4665. } else {
  4666. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4667. }
  4668. } else {
  4669. delete fragmentByStart[f.start];
  4670. f.ring.unshift(start);
  4671. fragmentByStart[f.start = startIndex] = f;
  4672. }
  4673. } else {
  4674. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4675. }
  4676. }
  4677. }
  4678. function index(point) {
  4679. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4680. }
  4681. function smoothLinear(ring, values, value) {
  4682. ring.forEach(function(point) {
  4683. var x = point[0],
  4684. y = point[1],
  4685. xt = x | 0,
  4686. yt = y | 0,
  4687. v0,
  4688. v1 = values[yt * dx + xt];
  4689. if (x > 0 && x < dx && xt === x) {
  4690. v0 = values[yt * dx + xt - 1];
  4691. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4692. }
  4693. if (y > 0 && y < dy && yt === y) {
  4694. v0 = values[(yt - 1) * dx + xt];
  4695. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4696. }
  4697. });
  4698. }
  4699. contours.contour = contour;
  4700. contours.size = function(_) {
  4701. if (!arguments.length) return [dx, dy];
  4702. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4703. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4704. return dx = _0, dy = _1, contours;
  4705. };
  4706. contours.thresholds = function(_) {
  4707. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
  4708. };
  4709. contours.smooth = function(_) {
  4710. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4711. };
  4712. return contours;
  4713. }
  4714. // TODO Optimize edge cases.
  4715. // TODO Optimize index calculation.
  4716. // TODO Optimize arguments.
  4717. function blurX(source, target, r) {
  4718. var n = source.width,
  4719. m = source.height,
  4720. w = (r << 1) + 1;
  4721. for (var j = 0; j < m; ++j) {
  4722. for (var i = 0, sr = 0; i < n + r; ++i) {
  4723. if (i < n) {
  4724. sr += source.data[i + j * n];
  4725. }
  4726. if (i >= r) {
  4727. if (i >= w) {
  4728. sr -= source.data[i - w + j * n];
  4729. }
  4730. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4731. }
  4732. }
  4733. }
  4734. }
  4735. // TODO Optimize edge cases.
  4736. // TODO Optimize index calculation.
  4737. // TODO Optimize arguments.
  4738. function blurY(source, target, r) {
  4739. var n = source.width,
  4740. m = source.height,
  4741. w = (r << 1) + 1;
  4742. for (var i = 0; i < n; ++i) {
  4743. for (var j = 0, sr = 0; j < m + r; ++j) {
  4744. if (j < m) {
  4745. sr += source.data[i + j * n];
  4746. }
  4747. if (j >= r) {
  4748. if (j >= w) {
  4749. sr -= source.data[i + (j - w) * n];
  4750. }
  4751. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4752. }
  4753. }
  4754. }
  4755. }
  4756. function defaultX(d) {
  4757. return d[0];
  4758. }
  4759. function defaultY(d) {
  4760. return d[1];
  4761. }
  4762. function defaultWeight() {
  4763. return 1;
  4764. }
  4765. function density() {
  4766. var x = defaultX,
  4767. y = defaultY,
  4768. weight = defaultWeight,
  4769. dx = 960,
  4770. dy = 500,
  4771. r = 20, // blur radius
  4772. k = 2, // log2(grid cell size)
  4773. o = r * 3, // grid offset, to pad for blur
  4774. n = (dx + o * 2) >> k, // grid width
  4775. m = (dy + o * 2) >> k, // grid height
  4776. threshold$$1 = constant$6(20);
  4777. function density(data) {
  4778. var values0 = new Float32Array(n * m),
  4779. values1 = new Float32Array(n * m);
  4780. data.forEach(function(d, i, data) {
  4781. var xi = (+x(d, i, data) + o) >> k,
  4782. yi = (+y(d, i, data) + o) >> k,
  4783. wi = +weight(d, i, data);
  4784. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4785. values0[xi + yi * n] += wi;
  4786. }
  4787. });
  4788. // TODO Optimize.
  4789. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4790. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4791. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4792. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4793. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4794. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4795. var tz = threshold$$1(values0);
  4796. // Convert number of thresholds into uniform thresholds.
  4797. if (!Array.isArray(tz)) {
  4798. var stop = max(values0);
  4799. tz = tickStep(0, stop, tz);
  4800. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4801. tz.shift();
  4802. }
  4803. return contours()
  4804. .thresholds(tz)
  4805. .size([n, m])
  4806. (values0)
  4807. .map(transform);
  4808. }
  4809. function transform(geometry) {
  4810. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4811. geometry.coordinates.forEach(transformPolygon);
  4812. return geometry;
  4813. }
  4814. function transformPolygon(coordinates) {
  4815. coordinates.forEach(transformRing);
  4816. }
  4817. function transformRing(coordinates) {
  4818. coordinates.forEach(transformPoint);
  4819. }
  4820. // TODO Optimize.
  4821. function transformPoint(coordinates) {
  4822. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4823. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4824. }
  4825. function resize() {
  4826. o = r * 3;
  4827. n = (dx + o * 2) >> k;
  4828. m = (dy + o * 2) >> k;
  4829. return density;
  4830. }
  4831. density.x = function(_) {
  4832. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4833. };
  4834. density.y = function(_) {
  4835. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4836. };
  4837. density.weight = function(_) {
  4838. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4839. };
  4840. density.size = function(_) {
  4841. if (!arguments.length) return [dx, dy];
  4842. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4843. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4844. return dx = _0, dy = _1, resize();
  4845. };
  4846. density.cellSize = function(_) {
  4847. if (!arguments.length) return 1 << k;
  4848. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4849. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4850. };
  4851. density.thresholds = function(_) {
  4852. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
  4853. };
  4854. density.bandwidth = function(_) {
  4855. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4856. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4857. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4858. };
  4859. return density;
  4860. }
  4861. var EOL = {},
  4862. EOF = {},
  4863. QUOTE = 34,
  4864. NEWLINE = 10,
  4865. RETURN = 13;
  4866. function objectConverter(columns) {
  4867. return new Function("d", "return {" + columns.map(function(name, i) {
  4868. return JSON.stringify(name) + ": d[" + i + "]";
  4869. }).join(",") + "}");
  4870. }
  4871. function customConverter(columns, f) {
  4872. var object = objectConverter(columns);
  4873. return function(row, i) {
  4874. return f(object(row), i, columns);
  4875. };
  4876. }
  4877. // Compute unique columns in order of discovery.
  4878. function inferColumns(rows) {
  4879. var columnSet = Object.create(null),
  4880. columns = [];
  4881. rows.forEach(function(row) {
  4882. for (var column in row) {
  4883. if (!(column in columnSet)) {
  4884. columns.push(columnSet[column] = column);
  4885. }
  4886. }
  4887. });
  4888. return columns;
  4889. }
  4890. function dsvFormat(delimiter) {
  4891. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4892. DELIMITER = delimiter.charCodeAt(0);
  4893. function parse(text, f) {
  4894. var convert, columns, rows = parseRows(text, function(row, i) {
  4895. if (convert) return convert(row, i - 1);
  4896. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4897. });
  4898. rows.columns = columns || [];
  4899. return rows;
  4900. }
  4901. function parseRows(text, f) {
  4902. var rows = [], // output rows
  4903. N = text.length,
  4904. I = 0, // current character index
  4905. n = 0, // current line number
  4906. t, // current token
  4907. eof = N <= 0, // current token followed by EOF?
  4908. eol = false; // current token followed by EOL?
  4909. // Strip the trailing newline.
  4910. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4911. if (text.charCodeAt(N - 1) === RETURN) --N;
  4912. function token() {
  4913. if (eof) return EOF;
  4914. if (eol) return eol = false, EOL;
  4915. // Unescape quotes.
  4916. var i, j = I, c;
  4917. if (text.charCodeAt(j) === QUOTE) {
  4918. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4919. if ((i = I) >= N) eof = true;
  4920. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4921. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4922. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4923. }
  4924. // Find next delimiter or newline.
  4925. while (I < N) {
  4926. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4927. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4928. else if (c !== DELIMITER) continue;
  4929. return text.slice(j, i);
  4930. }
  4931. // Return last token before EOF.
  4932. return eof = true, text.slice(j, N);
  4933. }
  4934. while ((t = token()) !== EOF) {
  4935. var row = [];
  4936. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4937. if (f && (row = f(row, n++)) == null) continue;
  4938. rows.push(row);
  4939. }
  4940. return rows;
  4941. }
  4942. function format(rows, columns) {
  4943. if (columns == null) columns = inferColumns(rows);
  4944. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4945. return columns.map(function(column) {
  4946. return formatValue(row[column]);
  4947. }).join(delimiter);
  4948. })).join("\n");
  4949. }
  4950. function formatRows(rows) {
  4951. return rows.map(formatRow).join("\n");
  4952. }
  4953. function formatRow(row) {
  4954. return row.map(formatValue).join(delimiter);
  4955. }
  4956. function formatValue(text) {
  4957. return text == null ? ""
  4958. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4959. : text;
  4960. }
  4961. return {
  4962. parse: parse,
  4963. parseRows: parseRows,
  4964. format: format,
  4965. formatRows: formatRows
  4966. };
  4967. }
  4968. var csv = dsvFormat(",");
  4969. var csvParse = csv.parse;
  4970. var csvParseRows = csv.parseRows;
  4971. var csvFormat = csv.format;
  4972. var csvFormatRows = csv.formatRows;
  4973. var tsv = dsvFormat("\t");
  4974. var tsvParse = tsv.parse;
  4975. var tsvParseRows = tsv.parseRows;
  4976. var tsvFormat = tsv.format;
  4977. var tsvFormatRows = tsv.formatRows;
  4978. function responseBlob(response) {
  4979. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4980. return response.blob();
  4981. }
  4982. function blob(input, init) {
  4983. return fetch(input, init).then(responseBlob);
  4984. }
  4985. function responseArrayBuffer(response) {
  4986. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4987. return response.arrayBuffer();
  4988. }
  4989. function buffer(input, init) {
  4990. return fetch(input, init).then(responseArrayBuffer);
  4991. }
  4992. function responseText(response) {
  4993. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4994. return response.text();
  4995. }
  4996. function text(input, init) {
  4997. return fetch(input, init).then(responseText);
  4998. }
  4999. function dsvParse(parse) {
  5000. return function(input, init, row) {
  5001. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  5002. return text(input, init).then(function(response) {
  5003. return parse(response, row);
  5004. });
  5005. };
  5006. }
  5007. function dsv(delimiter, input, init, row) {
  5008. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  5009. var format = dsvFormat(delimiter);
  5010. return text(input, init).then(function(response) {
  5011. return format.parse(response, row);
  5012. });
  5013. }
  5014. var csv$1 = dsvParse(csvParse);
  5015. var tsv$1 = dsvParse(tsvParse);
  5016. function image(input, init) {
  5017. return new Promise(function(resolve, reject) {
  5018. var image = new Image;
  5019. for (var key in init) image[key] = init[key];
  5020. image.onerror = reject;
  5021. image.onload = function() { resolve(image); };
  5022. image.src = input;
  5023. });
  5024. }
  5025. function responseJson(response) {
  5026. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5027. return response.json();
  5028. }
  5029. function json(input, init) {
  5030. return fetch(input, init).then(responseJson);
  5031. }
  5032. function parser(type) {
  5033. return function(input, init) {
  5034. return text(input, init).then(function(text$$1) {
  5035. return (new DOMParser).parseFromString(text$$1, type);
  5036. });
  5037. };
  5038. }
  5039. var xml = parser("application/xml");
  5040. var html = parser("text/html");
  5041. var svg = parser("image/svg+xml");
  5042. function center$1(x, y) {
  5043. var nodes;
  5044. if (x == null) x = 0;
  5045. if (y == null) y = 0;
  5046. function force() {
  5047. var i,
  5048. n = nodes.length,
  5049. node,
  5050. sx = 0,
  5051. sy = 0;
  5052. for (i = 0; i < n; ++i) {
  5053. node = nodes[i], sx += node.x, sy += node.y;
  5054. }
  5055. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5056. node = nodes[i], node.x -= sx, node.y -= sy;
  5057. }
  5058. }
  5059. force.initialize = function(_) {
  5060. nodes = _;
  5061. };
  5062. force.x = function(_) {
  5063. return arguments.length ? (x = +_, force) : x;
  5064. };
  5065. force.y = function(_) {
  5066. return arguments.length ? (y = +_, force) : y;
  5067. };
  5068. return force;
  5069. }
  5070. function constant$7(x) {
  5071. return function() {
  5072. return x;
  5073. };
  5074. }
  5075. function jiggle() {
  5076. return (Math.random() - 0.5) * 1e-6;
  5077. }
  5078. function tree_add(d) {
  5079. var x = +this._x.call(null, d),
  5080. y = +this._y.call(null, d);
  5081. return add(this.cover(x, y), x, y, d);
  5082. }
  5083. function add(tree, x, y, d) {
  5084. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5085. var parent,
  5086. node = tree._root,
  5087. leaf = {data: d},
  5088. x0 = tree._x0,
  5089. y0 = tree._y0,
  5090. x1 = tree._x1,
  5091. y1 = tree._y1,
  5092. xm,
  5093. ym,
  5094. xp,
  5095. yp,
  5096. right,
  5097. bottom,
  5098. i,
  5099. j;
  5100. // If the tree is empty, initialize the root as a leaf.
  5101. if (!node) return tree._root = leaf, tree;
  5102. // Find the existing leaf for the new point, or add it.
  5103. while (node.length) {
  5104. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5105. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5106. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5107. }
  5108. // Is the new point is exactly coincident with the existing point?
  5109. xp = +tree._x.call(null, node.data);
  5110. yp = +tree._y.call(null, node.data);
  5111. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5112. // Otherwise, split the leaf node until the old and new point are separated.
  5113. do {
  5114. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5115. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5116. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5117. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5118. return parent[j] = node, parent[i] = leaf, tree;
  5119. }
  5120. function addAll(data) {
  5121. var d, i, n = data.length,
  5122. x,
  5123. y,
  5124. xz = new Array(n),
  5125. yz = new Array(n),
  5126. x0 = Infinity,
  5127. y0 = Infinity,
  5128. x1 = -Infinity,
  5129. y1 = -Infinity;
  5130. // Compute the points and their extent.
  5131. for (i = 0; i < n; ++i) {
  5132. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5133. xz[i] = x;
  5134. yz[i] = y;
  5135. if (x < x0) x0 = x;
  5136. if (x > x1) x1 = x;
  5137. if (y < y0) y0 = y;
  5138. if (y > y1) y1 = y;
  5139. }
  5140. // If there were no (valid) points, inherit the existing extent.
  5141. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  5142. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  5143. // Expand the tree to cover the new points.
  5144. this.cover(x0, y0).cover(x1, y1);
  5145. // Add the new points.
  5146. for (i = 0; i < n; ++i) {
  5147. add(this, xz[i], yz[i], data[i]);
  5148. }
  5149. return this;
  5150. }
  5151. function tree_cover(x, y) {
  5152. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5153. var x0 = this._x0,
  5154. y0 = this._y0,
  5155. x1 = this._x1,
  5156. y1 = this._y1;
  5157. // If the quadtree has no extent, initialize them.
  5158. // Integer extent are necessary so that if we later double the extent,
  5159. // the existing quadrant boundaries don’t change due to floating point error!
  5160. if (isNaN(x0)) {
  5161. x1 = (x0 = Math.floor(x)) + 1;
  5162. y1 = (y0 = Math.floor(y)) + 1;
  5163. }
  5164. // Otherwise, double repeatedly to cover.
  5165. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  5166. var z = x1 - x0,
  5167. node = this._root,
  5168. parent,
  5169. i;
  5170. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  5171. case 0: {
  5172. do parent = new Array(4), parent[i] = node, node = parent;
  5173. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  5174. break;
  5175. }
  5176. case 1: {
  5177. do parent = new Array(4), parent[i] = node, node = parent;
  5178. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  5179. break;
  5180. }
  5181. case 2: {
  5182. do parent = new Array(4), parent[i] = node, node = parent;
  5183. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  5184. break;
  5185. }
  5186. case 3: {
  5187. do parent = new Array(4), parent[i] = node, node = parent;
  5188. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  5189. break;
  5190. }
  5191. }
  5192. if (this._root && this._root.length) this._root = node;
  5193. }
  5194. // If the quadtree covers the point already, just return.
  5195. else return this;
  5196. this._x0 = x0;
  5197. this._y0 = y0;
  5198. this._x1 = x1;
  5199. this._y1 = y1;
  5200. return this;
  5201. }
  5202. function tree_data() {
  5203. var data = [];
  5204. this.visit(function(node) {
  5205. if (!node.length) do data.push(node.data); while (node = node.next)
  5206. });
  5207. return data;
  5208. }
  5209. function tree_extent(_) {
  5210. return arguments.length
  5211. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5212. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5213. }
  5214. function Quad(node, x0, y0, x1, y1) {
  5215. this.node = node;
  5216. this.x0 = x0;
  5217. this.y0 = y0;
  5218. this.x1 = x1;
  5219. this.y1 = y1;
  5220. }
  5221. function tree_find(x, y, radius) {
  5222. var data,
  5223. x0 = this._x0,
  5224. y0 = this._y0,
  5225. x1,
  5226. y1,
  5227. x2,
  5228. y2,
  5229. x3 = this._x1,
  5230. y3 = this._y1,
  5231. quads = [],
  5232. node = this._root,
  5233. q,
  5234. i;
  5235. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5236. if (radius == null) radius = Infinity;
  5237. else {
  5238. x0 = x - radius, y0 = y - radius;
  5239. x3 = x + radius, y3 = y + radius;
  5240. radius *= radius;
  5241. }
  5242. while (q = quads.pop()) {
  5243. // Stop searching if this quadrant can’t contain a closer node.
  5244. if (!(node = q.node)
  5245. || (x1 = q.x0) > x3
  5246. || (y1 = q.y0) > y3
  5247. || (x2 = q.x1) < x0
  5248. || (y2 = q.y1) < y0) continue;
  5249. // Bisect the current quadrant.
  5250. if (node.length) {
  5251. var xm = (x1 + x2) / 2,
  5252. ym = (y1 + y2) / 2;
  5253. quads.push(
  5254. new Quad(node[3], xm, ym, x2, y2),
  5255. new Quad(node[2], x1, ym, xm, y2),
  5256. new Quad(node[1], xm, y1, x2, ym),
  5257. new Quad(node[0], x1, y1, xm, ym)
  5258. );
  5259. // Visit the closest quadrant first.
  5260. if (i = (y >= ym) << 1 | (x >= xm)) {
  5261. q = quads[quads.length - 1];
  5262. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5263. quads[quads.length - 1 - i] = q;
  5264. }
  5265. }
  5266. // Visit this point. (Visiting coincident points isn’t necessary!)
  5267. else {
  5268. var dx = x - +this._x.call(null, node.data),
  5269. dy = y - +this._y.call(null, node.data),
  5270. d2 = dx * dx + dy * dy;
  5271. if (d2 < radius) {
  5272. var d = Math.sqrt(radius = d2);
  5273. x0 = x - d, y0 = y - d;
  5274. x3 = x + d, y3 = y + d;
  5275. data = node.data;
  5276. }
  5277. }
  5278. }
  5279. return data;
  5280. }
  5281. function tree_remove(d) {
  5282. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5283. var parent,
  5284. node = this._root,
  5285. retainer,
  5286. previous,
  5287. next,
  5288. x0 = this._x0,
  5289. y0 = this._y0,
  5290. x1 = this._x1,
  5291. y1 = this._y1,
  5292. x,
  5293. y,
  5294. xm,
  5295. ym,
  5296. right,
  5297. bottom,
  5298. i,
  5299. j;
  5300. // If the tree is empty, initialize the root as a leaf.
  5301. if (!node) return this;
  5302. // Find the leaf node for the point.
  5303. // While descending, also retain the deepest parent with a non-removed sibling.
  5304. if (node.length) while (true) {
  5305. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5306. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5307. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5308. if (!node.length) break;
  5309. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5310. }
  5311. // Find the point to remove.
  5312. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5313. if (next = node.next) delete node.next;
  5314. // If there are multiple coincident points, remove just the point.
  5315. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5316. // If this is the root point, remove it.
  5317. if (!parent) return this._root = next, this;
  5318. // Remove this leaf.
  5319. next ? parent[i] = next : delete parent[i];
  5320. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5321. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5322. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5323. && !node.length) {
  5324. if (retainer) retainer[j] = node;
  5325. else this._root = node;
  5326. }
  5327. return this;
  5328. }
  5329. function removeAll(data) {
  5330. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5331. return this;
  5332. }
  5333. function tree_root() {
  5334. return this._root;
  5335. }
  5336. function tree_size() {
  5337. var size = 0;
  5338. this.visit(function(node) {
  5339. if (!node.length) do ++size; while (node = node.next)
  5340. });
  5341. return size;
  5342. }
  5343. function tree_visit(callback) {
  5344. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5345. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5346. while (q = quads.pop()) {
  5347. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5348. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5349. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5350. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5351. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5352. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5353. }
  5354. }
  5355. return this;
  5356. }
  5357. function tree_visitAfter(callback) {
  5358. var quads = [], next = [], q;
  5359. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5360. while (q = quads.pop()) {
  5361. var node = q.node;
  5362. if (node.length) {
  5363. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5364. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5365. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5366. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5367. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5368. }
  5369. next.push(q);
  5370. }
  5371. while (q = next.pop()) {
  5372. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5373. }
  5374. return this;
  5375. }
  5376. function defaultX$1(d) {
  5377. return d[0];
  5378. }
  5379. function tree_x(_) {
  5380. return arguments.length ? (this._x = _, this) : this._x;
  5381. }
  5382. function defaultY$1(d) {
  5383. return d[1];
  5384. }
  5385. function tree_y(_) {
  5386. return arguments.length ? (this._y = _, this) : this._y;
  5387. }
  5388. function quadtree(nodes, x, y) {
  5389. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5390. return nodes == null ? tree : tree.addAll(nodes);
  5391. }
  5392. function Quadtree(x, y, x0, y0, x1, y1) {
  5393. this._x = x;
  5394. this._y = y;
  5395. this._x0 = x0;
  5396. this._y0 = y0;
  5397. this._x1 = x1;
  5398. this._y1 = y1;
  5399. this._root = undefined;
  5400. }
  5401. function leaf_copy(leaf) {
  5402. var copy = {data: leaf.data}, next = copy;
  5403. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5404. return copy;
  5405. }
  5406. var treeProto = quadtree.prototype = Quadtree.prototype;
  5407. treeProto.copy = function() {
  5408. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5409. node = this._root,
  5410. nodes,
  5411. child;
  5412. if (!node) return copy;
  5413. if (!node.length) return copy._root = leaf_copy(node), copy;
  5414. nodes = [{source: node, target: copy._root = new Array(4)}];
  5415. while (node = nodes.pop()) {
  5416. for (var i = 0; i < 4; ++i) {
  5417. if (child = node.source[i]) {
  5418. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5419. else node.target[i] = leaf_copy(child);
  5420. }
  5421. }
  5422. }
  5423. return copy;
  5424. };
  5425. treeProto.add = tree_add;
  5426. treeProto.addAll = addAll;
  5427. treeProto.cover = tree_cover;
  5428. treeProto.data = tree_data;
  5429. treeProto.extent = tree_extent;
  5430. treeProto.find = tree_find;
  5431. treeProto.remove = tree_remove;
  5432. treeProto.removeAll = removeAll;
  5433. treeProto.root = tree_root;
  5434. treeProto.size = tree_size;
  5435. treeProto.visit = tree_visit;
  5436. treeProto.visitAfter = tree_visitAfter;
  5437. treeProto.x = tree_x;
  5438. treeProto.y = tree_y;
  5439. function x(d) {
  5440. return d.x + d.vx;
  5441. }
  5442. function y(d) {
  5443. return d.y + d.vy;
  5444. }
  5445. function collide(radius) {
  5446. var nodes,
  5447. radii,
  5448. strength = 1,
  5449. iterations = 1;
  5450. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5451. function force() {
  5452. var i, n = nodes.length,
  5453. tree,
  5454. node,
  5455. xi,
  5456. yi,
  5457. ri,
  5458. ri2;
  5459. for (var k = 0; k < iterations; ++k) {
  5460. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5461. for (i = 0; i < n; ++i) {
  5462. node = nodes[i];
  5463. ri = radii[node.index], ri2 = ri * ri;
  5464. xi = node.x + node.vx;
  5465. yi = node.y + node.vy;
  5466. tree.visit(apply);
  5467. }
  5468. }
  5469. function apply(quad, x0, y0, x1, y1) {
  5470. var data = quad.data, rj = quad.r, r = ri + rj;
  5471. if (data) {
  5472. if (data.index > node.index) {
  5473. var x = xi - data.x - data.vx,
  5474. y = yi - data.y - data.vy,
  5475. l = x * x + y * y;
  5476. if (l < r * r) {
  5477. if (x === 0) x = jiggle(), l += x * x;
  5478. if (y === 0) y = jiggle(), l += y * y;
  5479. l = (r - (l = Math.sqrt(l))) / l * strength;
  5480. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5481. node.vy += (y *= l) * r;
  5482. data.vx -= x * (r = 1 - r);
  5483. data.vy -= y * r;
  5484. }
  5485. }
  5486. return;
  5487. }
  5488. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5489. }
  5490. }
  5491. function prepare(quad) {
  5492. if (quad.data) return quad.r = radii[quad.data.index];
  5493. for (var i = quad.r = 0; i < 4; ++i) {
  5494. if (quad[i] && quad[i].r > quad.r) {
  5495. quad.r = quad[i].r;
  5496. }
  5497. }
  5498. }
  5499. function initialize() {
  5500. if (!nodes) return;
  5501. var i, n = nodes.length, node;
  5502. radii = new Array(n);
  5503. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5504. }
  5505. force.initialize = function(_) {
  5506. nodes = _;
  5507. initialize();
  5508. };
  5509. force.iterations = function(_) {
  5510. return arguments.length ? (iterations = +_, force) : iterations;
  5511. };
  5512. force.strength = function(_) {
  5513. return arguments.length ? (strength = +_, force) : strength;
  5514. };
  5515. force.radius = function(_) {
  5516. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5517. };
  5518. return force;
  5519. }
  5520. function index(d) {
  5521. return d.index;
  5522. }
  5523. function find(nodeById, nodeId) {
  5524. var node = nodeById.get(nodeId);
  5525. if (!node) throw new Error("missing: " + nodeId);
  5526. return node;
  5527. }
  5528. function link(links) {
  5529. var id = index,
  5530. strength = defaultStrength,
  5531. strengths,
  5532. distance = constant$7(30),
  5533. distances,
  5534. nodes,
  5535. count,
  5536. bias,
  5537. iterations = 1;
  5538. if (links == null) links = [];
  5539. function defaultStrength(link) {
  5540. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5541. }
  5542. function force(alpha) {
  5543. for (var k = 0, n = links.length; k < iterations; ++k) {
  5544. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5545. link = links[i], source = link.source, target = link.target;
  5546. x = target.x + target.vx - source.x - source.vx || jiggle();
  5547. y = target.y + target.vy - source.y - source.vy || jiggle();
  5548. l = Math.sqrt(x * x + y * y);
  5549. l = (l - distances[i]) / l * alpha * strengths[i];
  5550. x *= l, y *= l;
  5551. target.vx -= x * (b = bias[i]);
  5552. target.vy -= y * b;
  5553. source.vx += x * (b = 1 - b);
  5554. source.vy += y * b;
  5555. }
  5556. }
  5557. }
  5558. function initialize() {
  5559. if (!nodes) return;
  5560. var i,
  5561. n = nodes.length,
  5562. m = links.length,
  5563. nodeById = map$1(nodes, id),
  5564. link;
  5565. for (i = 0, count = new Array(n); i < m; ++i) {
  5566. link = links[i], link.index = i;
  5567. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5568. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5569. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5570. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5571. }
  5572. for (i = 0, bias = new Array(m); i < m; ++i) {
  5573. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5574. }
  5575. strengths = new Array(m), initializeStrength();
  5576. distances = new Array(m), initializeDistance();
  5577. }
  5578. function initializeStrength() {
  5579. if (!nodes) return;
  5580. for (var i = 0, n = links.length; i < n; ++i) {
  5581. strengths[i] = +strength(links[i], i, links);
  5582. }
  5583. }
  5584. function initializeDistance() {
  5585. if (!nodes) return;
  5586. for (var i = 0, n = links.length; i < n; ++i) {
  5587. distances[i] = +distance(links[i], i, links);
  5588. }
  5589. }
  5590. force.initialize = function(_) {
  5591. nodes = _;
  5592. initialize();
  5593. };
  5594. force.links = function(_) {
  5595. return arguments.length ? (links = _, initialize(), force) : links;
  5596. };
  5597. force.id = function(_) {
  5598. return arguments.length ? (id = _, force) : id;
  5599. };
  5600. force.iterations = function(_) {
  5601. return arguments.length ? (iterations = +_, force) : iterations;
  5602. };
  5603. force.strength = function(_) {
  5604. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5605. };
  5606. force.distance = function(_) {
  5607. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5608. };
  5609. return force;
  5610. }
  5611. function x$1(d) {
  5612. return d.x;
  5613. }
  5614. function y$1(d) {
  5615. return d.y;
  5616. }
  5617. var initialRadius = 10,
  5618. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5619. function simulation(nodes) {
  5620. var simulation,
  5621. alpha = 1,
  5622. alphaMin = 0.001,
  5623. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5624. alphaTarget = 0,
  5625. velocityDecay = 0.6,
  5626. forces = map$1(),
  5627. stepper = timer(step),
  5628. event = dispatch("tick", "end");
  5629. if (nodes == null) nodes = [];
  5630. function step() {
  5631. tick();
  5632. event.call("tick", simulation);
  5633. if (alpha < alphaMin) {
  5634. stepper.stop();
  5635. event.call("end", simulation);
  5636. }
  5637. }
  5638. function tick() {
  5639. var i, n = nodes.length, node;
  5640. alpha += (alphaTarget - alpha) * alphaDecay;
  5641. forces.each(function(force) {
  5642. force(alpha);
  5643. });
  5644. for (i = 0; i < n; ++i) {
  5645. node = nodes[i];
  5646. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5647. else node.x = node.fx, node.vx = 0;
  5648. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5649. else node.y = node.fy, node.vy = 0;
  5650. }
  5651. }
  5652. function initializeNodes() {
  5653. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5654. node = nodes[i], node.index = i;
  5655. if (isNaN(node.x) || isNaN(node.y)) {
  5656. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5657. node.x = radius * Math.cos(angle);
  5658. node.y = radius * Math.sin(angle);
  5659. }
  5660. if (isNaN(node.vx) || isNaN(node.vy)) {
  5661. node.vx = node.vy = 0;
  5662. }
  5663. }
  5664. }
  5665. function initializeForce(force) {
  5666. if (force.initialize) force.initialize(nodes);
  5667. return force;
  5668. }
  5669. initializeNodes();
  5670. return simulation = {
  5671. tick: tick,
  5672. restart: function() {
  5673. return stepper.restart(step), simulation;
  5674. },
  5675. stop: function() {
  5676. return stepper.stop(), simulation;
  5677. },
  5678. nodes: function(_) {
  5679. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5680. },
  5681. alpha: function(_) {
  5682. return arguments.length ? (alpha = +_, simulation) : alpha;
  5683. },
  5684. alphaMin: function(_) {
  5685. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5686. },
  5687. alphaDecay: function(_) {
  5688. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5689. },
  5690. alphaTarget: function(_) {
  5691. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5692. },
  5693. velocityDecay: function(_) {
  5694. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5695. },
  5696. force: function(name, _) {
  5697. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5698. },
  5699. find: function(x, y, radius) {
  5700. var i = 0,
  5701. n = nodes.length,
  5702. dx,
  5703. dy,
  5704. d2,
  5705. node,
  5706. closest;
  5707. if (radius == null) radius = Infinity;
  5708. else radius *= radius;
  5709. for (i = 0; i < n; ++i) {
  5710. node = nodes[i];
  5711. dx = x - node.x;
  5712. dy = y - node.y;
  5713. d2 = dx * dx + dy * dy;
  5714. if (d2 < radius) closest = node, radius = d2;
  5715. }
  5716. return closest;
  5717. },
  5718. on: function(name, _) {
  5719. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5720. }
  5721. };
  5722. }
  5723. function manyBody() {
  5724. var nodes,
  5725. node,
  5726. alpha,
  5727. strength = constant$7(-30),
  5728. strengths,
  5729. distanceMin2 = 1,
  5730. distanceMax2 = Infinity,
  5731. theta2 = 0.81;
  5732. function force(_) {
  5733. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5734. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5735. }
  5736. function initialize() {
  5737. if (!nodes) return;
  5738. var i, n = nodes.length, node;
  5739. strengths = new Array(n);
  5740. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5741. }
  5742. function accumulate(quad) {
  5743. var strength = 0, q, c, weight = 0, x, y, i;
  5744. // For internal nodes, accumulate forces from child quadrants.
  5745. if (quad.length) {
  5746. for (x = y = i = 0; i < 4; ++i) {
  5747. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5748. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5749. }
  5750. }
  5751. quad.x = x / weight;
  5752. quad.y = y / weight;
  5753. }
  5754. // For leaf nodes, accumulate forces from coincident quadrants.
  5755. else {
  5756. q = quad;
  5757. q.x = q.data.x;
  5758. q.y = q.data.y;
  5759. do strength += strengths[q.data.index];
  5760. while (q = q.next);
  5761. }
  5762. quad.value = strength;
  5763. }
  5764. function apply(quad, x1, _, x2) {
  5765. if (!quad.value) return true;
  5766. var x = quad.x - node.x,
  5767. y = quad.y - node.y,
  5768. w = x2 - x1,
  5769. l = x * x + y * y;
  5770. // Apply the Barnes-Hut approximation if possible.
  5771. // Limit forces for very close nodes; randomize direction if coincident.
  5772. if (w * w / theta2 < l) {
  5773. if (l < distanceMax2) {
  5774. if (x === 0) x = jiggle(), l += x * x;
  5775. if (y === 0) y = jiggle(), l += y * y;
  5776. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5777. node.vx += x * quad.value * alpha / l;
  5778. node.vy += y * quad.value * alpha / l;
  5779. }
  5780. return true;
  5781. }
  5782. // Otherwise, process points directly.
  5783. else if (quad.length || l >= distanceMax2) return;
  5784. // Limit forces for very close nodes; randomize direction if coincident.
  5785. if (quad.data !== node || quad.next) {
  5786. if (x === 0) x = jiggle(), l += x * x;
  5787. if (y === 0) y = jiggle(), l += y * y;
  5788. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5789. }
  5790. do if (quad.data !== node) {
  5791. w = strengths[quad.data.index] * alpha / l;
  5792. node.vx += x * w;
  5793. node.vy += y * w;
  5794. } while (quad = quad.next);
  5795. }
  5796. force.initialize = function(_) {
  5797. nodes = _;
  5798. initialize();
  5799. };
  5800. force.strength = function(_) {
  5801. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5802. };
  5803. force.distanceMin = function(_) {
  5804. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5805. };
  5806. force.distanceMax = function(_) {
  5807. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5808. };
  5809. force.theta = function(_) {
  5810. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5811. };
  5812. return force;
  5813. }
  5814. function radial(radius, x, y) {
  5815. var nodes,
  5816. strength = constant$7(0.1),
  5817. strengths,
  5818. radiuses;
  5819. if (typeof radius !== "function") radius = constant$7(+radius);
  5820. if (x == null) x = 0;
  5821. if (y == null) y = 0;
  5822. function force(alpha) {
  5823. for (var i = 0, n = nodes.length; i < n; ++i) {
  5824. var node = nodes[i],
  5825. dx = node.x - x || 1e-6,
  5826. dy = node.y - y || 1e-6,
  5827. r = Math.sqrt(dx * dx + dy * dy),
  5828. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5829. node.vx += dx * k;
  5830. node.vy += dy * k;
  5831. }
  5832. }
  5833. function initialize() {
  5834. if (!nodes) return;
  5835. var i, n = nodes.length;
  5836. strengths = new Array(n);
  5837. radiuses = new Array(n);
  5838. for (i = 0; i < n; ++i) {
  5839. radiuses[i] = +radius(nodes[i], i, nodes);
  5840. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5841. }
  5842. }
  5843. force.initialize = function(_) {
  5844. nodes = _, initialize();
  5845. };
  5846. force.strength = function(_) {
  5847. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5848. };
  5849. force.radius = function(_) {
  5850. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5851. };
  5852. force.x = function(_) {
  5853. return arguments.length ? (x = +_, force) : x;
  5854. };
  5855. force.y = function(_) {
  5856. return arguments.length ? (y = +_, force) : y;
  5857. };
  5858. return force;
  5859. }
  5860. function x$2(x) {
  5861. var strength = constant$7(0.1),
  5862. nodes,
  5863. strengths,
  5864. xz;
  5865. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  5866. function force(alpha) {
  5867. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5868. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5869. }
  5870. }
  5871. function initialize() {
  5872. if (!nodes) return;
  5873. var i, n = nodes.length;
  5874. strengths = new Array(n);
  5875. xz = new Array(n);
  5876. for (i = 0; i < n; ++i) {
  5877. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5878. }
  5879. }
  5880. force.initialize = function(_) {
  5881. nodes = _;
  5882. initialize();
  5883. };
  5884. force.strength = function(_) {
  5885. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5886. };
  5887. force.x = function(_) {
  5888. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  5889. };
  5890. return force;
  5891. }
  5892. function y$2(y) {
  5893. var strength = constant$7(0.1),
  5894. nodes,
  5895. strengths,
  5896. yz;
  5897. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  5898. function force(alpha) {
  5899. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5900. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5901. }
  5902. }
  5903. function initialize() {
  5904. if (!nodes) return;
  5905. var i, n = nodes.length;
  5906. strengths = new Array(n);
  5907. yz = new Array(n);
  5908. for (i = 0; i < n; ++i) {
  5909. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5910. }
  5911. }
  5912. force.initialize = function(_) {
  5913. nodes = _;
  5914. initialize();
  5915. };
  5916. force.strength = function(_) {
  5917. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5918. };
  5919. force.y = function(_) {
  5920. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  5921. };
  5922. return force;
  5923. }
  5924. // Computes the decimal coefficient and exponent of the specified number x with
  5925. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5926. // For example, formatDecimal(1.23) returns ["123", 0].
  5927. function formatDecimal(x, p) {
  5928. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5929. var i, coefficient = x.slice(0, i);
  5930. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5931. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5932. return [
  5933. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5934. +x.slice(i + 1)
  5935. ];
  5936. }
  5937. function exponent$1(x) {
  5938. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5939. }
  5940. function formatGroup(grouping, thousands) {
  5941. return function(value, width) {
  5942. var i = value.length,
  5943. t = [],
  5944. j = 0,
  5945. g = grouping[0],
  5946. length = 0;
  5947. while (i > 0 && g > 0) {
  5948. if (length + g + 1 > width) g = Math.max(1, width - length);
  5949. t.push(value.substring(i -= g, i + g));
  5950. if ((length += g + 1) > width) break;
  5951. g = grouping[j = (j + 1) % grouping.length];
  5952. }
  5953. return t.reverse().join(thousands);
  5954. };
  5955. }
  5956. function formatNumerals(numerals) {
  5957. return function(value) {
  5958. return value.replace(/[0-9]/g, function(i) {
  5959. return numerals[+i];
  5960. });
  5961. };
  5962. }
  5963. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  5964. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  5965. function formatSpecifier(specifier) {
  5966. return new FormatSpecifier(specifier);
  5967. }
  5968. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5969. function FormatSpecifier(specifier) {
  5970. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5971. var match;
  5972. this.fill = match[1] || " ";
  5973. this.align = match[2] || ">";
  5974. this.sign = match[3] || "-";
  5975. this.symbol = match[4] || "";
  5976. this.zero = !!match[5];
  5977. this.width = match[6] && +match[6];
  5978. this.comma = !!match[7];
  5979. this.precision = match[8] && +match[8].slice(1);
  5980. this.trim = !!match[9];
  5981. this.type = match[10] || "";
  5982. }
  5983. FormatSpecifier.prototype.toString = function() {
  5984. return this.fill
  5985. + this.align
  5986. + this.sign
  5987. + this.symbol
  5988. + (this.zero ? "0" : "")
  5989. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5990. + (this.comma ? "," : "")
  5991. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5992. + (this.trim ? "~" : "")
  5993. + this.type;
  5994. };
  5995. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  5996. function formatTrim(s) {
  5997. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5998. switch (s[i]) {
  5999. case ".": i0 = i1 = i; break;
  6000. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  6001. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  6002. }
  6003. }
  6004. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  6005. }
  6006. var prefixExponent;
  6007. function formatPrefixAuto(x, p) {
  6008. var d = formatDecimal(x, p);
  6009. if (!d) return x + "";
  6010. var coefficient = d[0],
  6011. exponent = d[1],
  6012. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6013. n = coefficient.length;
  6014. return i === n ? coefficient
  6015. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6016. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6017. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6018. }
  6019. function formatRounded(x, p) {
  6020. var d = formatDecimal(x, p);
  6021. if (!d) return x + "";
  6022. var coefficient = d[0],
  6023. exponent = d[1];
  6024. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6025. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6026. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6027. }
  6028. var formatTypes = {
  6029. "%": function(x, p) { return (x * 100).toFixed(p); },
  6030. "b": function(x) { return Math.round(x).toString(2); },
  6031. "c": function(x) { return x + ""; },
  6032. "d": function(x) { return Math.round(x).toString(10); },
  6033. "e": function(x, p) { return x.toExponential(p); },
  6034. "f": function(x, p) { return x.toFixed(p); },
  6035. "g": function(x, p) { return x.toPrecision(p); },
  6036. "o": function(x) { return Math.round(x).toString(8); },
  6037. "p": function(x, p) { return formatRounded(x * 100, p); },
  6038. "r": formatRounded,
  6039. "s": formatPrefixAuto,
  6040. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6041. "x": function(x) { return Math.round(x).toString(16); }
  6042. };
  6043. function identity$3(x) {
  6044. return x;
  6045. }
  6046. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6047. function formatLocale(locale) {
  6048. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  6049. currency = locale.currency,
  6050. decimal = locale.decimal,
  6051. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  6052. percent = locale.percent || "%";
  6053. function newFormat(specifier) {
  6054. specifier = formatSpecifier(specifier);
  6055. var fill = specifier.fill,
  6056. align = specifier.align,
  6057. sign = specifier.sign,
  6058. symbol = specifier.symbol,
  6059. zero = specifier.zero,
  6060. width = specifier.width,
  6061. comma = specifier.comma,
  6062. precision = specifier.precision,
  6063. trim = specifier.trim,
  6064. type = specifier.type;
  6065. // The "n" type is an alias for ",g".
  6066. if (type === "n") comma = true, type = "g";
  6067. // The "" type, and any invalid type, is an alias for ".12~g".
  6068. else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
  6069. // If zero fill is specified, padding goes after sign and before digits.
  6070. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6071. // Compute the prefix and suffix.
  6072. // For SI-prefix, the suffix is lazily computed.
  6073. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6074. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  6075. // What format function should we use?
  6076. // Is this an integer type?
  6077. // Can this type generate exponential notation?
  6078. var formatType = formatTypes[type],
  6079. maybeSuffix = /[defgprs%]/.test(type);
  6080. // Set the default precision if not specified,
  6081. // or clamp the specified precision to the supported range.
  6082. // For significant precision, it must be in [1, 21].
  6083. // For fixed precision, it must be in [0, 20].
  6084. precision = precision == null ? 6
  6085. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6086. : Math.max(0, Math.min(20, precision));
  6087. function format(value) {
  6088. var valuePrefix = prefix,
  6089. valueSuffix = suffix,
  6090. i, n, c;
  6091. if (type === "c") {
  6092. valueSuffix = formatType(value) + valueSuffix;
  6093. value = "";
  6094. } else {
  6095. value = +value;
  6096. // Perform the initial formatting.
  6097. var valueNegative = value < 0;
  6098. value = formatType(Math.abs(value), precision);
  6099. // Trim insignificant zeros.
  6100. if (trim) value = formatTrim(value);
  6101. // If a negative value rounds to zero during formatting, treat as positive.
  6102. if (valueNegative && +value === 0) valueNegative = false;
  6103. // Compute the prefix and suffix.
  6104. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6105. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6106. // Break the formatted value into the integer “value” part that can be
  6107. // grouped, and fractional or exponential “suffix” part that is not.
  6108. if (maybeSuffix) {
  6109. i = -1, n = value.length;
  6110. while (++i < n) {
  6111. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6112. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6113. value = value.slice(0, i);
  6114. break;
  6115. }
  6116. }
  6117. }
  6118. }
  6119. // If the fill character is not "0", grouping is applied before padding.
  6120. if (comma && !zero) value = group(value, Infinity);
  6121. // Compute the padding.
  6122. var length = valuePrefix.length + value.length + valueSuffix.length,
  6123. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6124. // If the fill character is "0", grouping is applied after padding.
  6125. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6126. // Reconstruct the final output based on the desired alignment.
  6127. switch (align) {
  6128. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6129. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6130. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6131. default: value = padding + valuePrefix + value + valueSuffix; break;
  6132. }
  6133. return numerals(value);
  6134. }
  6135. format.toString = function() {
  6136. return specifier + "";
  6137. };
  6138. return format;
  6139. }
  6140. function formatPrefix(specifier, value) {
  6141. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6142. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6143. k = Math.pow(10, -e),
  6144. prefix = prefixes[8 + e / 3];
  6145. return function(value) {
  6146. return f(k * value) + prefix;
  6147. };
  6148. }
  6149. return {
  6150. format: newFormat,
  6151. formatPrefix: formatPrefix
  6152. };
  6153. }
  6154. var locale;
  6155. defaultLocale({
  6156. decimal: ".",
  6157. thousands: ",",
  6158. grouping: [3],
  6159. currency: ["$", ""]
  6160. });
  6161. function defaultLocale(definition) {
  6162. locale = formatLocale(definition);
  6163. exports.format = locale.format;
  6164. exports.formatPrefix = locale.formatPrefix;
  6165. return locale;
  6166. }
  6167. function precisionFixed(step) {
  6168. return Math.max(0, -exponent$1(Math.abs(step)));
  6169. }
  6170. function precisionPrefix(step, value) {
  6171. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6172. }
  6173. function precisionRound(step, max) {
  6174. step = Math.abs(step), max = Math.abs(max) - step;
  6175. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6176. }
  6177. // Adds floating point numbers with twice the normal precision.
  6178. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6179. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6180. // 305–363 (1997).
  6181. // Code adapted from GeographicLib by Charles F. F. Karney,
  6182. // http://geographiclib.sourceforge.net/
  6183. function adder() {
  6184. return new Adder;
  6185. }
  6186. function Adder() {
  6187. this.reset();
  6188. }
  6189. Adder.prototype = {
  6190. constructor: Adder,
  6191. reset: function() {
  6192. this.s = // rounded value
  6193. this.t = 0; // exact error
  6194. },
  6195. add: function(y) {
  6196. add$1(temp, y, this.t);
  6197. add$1(this, temp.s, this.s);
  6198. if (this.s) this.t += temp.t;
  6199. else this.s = temp.t;
  6200. },
  6201. valueOf: function() {
  6202. return this.s;
  6203. }
  6204. };
  6205. var temp = new Adder;
  6206. function add$1(adder, a, b) {
  6207. var x = adder.s = a + b,
  6208. bv = x - a,
  6209. av = x - bv;
  6210. adder.t = (a - av) + (b - bv);
  6211. }
  6212. var epsilon$2 = 1e-6;
  6213. var epsilon2$1 = 1e-12;
  6214. var pi$3 = Math.PI;
  6215. var halfPi$2 = pi$3 / 2;
  6216. var quarterPi = pi$3 / 4;
  6217. var tau$3 = pi$3 * 2;
  6218. var degrees$1 = 180 / pi$3;
  6219. var radians = pi$3 / 180;
  6220. var abs = Math.abs;
  6221. var atan = Math.atan;
  6222. var atan2 = Math.atan2;
  6223. var cos$1 = Math.cos;
  6224. var ceil = Math.ceil;
  6225. var exp = Math.exp;
  6226. var log = Math.log;
  6227. var pow = Math.pow;
  6228. var sin$1 = Math.sin;
  6229. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6230. var sqrt = Math.sqrt;
  6231. var tan = Math.tan;
  6232. function acos(x) {
  6233. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6234. }
  6235. function asin(x) {
  6236. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6237. }
  6238. function haversin(x) {
  6239. return (x = sin$1(x / 2)) * x;
  6240. }
  6241. function noop$2() {}
  6242. function streamGeometry(geometry, stream) {
  6243. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6244. streamGeometryType[geometry.type](geometry, stream);
  6245. }
  6246. }
  6247. var streamObjectType = {
  6248. Feature: function(object, stream) {
  6249. streamGeometry(object.geometry, stream);
  6250. },
  6251. FeatureCollection: function(object, stream) {
  6252. var features = object.features, i = -1, n = features.length;
  6253. while (++i < n) streamGeometry(features[i].geometry, stream);
  6254. }
  6255. };
  6256. var streamGeometryType = {
  6257. Sphere: function(object, stream) {
  6258. stream.sphere();
  6259. },
  6260. Point: function(object, stream) {
  6261. object = object.coordinates;
  6262. stream.point(object[0], object[1], object[2]);
  6263. },
  6264. MultiPoint: function(object, stream) {
  6265. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6266. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6267. },
  6268. LineString: function(object, stream) {
  6269. streamLine(object.coordinates, stream, 0);
  6270. },
  6271. MultiLineString: function(object, stream) {
  6272. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6273. while (++i < n) streamLine(coordinates[i], stream, 0);
  6274. },
  6275. Polygon: function(object, stream) {
  6276. streamPolygon(object.coordinates, stream);
  6277. },
  6278. MultiPolygon: function(object, stream) {
  6279. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6280. while (++i < n) streamPolygon(coordinates[i], stream);
  6281. },
  6282. GeometryCollection: function(object, stream) {
  6283. var geometries = object.geometries, i = -1, n = geometries.length;
  6284. while (++i < n) streamGeometry(geometries[i], stream);
  6285. }
  6286. };
  6287. function streamLine(coordinates, stream, closed) {
  6288. var i = -1, n = coordinates.length - closed, coordinate;
  6289. stream.lineStart();
  6290. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6291. stream.lineEnd();
  6292. }
  6293. function streamPolygon(coordinates, stream) {
  6294. var i = -1, n = coordinates.length;
  6295. stream.polygonStart();
  6296. while (++i < n) streamLine(coordinates[i], stream, 1);
  6297. stream.polygonEnd();
  6298. }
  6299. function geoStream(object, stream) {
  6300. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6301. streamObjectType[object.type](object, stream);
  6302. } else {
  6303. streamGeometry(object, stream);
  6304. }
  6305. }
  6306. var areaRingSum = adder();
  6307. var areaSum = adder(),
  6308. lambda00,
  6309. phi00,
  6310. lambda0,
  6311. cosPhi0,
  6312. sinPhi0;
  6313. var areaStream = {
  6314. point: noop$2,
  6315. lineStart: noop$2,
  6316. lineEnd: noop$2,
  6317. polygonStart: function() {
  6318. areaRingSum.reset();
  6319. areaStream.lineStart = areaRingStart;
  6320. areaStream.lineEnd = areaRingEnd;
  6321. },
  6322. polygonEnd: function() {
  6323. var areaRing = +areaRingSum;
  6324. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6325. this.lineStart = this.lineEnd = this.point = noop$2;
  6326. },
  6327. sphere: function() {
  6328. areaSum.add(tau$3);
  6329. }
  6330. };
  6331. function areaRingStart() {
  6332. areaStream.point = areaPointFirst;
  6333. }
  6334. function areaRingEnd() {
  6335. areaPoint(lambda00, phi00);
  6336. }
  6337. function areaPointFirst(lambda, phi) {
  6338. areaStream.point = areaPoint;
  6339. lambda00 = lambda, phi00 = phi;
  6340. lambda *= radians, phi *= radians;
  6341. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6342. }
  6343. function areaPoint(lambda, phi) {
  6344. lambda *= radians, phi *= radians;
  6345. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6346. // Spherical excess E for a spherical triangle with vertices: south pole,
  6347. // previous point, current point. Uses a formula derived from Cagnoli’s
  6348. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6349. var dLambda = lambda - lambda0,
  6350. sdLambda = dLambda >= 0 ? 1 : -1,
  6351. adLambda = sdLambda * dLambda,
  6352. cosPhi = cos$1(phi),
  6353. sinPhi = sin$1(phi),
  6354. k = sinPhi0 * sinPhi,
  6355. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6356. v = k * sdLambda * sin$1(adLambda);
  6357. areaRingSum.add(atan2(v, u));
  6358. // Advance the previous points.
  6359. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6360. }
  6361. function area$1(object) {
  6362. areaSum.reset();
  6363. geoStream(object, areaStream);
  6364. return areaSum * 2;
  6365. }
  6366. function spherical(cartesian) {
  6367. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6368. }
  6369. function cartesian(spherical) {
  6370. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6371. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6372. }
  6373. function cartesianDot(a, b) {
  6374. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6375. }
  6376. function cartesianCross(a, b) {
  6377. 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]];
  6378. }
  6379. // TODO return a
  6380. function cartesianAddInPlace(a, b) {
  6381. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6382. }
  6383. function cartesianScale(vector, k) {
  6384. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6385. }
  6386. // TODO return d
  6387. function cartesianNormalizeInPlace(d) {
  6388. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6389. d[0] /= l, d[1] /= l, d[2] /= l;
  6390. }
  6391. var lambda0$1, phi0, lambda1, phi1, // bounds
  6392. lambda2, // previous lambda-coordinate
  6393. lambda00$1, phi00$1, // first point
  6394. p0, // previous 3D point
  6395. deltaSum = adder(),
  6396. ranges,
  6397. range;
  6398. var boundsStream = {
  6399. point: boundsPoint,
  6400. lineStart: boundsLineStart,
  6401. lineEnd: boundsLineEnd,
  6402. polygonStart: function() {
  6403. boundsStream.point = boundsRingPoint;
  6404. boundsStream.lineStart = boundsRingStart;
  6405. boundsStream.lineEnd = boundsRingEnd;
  6406. deltaSum.reset();
  6407. areaStream.polygonStart();
  6408. },
  6409. polygonEnd: function() {
  6410. areaStream.polygonEnd();
  6411. boundsStream.point = boundsPoint;
  6412. boundsStream.lineStart = boundsLineStart;
  6413. boundsStream.lineEnd = boundsLineEnd;
  6414. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6415. else if (deltaSum > epsilon$2) phi1 = 90;
  6416. else if (deltaSum < -epsilon$2) phi0 = -90;
  6417. range[0] = lambda0$1, range[1] = lambda1;
  6418. }
  6419. };
  6420. function boundsPoint(lambda, phi) {
  6421. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6422. if (phi < phi0) phi0 = phi;
  6423. if (phi > phi1) phi1 = phi;
  6424. }
  6425. function linePoint(lambda, phi) {
  6426. var p = cartesian([lambda * radians, phi * radians]);
  6427. if (p0) {
  6428. var normal = cartesianCross(p0, p),
  6429. equatorial = [normal[1], -normal[0], 0],
  6430. inflection = cartesianCross(equatorial, normal);
  6431. cartesianNormalizeInPlace(inflection);
  6432. inflection = spherical(inflection);
  6433. var delta = lambda - lambda2,
  6434. sign$$1 = delta > 0 ? 1 : -1,
  6435. lambdai = inflection[0] * degrees$1 * sign$$1,
  6436. phii,
  6437. antimeridian = abs(delta) > 180;
  6438. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6439. phii = inflection[1] * degrees$1;
  6440. if (phii > phi1) phi1 = phii;
  6441. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6442. phii = -inflection[1] * degrees$1;
  6443. if (phii < phi0) phi0 = phii;
  6444. } else {
  6445. if (phi < phi0) phi0 = phi;
  6446. if (phi > phi1) phi1 = phi;
  6447. }
  6448. if (antimeridian) {
  6449. if (lambda < lambda2) {
  6450. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6451. } else {
  6452. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6453. }
  6454. } else {
  6455. if (lambda1 >= lambda0$1) {
  6456. if (lambda < lambda0$1) lambda0$1 = lambda;
  6457. if (lambda > lambda1) lambda1 = lambda;
  6458. } else {
  6459. if (lambda > lambda2) {
  6460. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6461. } else {
  6462. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6463. }
  6464. }
  6465. }
  6466. } else {
  6467. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6468. }
  6469. if (phi < phi0) phi0 = phi;
  6470. if (phi > phi1) phi1 = phi;
  6471. p0 = p, lambda2 = lambda;
  6472. }
  6473. function boundsLineStart() {
  6474. boundsStream.point = linePoint;
  6475. }
  6476. function boundsLineEnd() {
  6477. range[0] = lambda0$1, range[1] = lambda1;
  6478. boundsStream.point = boundsPoint;
  6479. p0 = null;
  6480. }
  6481. function boundsRingPoint(lambda, phi) {
  6482. if (p0) {
  6483. var delta = lambda - lambda2;
  6484. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6485. } else {
  6486. lambda00$1 = lambda, phi00$1 = phi;
  6487. }
  6488. areaStream.point(lambda, phi);
  6489. linePoint(lambda, phi);
  6490. }
  6491. function boundsRingStart() {
  6492. areaStream.lineStart();
  6493. }
  6494. function boundsRingEnd() {
  6495. boundsRingPoint(lambda00$1, phi00$1);
  6496. areaStream.lineEnd();
  6497. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6498. range[0] = lambda0$1, range[1] = lambda1;
  6499. p0 = null;
  6500. }
  6501. // Finds the left-right distance between two longitudes.
  6502. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6503. // the distance between ±180° to be 360°.
  6504. function angle(lambda0, lambda1) {
  6505. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6506. }
  6507. function rangeCompare(a, b) {
  6508. return a[0] - b[0];
  6509. }
  6510. function rangeContains(range, x) {
  6511. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6512. }
  6513. function bounds(feature) {
  6514. var i, n, a, b, merged, deltaMax, delta;
  6515. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6516. ranges = [];
  6517. geoStream(feature, boundsStream);
  6518. // First, sort ranges by their minimum longitudes.
  6519. if (n = ranges.length) {
  6520. ranges.sort(rangeCompare);
  6521. // Then, merge any ranges that overlap.
  6522. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6523. b = ranges[i];
  6524. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6525. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6526. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6527. } else {
  6528. merged.push(a = b);
  6529. }
  6530. }
  6531. // Finally, find the largest gap between the merged ranges.
  6532. // The final bounding box will be the inverse of this gap.
  6533. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6534. b = merged[i];
  6535. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6536. }
  6537. }
  6538. ranges = range = null;
  6539. return lambda0$1 === Infinity || phi0 === Infinity
  6540. ? [[NaN, NaN], [NaN, NaN]]
  6541. : [[lambda0$1, phi0], [lambda1, phi1]];
  6542. }
  6543. var W0, W1,
  6544. X0, Y0, Z0,
  6545. X1, Y1, Z1,
  6546. X2, Y2, Z2,
  6547. lambda00$2, phi00$2, // first point
  6548. x0, y0, z0; // previous point
  6549. var centroidStream = {
  6550. sphere: noop$2,
  6551. point: centroidPoint,
  6552. lineStart: centroidLineStart,
  6553. lineEnd: centroidLineEnd,
  6554. polygonStart: function() {
  6555. centroidStream.lineStart = centroidRingStart;
  6556. centroidStream.lineEnd = centroidRingEnd;
  6557. },
  6558. polygonEnd: function() {
  6559. centroidStream.lineStart = centroidLineStart;
  6560. centroidStream.lineEnd = centroidLineEnd;
  6561. }
  6562. };
  6563. // Arithmetic mean of Cartesian vectors.
  6564. function centroidPoint(lambda, phi) {
  6565. lambda *= radians, phi *= radians;
  6566. var cosPhi = cos$1(phi);
  6567. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6568. }
  6569. function centroidPointCartesian(x, y, z) {
  6570. ++W0;
  6571. X0 += (x - X0) / W0;
  6572. Y0 += (y - Y0) / W0;
  6573. Z0 += (z - Z0) / W0;
  6574. }
  6575. function centroidLineStart() {
  6576. centroidStream.point = centroidLinePointFirst;
  6577. }
  6578. function centroidLinePointFirst(lambda, phi) {
  6579. lambda *= radians, phi *= radians;
  6580. var cosPhi = cos$1(phi);
  6581. x0 = cosPhi * cos$1(lambda);
  6582. y0 = cosPhi * sin$1(lambda);
  6583. z0 = sin$1(phi);
  6584. centroidStream.point = centroidLinePoint;
  6585. centroidPointCartesian(x0, y0, z0);
  6586. }
  6587. function centroidLinePoint(lambda, phi) {
  6588. lambda *= radians, phi *= radians;
  6589. var cosPhi = cos$1(phi),
  6590. x = cosPhi * cos$1(lambda),
  6591. y = cosPhi * sin$1(lambda),
  6592. z = sin$1(phi),
  6593. w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  6594. W1 += w;
  6595. X1 += w * (x0 + (x0 = x));
  6596. Y1 += w * (y0 + (y0 = y));
  6597. Z1 += w * (z0 + (z0 = z));
  6598. centroidPointCartesian(x0, y0, z0);
  6599. }
  6600. function centroidLineEnd() {
  6601. centroidStream.point = centroidPoint;
  6602. }
  6603. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6604. // J. Applied Mechanics 42, 239 (1975).
  6605. function centroidRingStart() {
  6606. centroidStream.point = centroidRingPointFirst;
  6607. }
  6608. function centroidRingEnd() {
  6609. centroidRingPoint(lambda00$2, phi00$2);
  6610. centroidStream.point = centroidPoint;
  6611. }
  6612. function centroidRingPointFirst(lambda, phi) {
  6613. lambda00$2 = lambda, phi00$2 = phi;
  6614. lambda *= radians, phi *= radians;
  6615. centroidStream.point = centroidRingPoint;
  6616. var cosPhi = cos$1(phi);
  6617. x0 = cosPhi * cos$1(lambda);
  6618. y0 = cosPhi * sin$1(lambda);
  6619. z0 = sin$1(phi);
  6620. centroidPointCartesian(x0, y0, z0);
  6621. }
  6622. function centroidRingPoint(lambda, phi) {
  6623. lambda *= radians, phi *= radians;
  6624. var cosPhi = cos$1(phi),
  6625. x = cosPhi * cos$1(lambda),
  6626. y = cosPhi * sin$1(lambda),
  6627. z = sin$1(phi),
  6628. cx = y0 * z - z0 * y,
  6629. cy = z0 * x - x0 * z,
  6630. cz = x0 * y - y0 * x,
  6631. m = sqrt(cx * cx + cy * cy + cz * cz),
  6632. w = asin(m), // line weight = angle
  6633. v = m && -w / m; // area weight multiplier
  6634. X2 += v * cx;
  6635. Y2 += v * cy;
  6636. Z2 += v * cz;
  6637. W1 += w;
  6638. X1 += w * (x0 + (x0 = x));
  6639. Y1 += w * (y0 + (y0 = y));
  6640. Z1 += w * (z0 + (z0 = z));
  6641. centroidPointCartesian(x0, y0, z0);
  6642. }
  6643. function centroid(object) {
  6644. W0 = W1 =
  6645. X0 = Y0 = Z0 =
  6646. X1 = Y1 = Z1 =
  6647. X2 = Y2 = Z2 = 0;
  6648. geoStream(object, centroidStream);
  6649. var x = X2,
  6650. y = Y2,
  6651. z = Z2,
  6652. m = x * x + y * y + z * z;
  6653. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6654. if (m < epsilon2$1) {
  6655. x = X1, y = Y1, z = Z1;
  6656. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6657. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6658. m = x * x + y * y + z * z;
  6659. // If the feature still has an undefined ccentroid, then return.
  6660. if (m < epsilon2$1) return [NaN, NaN];
  6661. }
  6662. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6663. }
  6664. function constant$8(x) {
  6665. return function() {
  6666. return x;
  6667. };
  6668. }
  6669. function compose(a, b) {
  6670. function compose(x, y) {
  6671. return x = a(x, y), b(x[0], x[1]);
  6672. }
  6673. if (a.invert && b.invert) compose.invert = function(x, y) {
  6674. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6675. };
  6676. return compose;
  6677. }
  6678. function rotationIdentity(lambda, phi) {
  6679. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6680. }
  6681. rotationIdentity.invert = rotationIdentity;
  6682. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6683. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6684. : rotationLambda(deltaLambda))
  6685. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6686. : rotationIdentity);
  6687. }
  6688. function forwardRotationLambda(deltaLambda) {
  6689. return function(lambda, phi) {
  6690. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6691. };
  6692. }
  6693. function rotationLambda(deltaLambda) {
  6694. var rotation = forwardRotationLambda(deltaLambda);
  6695. rotation.invert = forwardRotationLambda(-deltaLambda);
  6696. return rotation;
  6697. }
  6698. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6699. var cosDeltaPhi = cos$1(deltaPhi),
  6700. sinDeltaPhi = sin$1(deltaPhi),
  6701. cosDeltaGamma = cos$1(deltaGamma),
  6702. sinDeltaGamma = sin$1(deltaGamma);
  6703. function rotation(lambda, phi) {
  6704. var cosPhi = cos$1(phi),
  6705. x = cos$1(lambda) * cosPhi,
  6706. y = sin$1(lambda) * cosPhi,
  6707. z = sin$1(phi),
  6708. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6709. return [
  6710. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6711. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6712. ];
  6713. }
  6714. rotation.invert = function(lambda, phi) {
  6715. var cosPhi = cos$1(phi),
  6716. x = cos$1(lambda) * cosPhi,
  6717. y = sin$1(lambda) * cosPhi,
  6718. z = sin$1(phi),
  6719. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6720. return [
  6721. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6722. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6723. ];
  6724. };
  6725. return rotation;
  6726. }
  6727. function rotation(rotate) {
  6728. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6729. function forward(coordinates) {
  6730. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6731. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6732. }
  6733. forward.invert = function(coordinates) {
  6734. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6735. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6736. };
  6737. return forward;
  6738. }
  6739. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6740. function circleStream(stream, radius, delta, direction, t0, t1) {
  6741. if (!delta) return;
  6742. var cosRadius = cos$1(radius),
  6743. sinRadius = sin$1(radius),
  6744. step = direction * delta;
  6745. if (t0 == null) {
  6746. t0 = radius + direction * tau$3;
  6747. t1 = radius - step / 2;
  6748. } else {
  6749. t0 = circleRadius(cosRadius, t0);
  6750. t1 = circleRadius(cosRadius, t1);
  6751. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6752. }
  6753. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6754. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6755. stream.point(point[0], point[1]);
  6756. }
  6757. }
  6758. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6759. function circleRadius(cosRadius, point) {
  6760. point = cartesian(point), point[0] -= cosRadius;
  6761. cartesianNormalizeInPlace(point);
  6762. var radius = acos(-point[1]);
  6763. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6764. }
  6765. function circle() {
  6766. var center = constant$8([0, 0]),
  6767. radius = constant$8(90),
  6768. precision = constant$8(6),
  6769. ring,
  6770. rotate,
  6771. stream = {point: point};
  6772. function point(x, y) {
  6773. ring.push(x = rotate(x, y));
  6774. x[0] *= degrees$1, x[1] *= degrees$1;
  6775. }
  6776. function circle() {
  6777. var c = center.apply(this, arguments),
  6778. r = radius.apply(this, arguments) * radians,
  6779. p = precision.apply(this, arguments) * radians;
  6780. ring = [];
  6781. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6782. circleStream(stream, r, p, 1);
  6783. c = {type: "Polygon", coordinates: [ring]};
  6784. ring = rotate = null;
  6785. return c;
  6786. }
  6787. circle.center = function(_) {
  6788. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6789. };
  6790. circle.radius = function(_) {
  6791. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6792. };
  6793. circle.precision = function(_) {
  6794. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6795. };
  6796. return circle;
  6797. }
  6798. function clipBuffer() {
  6799. var lines = [],
  6800. line;
  6801. return {
  6802. point: function(x, y) {
  6803. line.push([x, y]);
  6804. },
  6805. lineStart: function() {
  6806. lines.push(line = []);
  6807. },
  6808. lineEnd: noop$2,
  6809. rejoin: function() {
  6810. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6811. },
  6812. result: function() {
  6813. var result = lines;
  6814. lines = [];
  6815. line = null;
  6816. return result;
  6817. }
  6818. };
  6819. }
  6820. function pointEqual(a, b) {
  6821. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6822. }
  6823. function Intersection(point, points, other, entry) {
  6824. this.x = point;
  6825. this.z = points;
  6826. this.o = other; // another intersection
  6827. this.e = entry; // is an entry?
  6828. this.v = false; // visited
  6829. this.n = this.p = null; // next & previous
  6830. }
  6831. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6832. // into its visible line segments, and rejoins the segments by interpolating
  6833. // along the clip edge.
  6834. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6835. var subject = [],
  6836. clip = [],
  6837. i,
  6838. n;
  6839. segments.forEach(function(segment) {
  6840. if ((n = segment.length - 1) <= 0) return;
  6841. var n, p0 = segment[0], p1 = segment[n], x;
  6842. // If the first and last points of a segment are coincident, then treat as a
  6843. // closed ring. TODO if all rings are closed, then the winding order of the
  6844. // exterior ring should be checked.
  6845. if (pointEqual(p0, p1)) {
  6846. stream.lineStart();
  6847. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6848. stream.lineEnd();
  6849. return;
  6850. }
  6851. subject.push(x = new Intersection(p0, segment, null, true));
  6852. clip.push(x.o = new Intersection(p0, null, x, false));
  6853. subject.push(x = new Intersection(p1, segment, null, false));
  6854. clip.push(x.o = new Intersection(p1, null, x, true));
  6855. });
  6856. if (!subject.length) return;
  6857. clip.sort(compareIntersection);
  6858. link$1(subject);
  6859. link$1(clip);
  6860. for (i = 0, n = clip.length; i < n; ++i) {
  6861. clip[i].e = startInside = !startInside;
  6862. }
  6863. var start = subject[0],
  6864. points,
  6865. point;
  6866. while (1) {
  6867. // Find first unvisited intersection.
  6868. var current = start,
  6869. isSubject = true;
  6870. while (current.v) if ((current = current.n) === start) return;
  6871. points = current.z;
  6872. stream.lineStart();
  6873. do {
  6874. current.v = current.o.v = true;
  6875. if (current.e) {
  6876. if (isSubject) {
  6877. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6878. } else {
  6879. interpolate(current.x, current.n.x, 1, stream);
  6880. }
  6881. current = current.n;
  6882. } else {
  6883. if (isSubject) {
  6884. points = current.p.z;
  6885. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6886. } else {
  6887. interpolate(current.x, current.p.x, -1, stream);
  6888. }
  6889. current = current.p;
  6890. }
  6891. current = current.o;
  6892. points = current.z;
  6893. isSubject = !isSubject;
  6894. } while (!current.v);
  6895. stream.lineEnd();
  6896. }
  6897. }
  6898. function link$1(array) {
  6899. if (!(n = array.length)) return;
  6900. var n,
  6901. i = 0,
  6902. a = array[0],
  6903. b;
  6904. while (++i < n) {
  6905. a.n = b = array[i];
  6906. b.p = a;
  6907. a = b;
  6908. }
  6909. a.n = b = array[0];
  6910. b.p = a;
  6911. }
  6912. var sum$1 = adder();
  6913. function polygonContains(polygon, point) {
  6914. var lambda = point[0],
  6915. phi = point[1],
  6916. sinPhi = sin$1(phi),
  6917. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6918. angle = 0,
  6919. winding = 0;
  6920. sum$1.reset();
  6921. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  6922. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  6923. for (var i = 0, n = polygon.length; i < n; ++i) {
  6924. if (!(m = (ring = polygon[i]).length)) continue;
  6925. var ring,
  6926. m,
  6927. point0 = ring[m - 1],
  6928. lambda0 = point0[0],
  6929. phi0 = point0[1] / 2 + quarterPi,
  6930. sinPhi0 = sin$1(phi0),
  6931. cosPhi0 = cos$1(phi0);
  6932. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6933. var point1 = ring[j],
  6934. lambda1 = point1[0],
  6935. phi1 = point1[1] / 2 + quarterPi,
  6936. sinPhi1 = sin$1(phi1),
  6937. cosPhi1 = cos$1(phi1),
  6938. delta = lambda1 - lambda0,
  6939. sign$$1 = delta >= 0 ? 1 : -1,
  6940. absDelta = sign$$1 * delta,
  6941. antimeridian = absDelta > pi$3,
  6942. k = sinPhi0 * sinPhi1;
  6943. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6944. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6945. // Are the longitudes either side of the point’s meridian (lambda),
  6946. // and are the latitudes smaller than the parallel (phi)?
  6947. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6948. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6949. cartesianNormalizeInPlace(arc);
  6950. var intersection = cartesianCross(normal, arc);
  6951. cartesianNormalizeInPlace(intersection);
  6952. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6953. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6954. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6955. }
  6956. }
  6957. }
  6958. }
  6959. // First, determine whether the South pole is inside or outside:
  6960. //
  6961. // It is inside if:
  6962. // * the polygon winds around it in a clockwise direction.
  6963. // * the polygon does not (cumulatively) wind around it, but has a negative
  6964. // (counter-clockwise) area.
  6965. //
  6966. // Second, count the (signed) number of times a segment crosses a lambda
  6967. // from the point to the South pole. If it is zero, then the point is the
  6968. // same side as the South pole.
  6969. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6970. }
  6971. function clip(pointVisible, clipLine, interpolate, start) {
  6972. return function(sink) {
  6973. var line = clipLine(sink),
  6974. ringBuffer = clipBuffer(),
  6975. ringSink = clipLine(ringBuffer),
  6976. polygonStarted = false,
  6977. polygon,
  6978. segments,
  6979. ring;
  6980. var clip = {
  6981. point: point,
  6982. lineStart: lineStart,
  6983. lineEnd: lineEnd,
  6984. polygonStart: function() {
  6985. clip.point = pointRing;
  6986. clip.lineStart = ringStart;
  6987. clip.lineEnd = ringEnd;
  6988. segments = [];
  6989. polygon = [];
  6990. },
  6991. polygonEnd: function() {
  6992. clip.point = point;
  6993. clip.lineStart = lineStart;
  6994. clip.lineEnd = lineEnd;
  6995. segments = merge(segments);
  6996. var startInside = polygonContains(polygon, start);
  6997. if (segments.length) {
  6998. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6999. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  7000. } else if (startInside) {
  7001. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7002. sink.lineStart();
  7003. interpolate(null, null, 1, sink);
  7004. sink.lineEnd();
  7005. }
  7006. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7007. segments = polygon = null;
  7008. },
  7009. sphere: function() {
  7010. sink.polygonStart();
  7011. sink.lineStart();
  7012. interpolate(null, null, 1, sink);
  7013. sink.lineEnd();
  7014. sink.polygonEnd();
  7015. }
  7016. };
  7017. function point(lambda, phi) {
  7018. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7019. }
  7020. function pointLine(lambda, phi) {
  7021. line.point(lambda, phi);
  7022. }
  7023. function lineStart() {
  7024. clip.point = pointLine;
  7025. line.lineStart();
  7026. }
  7027. function lineEnd() {
  7028. clip.point = point;
  7029. line.lineEnd();
  7030. }
  7031. function pointRing(lambda, phi) {
  7032. ring.push([lambda, phi]);
  7033. ringSink.point(lambda, phi);
  7034. }
  7035. function ringStart() {
  7036. ringSink.lineStart();
  7037. ring = [];
  7038. }
  7039. function ringEnd() {
  7040. pointRing(ring[0][0], ring[0][1]);
  7041. ringSink.lineEnd();
  7042. var clean = ringSink.clean(),
  7043. ringSegments = ringBuffer.result(),
  7044. i, n = ringSegments.length, m,
  7045. segment,
  7046. point;
  7047. ring.pop();
  7048. polygon.push(ring);
  7049. ring = null;
  7050. if (!n) return;
  7051. // No intersections.
  7052. if (clean & 1) {
  7053. segment = ringSegments[0];
  7054. if ((m = segment.length - 1) > 0) {
  7055. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7056. sink.lineStart();
  7057. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7058. sink.lineEnd();
  7059. }
  7060. return;
  7061. }
  7062. // Rejoin connected segments.
  7063. // TODO reuse ringBuffer.rejoin()?
  7064. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7065. segments.push(ringSegments.filter(validSegment));
  7066. }
  7067. return clip;
  7068. };
  7069. }
  7070. function validSegment(segment) {
  7071. return segment.length > 1;
  7072. }
  7073. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7074. // and circle clipping, the same comparison is used.
  7075. function compareIntersection(a, b) {
  7076. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7077. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7078. }
  7079. var clipAntimeridian = clip(
  7080. function() { return true; },
  7081. clipAntimeridianLine,
  7082. clipAntimeridianInterpolate,
  7083. [-pi$3, -halfPi$2]
  7084. );
  7085. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7086. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7087. // intersections, and the first and last segments should be rejoined.
  7088. function clipAntimeridianLine(stream) {
  7089. var lambda0 = NaN,
  7090. phi0 = NaN,
  7091. sign0 = NaN,
  7092. clean; // no intersections
  7093. return {
  7094. lineStart: function() {
  7095. stream.lineStart();
  7096. clean = 1;
  7097. },
  7098. point: function(lambda1, phi1) {
  7099. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7100. delta = abs(lambda1 - lambda0);
  7101. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7102. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7103. stream.point(sign0, phi0);
  7104. stream.lineEnd();
  7105. stream.lineStart();
  7106. stream.point(sign1, phi0);
  7107. stream.point(lambda1, phi0);
  7108. clean = 0;
  7109. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7110. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7111. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7112. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7113. stream.point(sign0, phi0);
  7114. stream.lineEnd();
  7115. stream.lineStart();
  7116. stream.point(sign1, phi0);
  7117. clean = 0;
  7118. }
  7119. stream.point(lambda0 = lambda1, phi0 = phi1);
  7120. sign0 = sign1;
  7121. },
  7122. lineEnd: function() {
  7123. stream.lineEnd();
  7124. lambda0 = phi0 = NaN;
  7125. },
  7126. clean: function() {
  7127. return 2 - clean; // if intersections, rejoin first and last segments
  7128. }
  7129. };
  7130. }
  7131. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7132. var cosPhi0,
  7133. cosPhi1,
  7134. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7135. return abs(sinLambda0Lambda1) > epsilon$2
  7136. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7137. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7138. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7139. : (phi0 + phi1) / 2;
  7140. }
  7141. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7142. var phi;
  7143. if (from == null) {
  7144. phi = direction * halfPi$2;
  7145. stream.point(-pi$3, phi);
  7146. stream.point(0, phi);
  7147. stream.point(pi$3, phi);
  7148. stream.point(pi$3, 0);
  7149. stream.point(pi$3, -phi);
  7150. stream.point(0, -phi);
  7151. stream.point(-pi$3, -phi);
  7152. stream.point(-pi$3, 0);
  7153. stream.point(-pi$3, phi);
  7154. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7155. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7156. phi = direction * lambda / 2;
  7157. stream.point(-lambda, phi);
  7158. stream.point(0, phi);
  7159. stream.point(lambda, phi);
  7160. } else {
  7161. stream.point(to[0], to[1]);
  7162. }
  7163. }
  7164. function clipCircle(radius) {
  7165. var cr = cos$1(radius),
  7166. delta = 6 * radians,
  7167. smallRadius = cr > 0,
  7168. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7169. function interpolate(from, to, direction, stream) {
  7170. circleStream(stream, radius, delta, direction, from, to);
  7171. }
  7172. function visible(lambda, phi) {
  7173. return cos$1(lambda) * cos$1(phi) > cr;
  7174. }
  7175. // Takes a line and cuts into visible segments. Return values used for polygon
  7176. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7177. // intersections 2 - there were intersections, and the first and last segments
  7178. // should be rejoined.
  7179. function clipLine(stream) {
  7180. var point0, // previous point
  7181. c0, // code for previous point
  7182. v0, // visibility of previous point
  7183. v00, // visibility of first point
  7184. clean; // no intersections
  7185. return {
  7186. lineStart: function() {
  7187. v00 = v0 = false;
  7188. clean = 1;
  7189. },
  7190. point: function(lambda, phi) {
  7191. var point1 = [lambda, phi],
  7192. point2,
  7193. v = visible(lambda, phi),
  7194. c = smallRadius
  7195. ? v ? 0 : code(lambda, phi)
  7196. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7197. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7198. // Handle degeneracies.
  7199. // TODO ignore if not clipping polygons.
  7200. if (v !== v0) {
  7201. point2 = intersect(point0, point1);
  7202. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7203. point1[0] += epsilon$2;
  7204. point1[1] += epsilon$2;
  7205. v = visible(point1[0], point1[1]);
  7206. }
  7207. }
  7208. if (v !== v0) {
  7209. clean = 0;
  7210. if (v) {
  7211. // outside going in
  7212. stream.lineStart();
  7213. point2 = intersect(point1, point0);
  7214. stream.point(point2[0], point2[1]);
  7215. } else {
  7216. // inside going out
  7217. point2 = intersect(point0, point1);
  7218. stream.point(point2[0], point2[1]);
  7219. stream.lineEnd();
  7220. }
  7221. point0 = point2;
  7222. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7223. var t;
  7224. // If the codes for two points are different, or are both zero,
  7225. // and there this segment intersects with the small circle.
  7226. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7227. clean = 0;
  7228. if (smallRadius) {
  7229. stream.lineStart();
  7230. stream.point(t[0][0], t[0][1]);
  7231. stream.point(t[1][0], t[1][1]);
  7232. stream.lineEnd();
  7233. } else {
  7234. stream.point(t[1][0], t[1][1]);
  7235. stream.lineEnd();
  7236. stream.lineStart();
  7237. stream.point(t[0][0], t[0][1]);
  7238. }
  7239. }
  7240. }
  7241. if (v && (!point0 || !pointEqual(point0, point1))) {
  7242. stream.point(point1[0], point1[1]);
  7243. }
  7244. point0 = point1, v0 = v, c0 = c;
  7245. },
  7246. lineEnd: function() {
  7247. if (v0) stream.lineEnd();
  7248. point0 = null;
  7249. },
  7250. // Rejoin first and last segments if there were intersections and the first
  7251. // and last points were visible.
  7252. clean: function() {
  7253. return clean | ((v00 && v0) << 1);
  7254. }
  7255. };
  7256. }
  7257. // Intersects the great circle between a and b with the clip circle.
  7258. function intersect(a, b, two) {
  7259. var pa = cartesian(a),
  7260. pb = cartesian(b);
  7261. // We have two planes, n1.p = d1 and n2.p = d2.
  7262. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7263. var n1 = [1, 0, 0], // normal
  7264. n2 = cartesianCross(pa, pb),
  7265. n2n2 = cartesianDot(n2, n2),
  7266. n1n2 = n2[0], // cartesianDot(n1, n2),
  7267. determinant = n2n2 - n1n2 * n1n2;
  7268. // Two polar points.
  7269. if (!determinant) return !two && a;
  7270. var c1 = cr * n2n2 / determinant,
  7271. c2 = -cr * n1n2 / determinant,
  7272. n1xn2 = cartesianCross(n1, n2),
  7273. A = cartesianScale(n1, c1),
  7274. B = cartesianScale(n2, c2);
  7275. cartesianAddInPlace(A, B);
  7276. // Solve |p(t)|^2 = 1.
  7277. var u = n1xn2,
  7278. w = cartesianDot(A, u),
  7279. uu = cartesianDot(u, u),
  7280. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7281. if (t2 < 0) return;
  7282. var t = sqrt(t2),
  7283. q = cartesianScale(u, (-w - t) / uu);
  7284. cartesianAddInPlace(q, A);
  7285. q = spherical(q);
  7286. if (!two) return q;
  7287. // Two intersection points.
  7288. var lambda0 = a[0],
  7289. lambda1 = b[0],
  7290. phi0 = a[1],
  7291. phi1 = b[1],
  7292. z;
  7293. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7294. var delta = lambda1 - lambda0,
  7295. polar = abs(delta - pi$3) < epsilon$2,
  7296. meridian = polar || delta < epsilon$2;
  7297. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7298. // Check that the first point is between a and b.
  7299. if (meridian
  7300. ? polar
  7301. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7302. : phi0 <= q[1] && q[1] <= phi1
  7303. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7304. var q1 = cartesianScale(u, (-w + t) / uu);
  7305. cartesianAddInPlace(q1, A);
  7306. return [q, spherical(q1)];
  7307. }
  7308. }
  7309. // Generates a 4-bit vector representing the location of a point relative to
  7310. // the small circle's bounding box.
  7311. function code(lambda, phi) {
  7312. var r = smallRadius ? radius : pi$3 - radius,
  7313. code = 0;
  7314. if (lambda < -r) code |= 1; // left
  7315. else if (lambda > r) code |= 2; // right
  7316. if (phi < -r) code |= 4; // below
  7317. else if (phi > r) code |= 8; // above
  7318. return code;
  7319. }
  7320. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7321. }
  7322. function clipLine(a, b, x0, y0, x1, y1) {
  7323. var ax = a[0],
  7324. ay = a[1],
  7325. bx = b[0],
  7326. by = b[1],
  7327. t0 = 0,
  7328. t1 = 1,
  7329. dx = bx - ax,
  7330. dy = by - ay,
  7331. r;
  7332. r = x0 - ax;
  7333. if (!dx && r > 0) return;
  7334. r /= dx;
  7335. if (dx < 0) {
  7336. if (r < t0) return;
  7337. if (r < t1) t1 = r;
  7338. } else if (dx > 0) {
  7339. if (r > t1) return;
  7340. if (r > t0) t0 = r;
  7341. }
  7342. r = x1 - ax;
  7343. if (!dx && r < 0) return;
  7344. r /= dx;
  7345. if (dx < 0) {
  7346. if (r > t1) return;
  7347. if (r > t0) t0 = r;
  7348. } else if (dx > 0) {
  7349. if (r < t0) return;
  7350. if (r < t1) t1 = r;
  7351. }
  7352. r = y0 - ay;
  7353. if (!dy && r > 0) return;
  7354. r /= dy;
  7355. if (dy < 0) {
  7356. if (r < t0) return;
  7357. if (r < t1) t1 = r;
  7358. } else if (dy > 0) {
  7359. if (r > t1) return;
  7360. if (r > t0) t0 = r;
  7361. }
  7362. r = y1 - ay;
  7363. if (!dy && r < 0) return;
  7364. r /= dy;
  7365. if (dy < 0) {
  7366. if (r > t1) return;
  7367. if (r > t0) t0 = r;
  7368. } else if (dy > 0) {
  7369. if (r < t0) return;
  7370. if (r < t1) t1 = r;
  7371. }
  7372. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7373. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7374. return true;
  7375. }
  7376. var clipMax = 1e9, clipMin = -clipMax;
  7377. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7378. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7379. function clipRectangle(x0, y0, x1, y1) {
  7380. function visible(x, y) {
  7381. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7382. }
  7383. function interpolate(from, to, direction, stream) {
  7384. var a = 0, a1 = 0;
  7385. if (from == null
  7386. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7387. || comparePoint(from, to) < 0 ^ direction > 0) {
  7388. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7389. while ((a = (a + direction + 4) % 4) !== a1);
  7390. } else {
  7391. stream.point(to[0], to[1]);
  7392. }
  7393. }
  7394. function corner(p, direction) {
  7395. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7396. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7397. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7398. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7399. }
  7400. function compareIntersection(a, b) {
  7401. return comparePoint(a.x, b.x);
  7402. }
  7403. function comparePoint(a, b) {
  7404. var ca = corner(a, 1),
  7405. cb = corner(b, 1);
  7406. return ca !== cb ? ca - cb
  7407. : ca === 0 ? b[1] - a[1]
  7408. : ca === 1 ? a[0] - b[0]
  7409. : ca === 2 ? a[1] - b[1]
  7410. : b[0] - a[0];
  7411. }
  7412. return function(stream) {
  7413. var activeStream = stream,
  7414. bufferStream = clipBuffer(),
  7415. segments,
  7416. polygon,
  7417. ring,
  7418. x__, y__, v__, // first point
  7419. x_, y_, v_, // previous point
  7420. first,
  7421. clean;
  7422. var clipStream = {
  7423. point: point,
  7424. lineStart: lineStart,
  7425. lineEnd: lineEnd,
  7426. polygonStart: polygonStart,
  7427. polygonEnd: polygonEnd
  7428. };
  7429. function point(x, y) {
  7430. if (visible(x, y)) activeStream.point(x, y);
  7431. }
  7432. function polygonInside() {
  7433. var winding = 0;
  7434. for (var i = 0, n = polygon.length; i < n; ++i) {
  7435. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7436. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7437. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7438. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7439. }
  7440. }
  7441. return winding;
  7442. }
  7443. // Buffer geometry within a polygon and then clip it en masse.
  7444. function polygonStart() {
  7445. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7446. }
  7447. function polygonEnd() {
  7448. var startInside = polygonInside(),
  7449. cleanInside = clean && startInside,
  7450. visible = (segments = merge(segments)).length;
  7451. if (cleanInside || visible) {
  7452. stream.polygonStart();
  7453. if (cleanInside) {
  7454. stream.lineStart();
  7455. interpolate(null, null, 1, stream);
  7456. stream.lineEnd();
  7457. }
  7458. if (visible) {
  7459. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7460. }
  7461. stream.polygonEnd();
  7462. }
  7463. activeStream = stream, segments = polygon = ring = null;
  7464. }
  7465. function lineStart() {
  7466. clipStream.point = linePoint;
  7467. if (polygon) polygon.push(ring = []);
  7468. first = true;
  7469. v_ = false;
  7470. x_ = y_ = NaN;
  7471. }
  7472. // TODO rather than special-case polygons, simply handle them separately.
  7473. // Ideally, coincident intersection points should be jittered to avoid
  7474. // clipping issues.
  7475. function lineEnd() {
  7476. if (segments) {
  7477. linePoint(x__, y__);
  7478. if (v__ && v_) bufferStream.rejoin();
  7479. segments.push(bufferStream.result());
  7480. }
  7481. clipStream.point = point;
  7482. if (v_) activeStream.lineEnd();
  7483. }
  7484. function linePoint(x, y) {
  7485. var v = visible(x, y);
  7486. if (polygon) ring.push([x, y]);
  7487. if (first) {
  7488. x__ = x, y__ = y, v__ = v;
  7489. first = false;
  7490. if (v) {
  7491. activeStream.lineStart();
  7492. activeStream.point(x, y);
  7493. }
  7494. } else {
  7495. if (v && v_) activeStream.point(x, y);
  7496. else {
  7497. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7498. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7499. if (clipLine(a, b, x0, y0, x1, y1)) {
  7500. if (!v_) {
  7501. activeStream.lineStart();
  7502. activeStream.point(a[0], a[1]);
  7503. }
  7504. activeStream.point(b[0], b[1]);
  7505. if (!v) activeStream.lineEnd();
  7506. clean = false;
  7507. } else if (v) {
  7508. activeStream.lineStart();
  7509. activeStream.point(x, y);
  7510. clean = false;
  7511. }
  7512. }
  7513. }
  7514. x_ = x, y_ = y, v_ = v;
  7515. }
  7516. return clipStream;
  7517. };
  7518. }
  7519. function extent$1() {
  7520. var x0 = 0,
  7521. y0 = 0,
  7522. x1 = 960,
  7523. y1 = 500,
  7524. cache,
  7525. cacheStream,
  7526. clip;
  7527. return clip = {
  7528. stream: function(stream) {
  7529. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7530. },
  7531. extent: function(_) {
  7532. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7533. }
  7534. };
  7535. }
  7536. var lengthSum = adder(),
  7537. lambda0$2,
  7538. sinPhi0$1,
  7539. cosPhi0$1;
  7540. var lengthStream = {
  7541. sphere: noop$2,
  7542. point: noop$2,
  7543. lineStart: lengthLineStart,
  7544. lineEnd: noop$2,
  7545. polygonStart: noop$2,
  7546. polygonEnd: noop$2
  7547. };
  7548. function lengthLineStart() {
  7549. lengthStream.point = lengthPointFirst;
  7550. lengthStream.lineEnd = lengthLineEnd;
  7551. }
  7552. function lengthLineEnd() {
  7553. lengthStream.point = lengthStream.lineEnd = noop$2;
  7554. }
  7555. function lengthPointFirst(lambda, phi) {
  7556. lambda *= radians, phi *= radians;
  7557. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7558. lengthStream.point = lengthPoint;
  7559. }
  7560. function lengthPoint(lambda, phi) {
  7561. lambda *= radians, phi *= radians;
  7562. var sinPhi = sin$1(phi),
  7563. cosPhi = cos$1(phi),
  7564. delta = abs(lambda - lambda0$2),
  7565. cosDelta = cos$1(delta),
  7566. sinDelta = sin$1(delta),
  7567. x = cosPhi * sinDelta,
  7568. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7569. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7570. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7571. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7572. }
  7573. function length$1(object) {
  7574. lengthSum.reset();
  7575. geoStream(object, lengthStream);
  7576. return +lengthSum;
  7577. }
  7578. var coordinates = [null, null],
  7579. object$1 = {type: "LineString", coordinates: coordinates};
  7580. function distance(a, b) {
  7581. coordinates[0] = a;
  7582. coordinates[1] = b;
  7583. return length$1(object$1);
  7584. }
  7585. var containsObjectType = {
  7586. Feature: function(object, point) {
  7587. return containsGeometry(object.geometry, point);
  7588. },
  7589. FeatureCollection: function(object, point) {
  7590. var features = object.features, i = -1, n = features.length;
  7591. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7592. return false;
  7593. }
  7594. };
  7595. var containsGeometryType = {
  7596. Sphere: function() {
  7597. return true;
  7598. },
  7599. Point: function(object, point) {
  7600. return containsPoint(object.coordinates, point);
  7601. },
  7602. MultiPoint: function(object, point) {
  7603. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7604. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7605. return false;
  7606. },
  7607. LineString: function(object, point) {
  7608. return containsLine(object.coordinates, point);
  7609. },
  7610. MultiLineString: function(object, point) {
  7611. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7612. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7613. return false;
  7614. },
  7615. Polygon: function(object, point) {
  7616. return containsPolygon(object.coordinates, point);
  7617. },
  7618. MultiPolygon: function(object, point) {
  7619. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7620. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7621. return false;
  7622. },
  7623. GeometryCollection: function(object, point) {
  7624. var geometries = object.geometries, i = -1, n = geometries.length;
  7625. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7626. return false;
  7627. }
  7628. };
  7629. function containsGeometry(geometry, point) {
  7630. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7631. ? containsGeometryType[geometry.type](geometry, point)
  7632. : false;
  7633. }
  7634. function containsPoint(coordinates, point) {
  7635. return distance(coordinates, point) === 0;
  7636. }
  7637. function containsLine(coordinates, point) {
  7638. var ab = distance(coordinates[0], coordinates[1]),
  7639. ao = distance(coordinates[0], point),
  7640. ob = distance(point, coordinates[1]);
  7641. return ao + ob <= ab + epsilon$2;
  7642. }
  7643. function containsPolygon(coordinates, point) {
  7644. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7645. }
  7646. function ringRadians(ring) {
  7647. return ring = ring.map(pointRadians), ring.pop(), ring;
  7648. }
  7649. function pointRadians(point) {
  7650. return [point[0] * radians, point[1] * radians];
  7651. }
  7652. function contains$1(object, point) {
  7653. return (object && containsObjectType.hasOwnProperty(object.type)
  7654. ? containsObjectType[object.type]
  7655. : containsGeometry)(object, point);
  7656. }
  7657. function graticuleX(y0, y1, dy) {
  7658. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7659. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7660. }
  7661. function graticuleY(x0, x1, dx) {
  7662. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7663. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7664. }
  7665. function graticule() {
  7666. var x1, x0, X1, X0,
  7667. y1, y0, Y1, Y0,
  7668. dx = 10, dy = dx, DX = 90, DY = 360,
  7669. x, y, X, Y,
  7670. precision = 2.5;
  7671. function graticule() {
  7672. return {type: "MultiLineString", coordinates: lines()};
  7673. }
  7674. function lines() {
  7675. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7676. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7677. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7678. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7679. }
  7680. graticule.lines = function() {
  7681. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7682. };
  7683. graticule.outline = function() {
  7684. return {
  7685. type: "Polygon",
  7686. coordinates: [
  7687. X(X0).concat(
  7688. Y(Y1).slice(1),
  7689. X(X1).reverse().slice(1),
  7690. Y(Y0).reverse().slice(1))
  7691. ]
  7692. };
  7693. };
  7694. graticule.extent = function(_) {
  7695. if (!arguments.length) return graticule.extentMinor();
  7696. return graticule.extentMajor(_).extentMinor(_);
  7697. };
  7698. graticule.extentMajor = function(_) {
  7699. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7700. X0 = +_[0][0], X1 = +_[1][0];
  7701. Y0 = +_[0][1], Y1 = +_[1][1];
  7702. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7703. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7704. return graticule.precision(precision);
  7705. };
  7706. graticule.extentMinor = function(_) {
  7707. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7708. x0 = +_[0][0], x1 = +_[1][0];
  7709. y0 = +_[0][1], y1 = +_[1][1];
  7710. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7711. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7712. return graticule.precision(precision);
  7713. };
  7714. graticule.step = function(_) {
  7715. if (!arguments.length) return graticule.stepMinor();
  7716. return graticule.stepMajor(_).stepMinor(_);
  7717. };
  7718. graticule.stepMajor = function(_) {
  7719. if (!arguments.length) return [DX, DY];
  7720. DX = +_[0], DY = +_[1];
  7721. return graticule;
  7722. };
  7723. graticule.stepMinor = function(_) {
  7724. if (!arguments.length) return [dx, dy];
  7725. dx = +_[0], dy = +_[1];
  7726. return graticule;
  7727. };
  7728. graticule.precision = function(_) {
  7729. if (!arguments.length) return precision;
  7730. precision = +_;
  7731. x = graticuleX(y0, y1, 90);
  7732. y = graticuleY(x0, x1, precision);
  7733. X = graticuleX(Y0, Y1, 90);
  7734. Y = graticuleY(X0, X1, precision);
  7735. return graticule;
  7736. };
  7737. return graticule
  7738. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7739. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7740. }
  7741. function graticule10() {
  7742. return graticule()();
  7743. }
  7744. function interpolate$1(a, b) {
  7745. var x0 = a[0] * radians,
  7746. y0 = a[1] * radians,
  7747. x1 = b[0] * radians,
  7748. y1 = b[1] * radians,
  7749. cy0 = cos$1(y0),
  7750. sy0 = sin$1(y0),
  7751. cy1 = cos$1(y1),
  7752. sy1 = sin$1(y1),
  7753. kx0 = cy0 * cos$1(x0),
  7754. ky0 = cy0 * sin$1(x0),
  7755. kx1 = cy1 * cos$1(x1),
  7756. ky1 = cy1 * sin$1(x1),
  7757. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7758. k = sin$1(d);
  7759. var interpolate = d ? function(t) {
  7760. var B = sin$1(t *= d) / k,
  7761. A = sin$1(d - t) / k,
  7762. x = A * kx0 + B * kx1,
  7763. y = A * ky0 + B * ky1,
  7764. z = A * sy0 + B * sy1;
  7765. return [
  7766. atan2(y, x) * degrees$1,
  7767. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7768. ];
  7769. } : function() {
  7770. return [x0 * degrees$1, y0 * degrees$1];
  7771. };
  7772. interpolate.distance = d;
  7773. return interpolate;
  7774. }
  7775. function identity$4(x) {
  7776. return x;
  7777. }
  7778. var areaSum$1 = adder(),
  7779. areaRingSum$1 = adder(),
  7780. x00,
  7781. y00,
  7782. x0$1,
  7783. y0$1;
  7784. var areaStream$1 = {
  7785. point: noop$2,
  7786. lineStart: noop$2,
  7787. lineEnd: noop$2,
  7788. polygonStart: function() {
  7789. areaStream$1.lineStart = areaRingStart$1;
  7790. areaStream$1.lineEnd = areaRingEnd$1;
  7791. },
  7792. polygonEnd: function() {
  7793. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7794. areaSum$1.add(abs(areaRingSum$1));
  7795. areaRingSum$1.reset();
  7796. },
  7797. result: function() {
  7798. var area = areaSum$1 / 2;
  7799. areaSum$1.reset();
  7800. return area;
  7801. }
  7802. };
  7803. function areaRingStart$1() {
  7804. areaStream$1.point = areaPointFirst$1;
  7805. }
  7806. function areaPointFirst$1(x, y) {
  7807. areaStream$1.point = areaPoint$1;
  7808. x00 = x0$1 = x, y00 = y0$1 = y;
  7809. }
  7810. function areaPoint$1(x, y) {
  7811. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7812. x0$1 = x, y0$1 = y;
  7813. }
  7814. function areaRingEnd$1() {
  7815. areaPoint$1(x00, y00);
  7816. }
  7817. var x0$2 = Infinity,
  7818. y0$2 = x0$2,
  7819. x1 = -x0$2,
  7820. y1 = x1;
  7821. var boundsStream$1 = {
  7822. point: boundsPoint$1,
  7823. lineStart: noop$2,
  7824. lineEnd: noop$2,
  7825. polygonStart: noop$2,
  7826. polygonEnd: noop$2,
  7827. result: function() {
  7828. var bounds = [[x0$2, y0$2], [x1, y1]];
  7829. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7830. return bounds;
  7831. }
  7832. };
  7833. function boundsPoint$1(x, y) {
  7834. if (x < x0$2) x0$2 = x;
  7835. if (x > x1) x1 = x;
  7836. if (y < y0$2) y0$2 = y;
  7837. if (y > y1) y1 = y;
  7838. }
  7839. // TODO Enforce positive area for exterior, negative area for interior?
  7840. var X0$1 = 0,
  7841. Y0$1 = 0,
  7842. Z0$1 = 0,
  7843. X1$1 = 0,
  7844. Y1$1 = 0,
  7845. Z1$1 = 0,
  7846. X2$1 = 0,
  7847. Y2$1 = 0,
  7848. Z2$1 = 0,
  7849. x00$1,
  7850. y00$1,
  7851. x0$3,
  7852. y0$3;
  7853. var centroidStream$1 = {
  7854. point: centroidPoint$1,
  7855. lineStart: centroidLineStart$1,
  7856. lineEnd: centroidLineEnd$1,
  7857. polygonStart: function() {
  7858. centroidStream$1.lineStart = centroidRingStart$1;
  7859. centroidStream$1.lineEnd = centroidRingEnd$1;
  7860. },
  7861. polygonEnd: function() {
  7862. centroidStream$1.point = centroidPoint$1;
  7863. centroidStream$1.lineStart = centroidLineStart$1;
  7864. centroidStream$1.lineEnd = centroidLineEnd$1;
  7865. },
  7866. result: function() {
  7867. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7868. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7869. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7870. : [NaN, NaN];
  7871. X0$1 = Y0$1 = Z0$1 =
  7872. X1$1 = Y1$1 = Z1$1 =
  7873. X2$1 = Y2$1 = Z2$1 = 0;
  7874. return centroid;
  7875. }
  7876. };
  7877. function centroidPoint$1(x, y) {
  7878. X0$1 += x;
  7879. Y0$1 += y;
  7880. ++Z0$1;
  7881. }
  7882. function centroidLineStart$1() {
  7883. centroidStream$1.point = centroidPointFirstLine;
  7884. }
  7885. function centroidPointFirstLine(x, y) {
  7886. centroidStream$1.point = centroidPointLine;
  7887. centroidPoint$1(x0$3 = x, y0$3 = y);
  7888. }
  7889. function centroidPointLine(x, y) {
  7890. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7891. X1$1 += z * (x0$3 + x) / 2;
  7892. Y1$1 += z * (y0$3 + y) / 2;
  7893. Z1$1 += z;
  7894. centroidPoint$1(x0$3 = x, y0$3 = y);
  7895. }
  7896. function centroidLineEnd$1() {
  7897. centroidStream$1.point = centroidPoint$1;
  7898. }
  7899. function centroidRingStart$1() {
  7900. centroidStream$1.point = centroidPointFirstRing;
  7901. }
  7902. function centroidRingEnd$1() {
  7903. centroidPointRing(x00$1, y00$1);
  7904. }
  7905. function centroidPointFirstRing(x, y) {
  7906. centroidStream$1.point = centroidPointRing;
  7907. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7908. }
  7909. function centroidPointRing(x, y) {
  7910. var dx = x - x0$3,
  7911. dy = y - y0$3,
  7912. z = sqrt(dx * dx + dy * dy);
  7913. X1$1 += z * (x0$3 + x) / 2;
  7914. Y1$1 += z * (y0$3 + y) / 2;
  7915. Z1$1 += z;
  7916. z = y0$3 * x - x0$3 * y;
  7917. X2$1 += z * (x0$3 + x);
  7918. Y2$1 += z * (y0$3 + y);
  7919. Z2$1 += z * 3;
  7920. centroidPoint$1(x0$3 = x, y0$3 = y);
  7921. }
  7922. function PathContext(context) {
  7923. this._context = context;
  7924. }
  7925. PathContext.prototype = {
  7926. _radius: 4.5,
  7927. pointRadius: function(_) {
  7928. return this._radius = _, this;
  7929. },
  7930. polygonStart: function() {
  7931. this._line = 0;
  7932. },
  7933. polygonEnd: function() {
  7934. this._line = NaN;
  7935. },
  7936. lineStart: function() {
  7937. this._point = 0;
  7938. },
  7939. lineEnd: function() {
  7940. if (this._line === 0) this._context.closePath();
  7941. this._point = NaN;
  7942. },
  7943. point: function(x, y) {
  7944. switch (this._point) {
  7945. case 0: {
  7946. this._context.moveTo(x, y);
  7947. this._point = 1;
  7948. break;
  7949. }
  7950. case 1: {
  7951. this._context.lineTo(x, y);
  7952. break;
  7953. }
  7954. default: {
  7955. this._context.moveTo(x + this._radius, y);
  7956. this._context.arc(x, y, this._radius, 0, tau$3);
  7957. break;
  7958. }
  7959. }
  7960. },
  7961. result: noop$2
  7962. };
  7963. var lengthSum$1 = adder(),
  7964. lengthRing,
  7965. x00$2,
  7966. y00$2,
  7967. x0$4,
  7968. y0$4;
  7969. var lengthStream$1 = {
  7970. point: noop$2,
  7971. lineStart: function() {
  7972. lengthStream$1.point = lengthPointFirst$1;
  7973. },
  7974. lineEnd: function() {
  7975. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7976. lengthStream$1.point = noop$2;
  7977. },
  7978. polygonStart: function() {
  7979. lengthRing = true;
  7980. },
  7981. polygonEnd: function() {
  7982. lengthRing = null;
  7983. },
  7984. result: function() {
  7985. var length = +lengthSum$1;
  7986. lengthSum$1.reset();
  7987. return length;
  7988. }
  7989. };
  7990. function lengthPointFirst$1(x, y) {
  7991. lengthStream$1.point = lengthPoint$1;
  7992. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7993. }
  7994. function lengthPoint$1(x, y) {
  7995. x0$4 -= x, y0$4 -= y;
  7996. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7997. x0$4 = x, y0$4 = y;
  7998. }
  7999. function PathString() {
  8000. this._string = [];
  8001. }
  8002. PathString.prototype = {
  8003. _radius: 4.5,
  8004. _circle: circle$1(4.5),
  8005. pointRadius: function(_) {
  8006. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  8007. return this;
  8008. },
  8009. polygonStart: function() {
  8010. this._line = 0;
  8011. },
  8012. polygonEnd: function() {
  8013. this._line = NaN;
  8014. },
  8015. lineStart: function() {
  8016. this._point = 0;
  8017. },
  8018. lineEnd: function() {
  8019. if (this._line === 0) this._string.push("Z");
  8020. this._point = NaN;
  8021. },
  8022. point: function(x, y) {
  8023. switch (this._point) {
  8024. case 0: {
  8025. this._string.push("M", x, ",", y);
  8026. this._point = 1;
  8027. break;
  8028. }
  8029. case 1: {
  8030. this._string.push("L", x, ",", y);
  8031. break;
  8032. }
  8033. default: {
  8034. if (this._circle == null) this._circle = circle$1(this._radius);
  8035. this._string.push("M", x, ",", y, this._circle);
  8036. break;
  8037. }
  8038. }
  8039. },
  8040. result: function() {
  8041. if (this._string.length) {
  8042. var result = this._string.join("");
  8043. this._string = [];
  8044. return result;
  8045. } else {
  8046. return null;
  8047. }
  8048. }
  8049. };
  8050. function circle$1(radius) {
  8051. return "m0," + radius
  8052. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8053. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8054. + "z";
  8055. }
  8056. function index$1(projection, context) {
  8057. var pointRadius = 4.5,
  8058. projectionStream,
  8059. contextStream;
  8060. function path(object) {
  8061. if (object) {
  8062. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8063. geoStream(object, projectionStream(contextStream));
  8064. }
  8065. return contextStream.result();
  8066. }
  8067. path.area = function(object) {
  8068. geoStream(object, projectionStream(areaStream$1));
  8069. return areaStream$1.result();
  8070. };
  8071. path.measure = function(object) {
  8072. geoStream(object, projectionStream(lengthStream$1));
  8073. return lengthStream$1.result();
  8074. };
  8075. path.bounds = function(object) {
  8076. geoStream(object, projectionStream(boundsStream$1));
  8077. return boundsStream$1.result();
  8078. };
  8079. path.centroid = function(object) {
  8080. geoStream(object, projectionStream(centroidStream$1));
  8081. return centroidStream$1.result();
  8082. };
  8083. path.projection = function(_) {
  8084. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8085. };
  8086. path.context = function(_) {
  8087. if (!arguments.length) return context;
  8088. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8089. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8090. return path;
  8091. };
  8092. path.pointRadius = function(_) {
  8093. if (!arguments.length) return pointRadius;
  8094. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8095. return path;
  8096. };
  8097. return path.projection(projection).context(context);
  8098. }
  8099. function transform(methods) {
  8100. return {
  8101. stream: transformer(methods)
  8102. };
  8103. }
  8104. function transformer(methods) {
  8105. return function(stream) {
  8106. var s = new TransformStream;
  8107. for (var key in methods) s[key] = methods[key];
  8108. s.stream = stream;
  8109. return s;
  8110. };
  8111. }
  8112. function TransformStream() {}
  8113. TransformStream.prototype = {
  8114. constructor: TransformStream,
  8115. point: function(x, y) { this.stream.point(x, y); },
  8116. sphere: function() { this.stream.sphere(); },
  8117. lineStart: function() { this.stream.lineStart(); },
  8118. lineEnd: function() { this.stream.lineEnd(); },
  8119. polygonStart: function() { this.stream.polygonStart(); },
  8120. polygonEnd: function() { this.stream.polygonEnd(); }
  8121. };
  8122. function fit(projection, fitBounds, object) {
  8123. var clip = projection.clipExtent && projection.clipExtent();
  8124. projection.scale(150).translate([0, 0]);
  8125. if (clip != null) projection.clipExtent(null);
  8126. geoStream(object, projection.stream(boundsStream$1));
  8127. fitBounds(boundsStream$1.result());
  8128. if (clip != null) projection.clipExtent(clip);
  8129. return projection;
  8130. }
  8131. function fitExtent(projection, extent, object) {
  8132. return fit(projection, function(b) {
  8133. var w = extent[1][0] - extent[0][0],
  8134. h = extent[1][1] - extent[0][1],
  8135. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8136. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8137. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8138. projection.scale(150 * k).translate([x, y]);
  8139. }, object);
  8140. }
  8141. function fitSize(projection, size, object) {
  8142. return fitExtent(projection, [[0, 0], size], object);
  8143. }
  8144. function fitWidth(projection, width, object) {
  8145. return fit(projection, function(b) {
  8146. var w = +width,
  8147. k = w / (b[1][0] - b[0][0]),
  8148. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8149. y = -k * b[0][1];
  8150. projection.scale(150 * k).translate([x, y]);
  8151. }, object);
  8152. }
  8153. function fitHeight(projection, height, object) {
  8154. return fit(projection, function(b) {
  8155. var h = +height,
  8156. k = h / (b[1][1] - b[0][1]),
  8157. x = -k * b[0][0],
  8158. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8159. projection.scale(150 * k).translate([x, y]);
  8160. }, object);
  8161. }
  8162. var maxDepth = 16, // maximum depth of subdivision
  8163. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8164. function resample(project, delta2) {
  8165. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8166. }
  8167. function resampleNone(project) {
  8168. return transformer({
  8169. point: function(x, y) {
  8170. x = project(x, y);
  8171. this.stream.point(x[0], x[1]);
  8172. }
  8173. });
  8174. }
  8175. function resample$1(project, delta2) {
  8176. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8177. var dx = x1 - x0,
  8178. dy = y1 - y0,
  8179. d2 = dx * dx + dy * dy;
  8180. if (d2 > 4 * delta2 && depth--) {
  8181. var a = a0 + a1,
  8182. b = b0 + b1,
  8183. c = c0 + c1,
  8184. m = sqrt(a * a + b * b + c * c),
  8185. phi2 = asin(c /= m),
  8186. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8187. p = project(lambda2, phi2),
  8188. x2 = p[0],
  8189. y2 = p[1],
  8190. dx2 = x2 - x0,
  8191. dy2 = y2 - y0,
  8192. dz = dy * dx2 - dx * dy2;
  8193. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8194. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8195. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8196. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8197. stream.point(x2, y2);
  8198. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8199. }
  8200. }
  8201. }
  8202. return function(stream) {
  8203. var lambda00, x00, y00, a00, b00, c00, // first point
  8204. lambda0, x0, y0, a0, b0, c0; // previous point
  8205. var resampleStream = {
  8206. point: point,
  8207. lineStart: lineStart,
  8208. lineEnd: lineEnd,
  8209. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8210. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8211. };
  8212. function point(x, y) {
  8213. x = project(x, y);
  8214. stream.point(x[0], x[1]);
  8215. }
  8216. function lineStart() {
  8217. x0 = NaN;
  8218. resampleStream.point = linePoint;
  8219. stream.lineStart();
  8220. }
  8221. function linePoint(lambda, phi) {
  8222. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8223. 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);
  8224. stream.point(x0, y0);
  8225. }
  8226. function lineEnd() {
  8227. resampleStream.point = point;
  8228. stream.lineEnd();
  8229. }
  8230. function ringStart() {
  8231. lineStart();
  8232. resampleStream.point = ringPoint;
  8233. resampleStream.lineEnd = ringEnd;
  8234. }
  8235. function ringPoint(lambda, phi) {
  8236. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8237. resampleStream.point = linePoint;
  8238. }
  8239. function ringEnd() {
  8240. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8241. resampleStream.lineEnd = lineEnd;
  8242. lineEnd();
  8243. }
  8244. return resampleStream;
  8245. };
  8246. }
  8247. var transformRadians = transformer({
  8248. point: function(x, y) {
  8249. this.stream.point(x * radians, y * radians);
  8250. }
  8251. });
  8252. function transformRotate(rotate) {
  8253. return transformer({
  8254. point: function(x, y) {
  8255. var r = rotate(x, y);
  8256. return this.stream.point(r[0], r[1]);
  8257. }
  8258. });
  8259. }
  8260. function scaleTranslate(k, dx, dy) {
  8261. function transform$$1(x, y) {
  8262. return [dx + k * x, dy - k * y];
  8263. }
  8264. transform$$1.invert = function(x, y) {
  8265. return [(x - dx) / k, (dy - y) / k];
  8266. };
  8267. return transform$$1;
  8268. }
  8269. function scaleTranslateRotate(k, dx, dy, alpha) {
  8270. var cosAlpha = cos$1(alpha),
  8271. sinAlpha = sin$1(alpha),
  8272. a = cosAlpha * k,
  8273. b = sinAlpha * k,
  8274. ai = cosAlpha / k,
  8275. bi = sinAlpha / k,
  8276. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8277. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8278. function transform$$1(x, y) {
  8279. return [a * x - b * y + dx, dy - b * x - a * y];
  8280. }
  8281. transform$$1.invert = function(x, y) {
  8282. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8283. };
  8284. return transform$$1;
  8285. }
  8286. function projection(project) {
  8287. return projectionMutator(function() { return project; })();
  8288. }
  8289. function projectionMutator(projectAt) {
  8290. var project,
  8291. k = 150, // scale
  8292. x = 480, y = 250, // translate
  8293. lambda = 0, phi = 0, // center
  8294. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8295. alpha = 0, // post-rotate
  8296. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8297. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8298. delta2 = 0.5, // precision
  8299. projectResample,
  8300. projectTransform,
  8301. projectRotateTransform,
  8302. cache,
  8303. cacheStream;
  8304. function projection(point) {
  8305. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8306. }
  8307. function invert(point) {
  8308. point = projectRotateTransform.invert(point[0], point[1]);
  8309. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8310. }
  8311. projection.stream = function(stream) {
  8312. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8313. };
  8314. projection.preclip = function(_) {
  8315. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8316. };
  8317. projection.postclip = function(_) {
  8318. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8319. };
  8320. projection.clipAngle = function(_) {
  8321. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8322. };
  8323. projection.clipExtent = function(_) {
  8324. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8325. };
  8326. projection.scale = function(_) {
  8327. return arguments.length ? (k = +_, recenter()) : k;
  8328. };
  8329. projection.translate = function(_) {
  8330. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8331. };
  8332. projection.center = function(_) {
  8333. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8334. };
  8335. projection.rotate = function(_) {
  8336. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
  8337. };
  8338. projection.angle = function(_) {
  8339. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8340. };
  8341. projection.precision = function(_) {
  8342. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8343. };
  8344. projection.fitExtent = function(extent, object) {
  8345. return fitExtent(projection, extent, object);
  8346. };
  8347. projection.fitSize = function(size, object) {
  8348. return fitSize(projection, size, object);
  8349. };
  8350. projection.fitWidth = function(width, object) {
  8351. return fitWidth(projection, width, object);
  8352. };
  8353. projection.fitHeight = function(height, object) {
  8354. return fitHeight(projection, height, object);
  8355. };
  8356. function recenter() {
  8357. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8358. transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8359. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8360. projectTransform = compose(project, transform$$1);
  8361. projectRotateTransform = compose(rotate, projectTransform);
  8362. projectResample = resample(projectTransform, delta2);
  8363. return reset();
  8364. }
  8365. function reset() {
  8366. cache = cacheStream = null;
  8367. return projection;
  8368. }
  8369. return function() {
  8370. project = projectAt.apply(this, arguments);
  8371. projection.invert = project.invert && invert;
  8372. return recenter();
  8373. };
  8374. }
  8375. function conicProjection(projectAt) {
  8376. var phi0 = 0,
  8377. phi1 = pi$3 / 3,
  8378. m = projectionMutator(projectAt),
  8379. p = m(phi0, phi1);
  8380. p.parallels = function(_) {
  8381. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8382. };
  8383. return p;
  8384. }
  8385. function cylindricalEqualAreaRaw(phi0) {
  8386. var cosPhi0 = cos$1(phi0);
  8387. function forward(lambda, phi) {
  8388. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8389. }
  8390. forward.invert = function(x, y) {
  8391. return [x / cosPhi0, asin(y * cosPhi0)];
  8392. };
  8393. return forward;
  8394. }
  8395. function conicEqualAreaRaw(y0, y1) {
  8396. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8397. // Are the parallels symmetrical around the Equator?
  8398. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8399. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8400. function project(x, y) {
  8401. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8402. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8403. }
  8404. project.invert = function(x, y) {
  8405. var r0y = r0 - y;
  8406. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8407. };
  8408. return project;
  8409. }
  8410. function conicEqualArea() {
  8411. return conicProjection(conicEqualAreaRaw)
  8412. .scale(155.424)
  8413. .center([0, 33.6442]);
  8414. }
  8415. function albers() {
  8416. return conicEqualArea()
  8417. .parallels([29.5, 45.5])
  8418. .scale(1070)
  8419. .translate([480, 250])
  8420. .rotate([96, 0])
  8421. .center([-0.6, 38.7]);
  8422. }
  8423. // The projections must have mutually exclusive clip regions on the sphere,
  8424. // as this will avoid emitting interleaving lines and polygons.
  8425. function multiplex(streams) {
  8426. var n = streams.length;
  8427. return {
  8428. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8429. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8430. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8431. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8432. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8433. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8434. };
  8435. }
  8436. // A composite projection for the United States, configured by default for
  8437. // 960×500. The projection also works quite well at 960×600 if you change the
  8438. // scale to 1285 and adjust the translate accordingly. The set of standard
  8439. // parallels for each region comes from USGS, which is published here:
  8440. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8441. function albersUsa() {
  8442. var cache,
  8443. cacheStream,
  8444. lower48 = albers(), lower48Point,
  8445. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8446. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8447. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8448. function albersUsa(coordinates) {
  8449. var x = coordinates[0], y = coordinates[1];
  8450. return point = null,
  8451. (lower48Point.point(x, y), point)
  8452. || (alaskaPoint.point(x, y), point)
  8453. || (hawaiiPoint.point(x, y), point);
  8454. }
  8455. albersUsa.invert = function(coordinates) {
  8456. var k = lower48.scale(),
  8457. t = lower48.translate(),
  8458. x = (coordinates[0] - t[0]) / k,
  8459. y = (coordinates[1] - t[1]) / k;
  8460. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8461. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8462. : lower48).invert(coordinates);
  8463. };
  8464. albersUsa.stream = function(stream) {
  8465. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8466. };
  8467. albersUsa.precision = function(_) {
  8468. if (!arguments.length) return lower48.precision();
  8469. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8470. return reset();
  8471. };
  8472. albersUsa.scale = function(_) {
  8473. if (!arguments.length) return lower48.scale();
  8474. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8475. return albersUsa.translate(lower48.translate());
  8476. };
  8477. albersUsa.translate = function(_) {
  8478. if (!arguments.length) return lower48.translate();
  8479. var k = lower48.scale(), x = +_[0], y = +_[1];
  8480. lower48Point = lower48
  8481. .translate(_)
  8482. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8483. .stream(pointStream);
  8484. alaskaPoint = alaska
  8485. .translate([x - 0.307 * k, y + 0.201 * k])
  8486. .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8487. .stream(pointStream);
  8488. hawaiiPoint = hawaii
  8489. .translate([x - 0.205 * k, y + 0.212 * k])
  8490. .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8491. .stream(pointStream);
  8492. return reset();
  8493. };
  8494. albersUsa.fitExtent = function(extent, object) {
  8495. return fitExtent(albersUsa, extent, object);
  8496. };
  8497. albersUsa.fitSize = function(size, object) {
  8498. return fitSize(albersUsa, size, object);
  8499. };
  8500. albersUsa.fitWidth = function(width, object) {
  8501. return fitWidth(albersUsa, width, object);
  8502. };
  8503. albersUsa.fitHeight = function(height, object) {
  8504. return fitHeight(albersUsa, height, object);
  8505. };
  8506. function reset() {
  8507. cache = cacheStream = null;
  8508. return albersUsa;
  8509. }
  8510. return albersUsa.scale(1070);
  8511. }
  8512. function azimuthalRaw(scale) {
  8513. return function(x, y) {
  8514. var cx = cos$1(x),
  8515. cy = cos$1(y),
  8516. k = scale(cx * cy);
  8517. return [
  8518. k * cy * sin$1(x),
  8519. k * sin$1(y)
  8520. ];
  8521. }
  8522. }
  8523. function azimuthalInvert(angle) {
  8524. return function(x, y) {
  8525. var z = sqrt(x * x + y * y),
  8526. c = angle(z),
  8527. sc = sin$1(c),
  8528. cc = cos$1(c);
  8529. return [
  8530. atan2(x * sc, z * cc),
  8531. asin(z && y * sc / z)
  8532. ];
  8533. }
  8534. }
  8535. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8536. return sqrt(2 / (1 + cxcy));
  8537. });
  8538. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8539. return 2 * asin(z / 2);
  8540. });
  8541. function azimuthalEqualArea() {
  8542. return projection(azimuthalEqualAreaRaw)
  8543. .scale(124.75)
  8544. .clipAngle(180 - 1e-3);
  8545. }
  8546. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8547. return (c = acos(c)) && c / sin$1(c);
  8548. });
  8549. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8550. return z;
  8551. });
  8552. function azimuthalEquidistant() {
  8553. return projection(azimuthalEquidistantRaw)
  8554. .scale(79.4188)
  8555. .clipAngle(180 - 1e-3);
  8556. }
  8557. function mercatorRaw(lambda, phi) {
  8558. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8559. }
  8560. mercatorRaw.invert = function(x, y) {
  8561. return [x, 2 * atan(exp(y)) - halfPi$2];
  8562. };
  8563. function mercator() {
  8564. return mercatorProjection(mercatorRaw)
  8565. .scale(961 / tau$3);
  8566. }
  8567. function mercatorProjection(project) {
  8568. var m = projection(project),
  8569. center = m.center,
  8570. scale = m.scale,
  8571. translate = m.translate,
  8572. clipExtent = m.clipExtent,
  8573. x0 = null, y0, x1, y1; // clip extent
  8574. m.scale = function(_) {
  8575. return arguments.length ? (scale(_), reclip()) : scale();
  8576. };
  8577. m.translate = function(_) {
  8578. return arguments.length ? (translate(_), reclip()) : translate();
  8579. };
  8580. m.center = function(_) {
  8581. return arguments.length ? (center(_), reclip()) : center();
  8582. };
  8583. m.clipExtent = function(_) {
  8584. 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]];
  8585. };
  8586. function reclip() {
  8587. var k = pi$3 * scale(),
  8588. t = m(rotation(m.rotate()).invert([0, 0]));
  8589. return clipExtent(x0 == null
  8590. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8591. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8592. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8593. }
  8594. return reclip();
  8595. }
  8596. function tany(y) {
  8597. return tan((halfPi$2 + y) / 2);
  8598. }
  8599. function conicConformalRaw(y0, y1) {
  8600. var cy0 = cos$1(y0),
  8601. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8602. f = cy0 * pow(tany(y0), n) / n;
  8603. if (!n) return mercatorRaw;
  8604. function project(x, y) {
  8605. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8606. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8607. var r = f / pow(tany(y), n);
  8608. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8609. }
  8610. project.invert = function(x, y) {
  8611. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8612. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8613. };
  8614. return project;
  8615. }
  8616. function conicConformal() {
  8617. return conicProjection(conicConformalRaw)
  8618. .scale(109.5)
  8619. .parallels([30, 30]);
  8620. }
  8621. function equirectangularRaw(lambda, phi) {
  8622. return [lambda, phi];
  8623. }
  8624. equirectangularRaw.invert = equirectangularRaw;
  8625. function equirectangular() {
  8626. return projection(equirectangularRaw)
  8627. .scale(152.63);
  8628. }
  8629. function conicEquidistantRaw(y0, y1) {
  8630. var cy0 = cos$1(y0),
  8631. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8632. g = cy0 / n + y0;
  8633. if (abs(n) < epsilon$2) return equirectangularRaw;
  8634. function project(x, y) {
  8635. var gy = g - y, nx = n * x;
  8636. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8637. }
  8638. project.invert = function(x, y) {
  8639. var gy = g - y;
  8640. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8641. };
  8642. return project;
  8643. }
  8644. function conicEquidistant() {
  8645. return conicProjection(conicEquidistantRaw)
  8646. .scale(131.154)
  8647. .center([0, 13.9389]);
  8648. }
  8649. var A1 = 1.340264,
  8650. A2 = -0.081106,
  8651. A3 = 0.000893,
  8652. A4 = 0.003796,
  8653. M = sqrt(3) / 2,
  8654. iterations = 12;
  8655. function equalEarthRaw(lambda, phi) {
  8656. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  8657. return [
  8658. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  8659. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  8660. ];
  8661. }
  8662. equalEarthRaw.invert = function(x, y) {
  8663. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  8664. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  8665. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  8666. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  8667. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  8668. if (abs(delta) < epsilon2$1) break;
  8669. }
  8670. return [
  8671. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  8672. asin(sin$1(l) / M)
  8673. ];
  8674. };
  8675. function equalEarth() {
  8676. return projection(equalEarthRaw)
  8677. .scale(177.158);
  8678. }
  8679. function gnomonicRaw(x, y) {
  8680. var cy = cos$1(y), k = cos$1(x) * cy;
  8681. return [cy * sin$1(x) / k, sin$1(y) / k];
  8682. }
  8683. gnomonicRaw.invert = azimuthalInvert(atan);
  8684. function gnomonic() {
  8685. return projection(gnomonicRaw)
  8686. .scale(144.049)
  8687. .clipAngle(60);
  8688. }
  8689. function scaleTranslate$1(kx, ky, tx, ty) {
  8690. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8691. point: function(x, y) {
  8692. this.stream.point(x * kx + tx, y * ky + ty);
  8693. }
  8694. });
  8695. }
  8696. function identity$5() {
  8697. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8698. x0 = null, y0, x1, y1, // clip extent
  8699. postclip = identity$4,
  8700. cache,
  8701. cacheStream,
  8702. projection;
  8703. function reset() {
  8704. cache = cacheStream = null;
  8705. return projection;
  8706. }
  8707. return projection = {
  8708. stream: function(stream) {
  8709. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8710. },
  8711. postclip: function(_) {
  8712. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8713. },
  8714. clipExtent: function(_) {
  8715. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8716. },
  8717. scale: function(_) {
  8718. return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8719. },
  8720. translate: function(_) {
  8721. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8722. },
  8723. reflectX: function(_) {
  8724. return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8725. },
  8726. reflectY: function(_) {
  8727. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8728. },
  8729. fitExtent: function(extent, object) {
  8730. return fitExtent(projection, extent, object);
  8731. },
  8732. fitSize: function(size, object) {
  8733. return fitSize(projection, size, object);
  8734. },
  8735. fitWidth: function(width, object) {
  8736. return fitWidth(projection, width, object);
  8737. },
  8738. fitHeight: function(height, object) {
  8739. return fitHeight(projection, height, object);
  8740. }
  8741. };
  8742. }
  8743. function naturalEarth1Raw(lambda, phi) {
  8744. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8745. return [
  8746. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8747. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8748. ];
  8749. }
  8750. naturalEarth1Raw.invert = function(x, y) {
  8751. var phi = y, i = 25, delta;
  8752. do {
  8753. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8754. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8755. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8756. } while (abs(delta) > epsilon$2 && --i > 0);
  8757. return [
  8758. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8759. phi
  8760. ];
  8761. };
  8762. function naturalEarth1() {
  8763. return projection(naturalEarth1Raw)
  8764. .scale(175.295);
  8765. }
  8766. function orthographicRaw(x, y) {
  8767. return [cos$1(y) * sin$1(x), sin$1(y)];
  8768. }
  8769. orthographicRaw.invert = azimuthalInvert(asin);
  8770. function orthographic() {
  8771. return projection(orthographicRaw)
  8772. .scale(249.5)
  8773. .clipAngle(90 + epsilon$2);
  8774. }
  8775. function stereographicRaw(x, y) {
  8776. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8777. return [cy * sin$1(x) / k, sin$1(y) / k];
  8778. }
  8779. stereographicRaw.invert = azimuthalInvert(function(z) {
  8780. return 2 * atan(z);
  8781. });
  8782. function stereographic() {
  8783. return projection(stereographicRaw)
  8784. .scale(250)
  8785. .clipAngle(142);
  8786. }
  8787. function transverseMercatorRaw(lambda, phi) {
  8788. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8789. }
  8790. transverseMercatorRaw.invert = function(x, y) {
  8791. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8792. };
  8793. function transverseMercator() {
  8794. var m = mercatorProjection(transverseMercatorRaw),
  8795. center = m.center,
  8796. rotate = m.rotate;
  8797. m.center = function(_) {
  8798. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8799. };
  8800. m.rotate = function(_) {
  8801. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8802. };
  8803. return rotate([0, 0, 90])
  8804. .scale(159.155);
  8805. }
  8806. function defaultSeparation(a, b) {
  8807. return a.parent === b.parent ? 1 : 2;
  8808. }
  8809. function meanX(children) {
  8810. return children.reduce(meanXReduce, 0) / children.length;
  8811. }
  8812. function meanXReduce(x, c) {
  8813. return x + c.x;
  8814. }
  8815. function maxY(children) {
  8816. return 1 + children.reduce(maxYReduce, 0);
  8817. }
  8818. function maxYReduce(y, c) {
  8819. return Math.max(y, c.y);
  8820. }
  8821. function leafLeft(node) {
  8822. var children;
  8823. while (children = node.children) node = children[0];
  8824. return node;
  8825. }
  8826. function leafRight(node) {
  8827. var children;
  8828. while (children = node.children) node = children[children.length - 1];
  8829. return node;
  8830. }
  8831. function cluster() {
  8832. var separation = defaultSeparation,
  8833. dx = 1,
  8834. dy = 1,
  8835. nodeSize = false;
  8836. function cluster(root) {
  8837. var previousNode,
  8838. x = 0;
  8839. // First walk, computing the initial x & y values.
  8840. root.eachAfter(function(node) {
  8841. var children = node.children;
  8842. if (children) {
  8843. node.x = meanX(children);
  8844. node.y = maxY(children);
  8845. } else {
  8846. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8847. node.y = 0;
  8848. previousNode = node;
  8849. }
  8850. });
  8851. var left = leafLeft(root),
  8852. right = leafRight(root),
  8853. x0 = left.x - separation(left, right) / 2,
  8854. x1 = right.x + separation(right, left) / 2;
  8855. // Second walk, normalizing x & y to the desired size.
  8856. return root.eachAfter(nodeSize ? function(node) {
  8857. node.x = (node.x - root.x) * dx;
  8858. node.y = (root.y - node.y) * dy;
  8859. } : function(node) {
  8860. node.x = (node.x - x0) / (x1 - x0) * dx;
  8861. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8862. });
  8863. }
  8864. cluster.separation = function(x) {
  8865. return arguments.length ? (separation = x, cluster) : separation;
  8866. };
  8867. cluster.size = function(x) {
  8868. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8869. };
  8870. cluster.nodeSize = function(x) {
  8871. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8872. };
  8873. return cluster;
  8874. }
  8875. function count(node) {
  8876. var sum = 0,
  8877. children = node.children,
  8878. i = children && children.length;
  8879. if (!i) sum = 1;
  8880. else while (--i >= 0) sum += children[i].value;
  8881. node.value = sum;
  8882. }
  8883. function node_count() {
  8884. return this.eachAfter(count);
  8885. }
  8886. function node_each(callback) {
  8887. var node = this, current, next = [node], children, i, n;
  8888. do {
  8889. current = next.reverse(), next = [];
  8890. while (node = current.pop()) {
  8891. callback(node), children = node.children;
  8892. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8893. next.push(children[i]);
  8894. }
  8895. }
  8896. } while (next.length);
  8897. return this;
  8898. }
  8899. function node_eachBefore(callback) {
  8900. var node = this, nodes = [node], children, i;
  8901. while (node = nodes.pop()) {
  8902. callback(node), children = node.children;
  8903. if (children) for (i = children.length - 1; i >= 0; --i) {
  8904. nodes.push(children[i]);
  8905. }
  8906. }
  8907. return this;
  8908. }
  8909. function node_eachAfter(callback) {
  8910. var node = this, nodes = [node], next = [], children, i, n;
  8911. while (node = nodes.pop()) {
  8912. next.push(node), children = node.children;
  8913. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8914. nodes.push(children[i]);
  8915. }
  8916. }
  8917. while (node = next.pop()) {
  8918. callback(node);
  8919. }
  8920. return this;
  8921. }
  8922. function node_sum(value) {
  8923. return this.eachAfter(function(node) {
  8924. var sum = +value(node.data) || 0,
  8925. children = node.children,
  8926. i = children && children.length;
  8927. while (--i >= 0) sum += children[i].value;
  8928. node.value = sum;
  8929. });
  8930. }
  8931. function node_sort(compare) {
  8932. return this.eachBefore(function(node) {
  8933. if (node.children) {
  8934. node.children.sort(compare);
  8935. }
  8936. });
  8937. }
  8938. function node_path(end) {
  8939. var start = this,
  8940. ancestor = leastCommonAncestor(start, end),
  8941. nodes = [start];
  8942. while (start !== ancestor) {
  8943. start = start.parent;
  8944. nodes.push(start);
  8945. }
  8946. var k = nodes.length;
  8947. while (end !== ancestor) {
  8948. nodes.splice(k, 0, end);
  8949. end = end.parent;
  8950. }
  8951. return nodes;
  8952. }
  8953. function leastCommonAncestor(a, b) {
  8954. if (a === b) return a;
  8955. var aNodes = a.ancestors(),
  8956. bNodes = b.ancestors(),
  8957. c = null;
  8958. a = aNodes.pop();
  8959. b = bNodes.pop();
  8960. while (a === b) {
  8961. c = a;
  8962. a = aNodes.pop();
  8963. b = bNodes.pop();
  8964. }
  8965. return c;
  8966. }
  8967. function node_ancestors() {
  8968. var node = this, nodes = [node];
  8969. while (node = node.parent) {
  8970. nodes.push(node);
  8971. }
  8972. return nodes;
  8973. }
  8974. function node_descendants() {
  8975. var nodes = [];
  8976. this.each(function(node) {
  8977. nodes.push(node);
  8978. });
  8979. return nodes;
  8980. }
  8981. function node_leaves() {
  8982. var leaves = [];
  8983. this.eachBefore(function(node) {
  8984. if (!node.children) {
  8985. leaves.push(node);
  8986. }
  8987. });
  8988. return leaves;
  8989. }
  8990. function node_links() {
  8991. var root = this, links = [];
  8992. root.each(function(node) {
  8993. if (node !== root) { // Don’t include the root’s parent, if any.
  8994. links.push({source: node.parent, target: node});
  8995. }
  8996. });
  8997. return links;
  8998. }
  8999. function hierarchy(data, children) {
  9000. var root = new Node(data),
  9001. valued = +data.value && (root.value = data.value),
  9002. node,
  9003. nodes = [root],
  9004. child,
  9005. childs,
  9006. i,
  9007. n;
  9008. if (children == null) children = defaultChildren;
  9009. while (node = nodes.pop()) {
  9010. if (valued) node.value = +node.data.value;
  9011. if ((childs = children(node.data)) && (n = childs.length)) {
  9012. node.children = new Array(n);
  9013. for (i = n - 1; i >= 0; --i) {
  9014. nodes.push(child = node.children[i] = new Node(childs[i]));
  9015. child.parent = node;
  9016. child.depth = node.depth + 1;
  9017. }
  9018. }
  9019. }
  9020. return root.eachBefore(computeHeight);
  9021. }
  9022. function node_copy() {
  9023. return hierarchy(this).eachBefore(copyData);
  9024. }
  9025. function defaultChildren(d) {
  9026. return d.children;
  9027. }
  9028. function copyData(node) {
  9029. node.data = node.data.data;
  9030. }
  9031. function computeHeight(node) {
  9032. var height = 0;
  9033. do node.height = height;
  9034. while ((node = node.parent) && (node.height < ++height));
  9035. }
  9036. function Node(data) {
  9037. this.data = data;
  9038. this.depth =
  9039. this.height = 0;
  9040. this.parent = null;
  9041. }
  9042. Node.prototype = hierarchy.prototype = {
  9043. constructor: Node,
  9044. count: node_count,
  9045. each: node_each,
  9046. eachAfter: node_eachAfter,
  9047. eachBefore: node_eachBefore,
  9048. sum: node_sum,
  9049. sort: node_sort,
  9050. path: node_path,
  9051. ancestors: node_ancestors,
  9052. descendants: node_descendants,
  9053. leaves: node_leaves,
  9054. links: node_links,
  9055. copy: node_copy
  9056. };
  9057. var slice$4 = Array.prototype.slice;
  9058. function shuffle$1(array) {
  9059. var m = array.length,
  9060. t,
  9061. i;
  9062. while (m) {
  9063. i = Math.random() * m-- | 0;
  9064. t = array[m];
  9065. array[m] = array[i];
  9066. array[i] = t;
  9067. }
  9068. return array;
  9069. }
  9070. function enclose(circles) {
  9071. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9072. while (i < n) {
  9073. p = circles[i];
  9074. if (e && enclosesWeak(e, p)) ++i;
  9075. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9076. }
  9077. return e;
  9078. }
  9079. function extendBasis(B, p) {
  9080. var i, j;
  9081. if (enclosesWeakAll(p, B)) return [p];
  9082. // If we get here then B must have at least one element.
  9083. for (i = 0; i < B.length; ++i) {
  9084. if (enclosesNot(p, B[i])
  9085. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9086. return [B[i], p];
  9087. }
  9088. }
  9089. // If we get here then B must have at least two elements.
  9090. for (i = 0; i < B.length - 1; ++i) {
  9091. for (j = i + 1; j < B.length; ++j) {
  9092. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9093. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9094. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9095. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9096. return [B[i], B[j], p];
  9097. }
  9098. }
  9099. }
  9100. // If we get here then something is very wrong.
  9101. throw new Error;
  9102. }
  9103. function enclosesNot(a, b) {
  9104. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9105. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9106. }
  9107. function enclosesWeak(a, b) {
  9108. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9109. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9110. }
  9111. function enclosesWeakAll(a, B) {
  9112. for (var i = 0; i < B.length; ++i) {
  9113. if (!enclosesWeak(a, B[i])) {
  9114. return false;
  9115. }
  9116. }
  9117. return true;
  9118. }
  9119. function encloseBasis(B) {
  9120. switch (B.length) {
  9121. case 1: return encloseBasis1(B[0]);
  9122. case 2: return encloseBasis2(B[0], B[1]);
  9123. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9124. }
  9125. }
  9126. function encloseBasis1(a) {
  9127. return {
  9128. x: a.x,
  9129. y: a.y,
  9130. r: a.r
  9131. };
  9132. }
  9133. function encloseBasis2(a, b) {
  9134. var x1 = a.x, y1 = a.y, r1 = a.r,
  9135. x2 = b.x, y2 = b.y, r2 = b.r,
  9136. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9137. l = Math.sqrt(x21 * x21 + y21 * y21);
  9138. return {
  9139. x: (x1 + x2 + x21 / l * r21) / 2,
  9140. y: (y1 + y2 + y21 / l * r21) / 2,
  9141. r: (l + r1 + r2) / 2
  9142. };
  9143. }
  9144. function encloseBasis3(a, b, c) {
  9145. var x1 = a.x, y1 = a.y, r1 = a.r,
  9146. x2 = b.x, y2 = b.y, r2 = b.r,
  9147. x3 = c.x, y3 = c.y, r3 = c.r,
  9148. a2 = x1 - x2,
  9149. a3 = x1 - x3,
  9150. b2 = y1 - y2,
  9151. b3 = y1 - y3,
  9152. c2 = r2 - r1,
  9153. c3 = r3 - r1,
  9154. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9155. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9156. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9157. ab = a3 * b2 - a2 * b3,
  9158. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9159. xb = (b3 * c2 - b2 * c3) / ab,
  9160. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9161. yb = (a2 * c3 - a3 * c2) / ab,
  9162. A = xb * xb + yb * yb - 1,
  9163. B = 2 * (r1 + xa * xb + ya * yb),
  9164. C = xa * xa + ya * ya - r1 * r1,
  9165. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9166. return {
  9167. x: x1 + xa + xb * r,
  9168. y: y1 + ya + yb * r,
  9169. r: r
  9170. };
  9171. }
  9172. function place(b, a, c) {
  9173. var dx = b.x - a.x, x, a2,
  9174. dy = b.y - a.y, y, b2,
  9175. d2 = dx * dx + dy * dy;
  9176. if (d2) {
  9177. a2 = a.r + c.r, a2 *= a2;
  9178. b2 = b.r + c.r, b2 *= b2;
  9179. if (a2 > b2) {
  9180. x = (d2 + b2 - a2) / (2 * d2);
  9181. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9182. c.x = b.x - x * dx - y * dy;
  9183. c.y = b.y - x * dy + y * dx;
  9184. } else {
  9185. x = (d2 + a2 - b2) / (2 * d2);
  9186. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9187. c.x = a.x + x * dx - y * dy;
  9188. c.y = a.y + x * dy + y * dx;
  9189. }
  9190. } else {
  9191. c.x = a.x + c.r;
  9192. c.y = a.y;
  9193. }
  9194. }
  9195. function intersects(a, b) {
  9196. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9197. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9198. }
  9199. function score(node) {
  9200. var a = node._,
  9201. b = node.next._,
  9202. ab = a.r + b.r,
  9203. dx = (a.x * b.r + b.x * a.r) / ab,
  9204. dy = (a.y * b.r + b.y * a.r) / ab;
  9205. return dx * dx + dy * dy;
  9206. }
  9207. function Node$1(circle) {
  9208. this._ = circle;
  9209. this.next = null;
  9210. this.previous = null;
  9211. }
  9212. function packEnclose(circles) {
  9213. if (!(n = circles.length)) return 0;
  9214. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9215. // Place the first circle.
  9216. a = circles[0], a.x = 0, a.y = 0;
  9217. if (!(n > 1)) return a.r;
  9218. // Place the second circle.
  9219. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9220. if (!(n > 2)) return a.r + b.r;
  9221. // Place the third circle.
  9222. place(b, a, c = circles[2]);
  9223. // Initialize the front-chain using the first three circles a, b and c.
  9224. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9225. a.next = c.previous = b;
  9226. b.next = a.previous = c;
  9227. c.next = b.previous = a;
  9228. // Attempt to place each remaining circle…
  9229. pack: for (i = 3; i < n; ++i) {
  9230. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9231. // Find the closest intersecting circle on the front-chain, if any.
  9232. // “Closeness” is determined by linear distance along the front-chain.
  9233. // “Ahead” or “behind” is likewise determined by linear distance.
  9234. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9235. do {
  9236. if (sj <= sk) {
  9237. if (intersects(j._, c._)) {
  9238. b = j, a.next = b, b.previous = a, --i;
  9239. continue pack;
  9240. }
  9241. sj += j._.r, j = j.next;
  9242. } else {
  9243. if (intersects(k._, c._)) {
  9244. a = k, a.next = b, b.previous = a, --i;
  9245. continue pack;
  9246. }
  9247. sk += k._.r, k = k.previous;
  9248. }
  9249. } while (j !== k.next);
  9250. // Success! Insert the new circle c between a and b.
  9251. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9252. // Compute the new closest circle pair to the centroid.
  9253. aa = score(a);
  9254. while ((c = c.next) !== b) {
  9255. if ((ca = score(c)) < aa) {
  9256. a = c, aa = ca;
  9257. }
  9258. }
  9259. b = a.next;
  9260. }
  9261. // Compute the enclosing circle of the front chain.
  9262. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9263. // Translate the circles to put the enclosing circle around the origin.
  9264. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9265. return c.r;
  9266. }
  9267. function siblings(circles) {
  9268. packEnclose(circles);
  9269. return circles;
  9270. }
  9271. function optional(f) {
  9272. return f == null ? null : required(f);
  9273. }
  9274. function required(f) {
  9275. if (typeof f !== "function") throw new Error;
  9276. return f;
  9277. }
  9278. function constantZero() {
  9279. return 0;
  9280. }
  9281. function constant$9(x) {
  9282. return function() {
  9283. return x;
  9284. };
  9285. }
  9286. function defaultRadius$1(d) {
  9287. return Math.sqrt(d.value);
  9288. }
  9289. function index$2() {
  9290. var radius = null,
  9291. dx = 1,
  9292. dy = 1,
  9293. padding = constantZero;
  9294. function pack(root) {
  9295. root.x = dx / 2, root.y = dy / 2;
  9296. if (radius) {
  9297. root.eachBefore(radiusLeaf(radius))
  9298. .eachAfter(packChildren(padding, 0.5))
  9299. .eachBefore(translateChild(1));
  9300. } else {
  9301. root.eachBefore(radiusLeaf(defaultRadius$1))
  9302. .eachAfter(packChildren(constantZero, 1))
  9303. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9304. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9305. }
  9306. return root;
  9307. }
  9308. pack.radius = function(x) {
  9309. return arguments.length ? (radius = optional(x), pack) : radius;
  9310. };
  9311. pack.size = function(x) {
  9312. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9313. };
  9314. pack.padding = function(x) {
  9315. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9316. };
  9317. return pack;
  9318. }
  9319. function radiusLeaf(radius) {
  9320. return function(node) {
  9321. if (!node.children) {
  9322. node.r = Math.max(0, +radius(node) || 0);
  9323. }
  9324. };
  9325. }
  9326. function packChildren(padding, k) {
  9327. return function(node) {
  9328. if (children = node.children) {
  9329. var children,
  9330. i,
  9331. n = children.length,
  9332. r = padding(node) * k || 0,
  9333. e;
  9334. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9335. e = packEnclose(children);
  9336. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9337. node.r = e + r;
  9338. }
  9339. };
  9340. }
  9341. function translateChild(k) {
  9342. return function(node) {
  9343. var parent = node.parent;
  9344. node.r *= k;
  9345. if (parent) {
  9346. node.x = parent.x + k * node.x;
  9347. node.y = parent.y + k * node.y;
  9348. }
  9349. };
  9350. }
  9351. function roundNode(node) {
  9352. node.x0 = Math.round(node.x0);
  9353. node.y0 = Math.round(node.y0);
  9354. node.x1 = Math.round(node.x1);
  9355. node.y1 = Math.round(node.y1);
  9356. }
  9357. function treemapDice(parent, x0, y0, x1, y1) {
  9358. var nodes = parent.children,
  9359. node,
  9360. i = -1,
  9361. n = nodes.length,
  9362. k = parent.value && (x1 - x0) / parent.value;
  9363. while (++i < n) {
  9364. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9365. node.x0 = x0, node.x1 = x0 += node.value * k;
  9366. }
  9367. }
  9368. function partition() {
  9369. var dx = 1,
  9370. dy = 1,
  9371. padding = 0,
  9372. round = false;
  9373. function partition(root) {
  9374. var n = root.height + 1;
  9375. root.x0 =
  9376. root.y0 = padding;
  9377. root.x1 = dx;
  9378. root.y1 = dy / n;
  9379. root.eachBefore(positionNode(dy, n));
  9380. if (round) root.eachBefore(roundNode);
  9381. return root;
  9382. }
  9383. function positionNode(dy, n) {
  9384. return function(node) {
  9385. if (node.children) {
  9386. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9387. }
  9388. var x0 = node.x0,
  9389. y0 = node.y0,
  9390. x1 = node.x1 - padding,
  9391. y1 = node.y1 - padding;
  9392. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9393. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9394. node.x0 = x0;
  9395. node.y0 = y0;
  9396. node.x1 = x1;
  9397. node.y1 = y1;
  9398. };
  9399. }
  9400. partition.round = function(x) {
  9401. return arguments.length ? (round = !!x, partition) : round;
  9402. };
  9403. partition.size = function(x) {
  9404. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9405. };
  9406. partition.padding = function(x) {
  9407. return arguments.length ? (padding = +x, partition) : padding;
  9408. };
  9409. return partition;
  9410. }
  9411. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9412. preroot = {depth: -1},
  9413. ambiguous = {};
  9414. function defaultId(d) {
  9415. return d.id;
  9416. }
  9417. function defaultParentId(d) {
  9418. return d.parentId;
  9419. }
  9420. function stratify() {
  9421. var id = defaultId,
  9422. parentId = defaultParentId;
  9423. function stratify(data) {
  9424. var d,
  9425. i,
  9426. n = data.length,
  9427. root,
  9428. parent,
  9429. node,
  9430. nodes = new Array(n),
  9431. nodeId,
  9432. nodeKey,
  9433. nodeByKey = {};
  9434. for (i = 0; i < n; ++i) {
  9435. d = data[i], node = nodes[i] = new Node(d);
  9436. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9437. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9438. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9439. }
  9440. }
  9441. for (i = 0; i < n; ++i) {
  9442. node = nodes[i], nodeId = parentId(data[i], i, data);
  9443. if (nodeId == null || !(nodeId += "")) {
  9444. if (root) throw new Error("multiple roots");
  9445. root = node;
  9446. } else {
  9447. parent = nodeByKey[keyPrefix$1 + nodeId];
  9448. if (!parent) throw new Error("missing: " + nodeId);
  9449. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9450. if (parent.children) parent.children.push(node);
  9451. else parent.children = [node];
  9452. node.parent = parent;
  9453. }
  9454. }
  9455. if (!root) throw new Error("no root");
  9456. root.parent = preroot;
  9457. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9458. root.parent = null;
  9459. if (n > 0) throw new Error("cycle");
  9460. return root;
  9461. }
  9462. stratify.id = function(x) {
  9463. return arguments.length ? (id = required(x), stratify) : id;
  9464. };
  9465. stratify.parentId = function(x) {
  9466. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9467. };
  9468. return stratify;
  9469. }
  9470. function defaultSeparation$1(a, b) {
  9471. return a.parent === b.parent ? 1 : 2;
  9472. }
  9473. // function radialSeparation(a, b) {
  9474. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9475. // }
  9476. // This function is used to traverse the left contour of a subtree (or
  9477. // subforest). It returns the successor of v on this contour. This successor is
  9478. // either given by the leftmost child of v or by the thread of v. The function
  9479. // returns null if and only if v is on the highest level of its subtree.
  9480. function nextLeft(v) {
  9481. var children = v.children;
  9482. return children ? children[0] : v.t;
  9483. }
  9484. // This function works analogously to nextLeft.
  9485. function nextRight(v) {
  9486. var children = v.children;
  9487. return children ? children[children.length - 1] : v.t;
  9488. }
  9489. // Shifts the current subtree rooted at w+. This is done by increasing
  9490. // prelim(w+) and mod(w+) by shift.
  9491. function moveSubtree(wm, wp, shift) {
  9492. var change = shift / (wp.i - wm.i);
  9493. wp.c -= change;
  9494. wp.s += shift;
  9495. wm.c += change;
  9496. wp.z += shift;
  9497. wp.m += shift;
  9498. }
  9499. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9500. // performed by this function. To prepare the shifts, we have to adjust
  9501. // change(w+), shift(w+), and change(w-).
  9502. function executeShifts(v) {
  9503. var shift = 0,
  9504. change = 0,
  9505. children = v.children,
  9506. i = children.length,
  9507. w;
  9508. while (--i >= 0) {
  9509. w = children[i];
  9510. w.z += shift;
  9511. w.m += shift;
  9512. shift += w.s + (change += w.c);
  9513. }
  9514. }
  9515. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9516. // returns the specified (default) ancestor.
  9517. function nextAncestor(vim, v, ancestor) {
  9518. return vim.a.parent === v.parent ? vim.a : ancestor;
  9519. }
  9520. function TreeNode(node, i) {
  9521. this._ = node;
  9522. this.parent = null;
  9523. this.children = null;
  9524. this.A = null; // default ancestor
  9525. this.a = this; // ancestor
  9526. this.z = 0; // prelim
  9527. this.m = 0; // mod
  9528. this.c = 0; // change
  9529. this.s = 0; // shift
  9530. this.t = null; // thread
  9531. this.i = i; // number
  9532. }
  9533. TreeNode.prototype = Object.create(Node.prototype);
  9534. function treeRoot(root) {
  9535. var tree = new TreeNode(root, 0),
  9536. node,
  9537. nodes = [tree],
  9538. child,
  9539. children,
  9540. i,
  9541. n;
  9542. while (node = nodes.pop()) {
  9543. if (children = node._.children) {
  9544. node.children = new Array(n = children.length);
  9545. for (i = n - 1; i >= 0; --i) {
  9546. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9547. child.parent = node;
  9548. }
  9549. }
  9550. }
  9551. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9552. return tree;
  9553. }
  9554. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9555. function tree() {
  9556. var separation = defaultSeparation$1,
  9557. dx = 1,
  9558. dy = 1,
  9559. nodeSize = null;
  9560. function tree(root) {
  9561. var t = treeRoot(root);
  9562. // Compute the layout using Buchheim et al.’s algorithm.
  9563. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9564. t.eachBefore(secondWalk);
  9565. // If a fixed node size is specified, scale x and y.
  9566. if (nodeSize) root.eachBefore(sizeNode);
  9567. // If a fixed tree size is specified, scale x and y based on the extent.
  9568. // Compute the left-most, right-most, and depth-most nodes for extents.
  9569. else {
  9570. var left = root,
  9571. right = root,
  9572. bottom = root;
  9573. root.eachBefore(function(node) {
  9574. if (node.x < left.x) left = node;
  9575. if (node.x > right.x) right = node;
  9576. if (node.depth > bottom.depth) bottom = node;
  9577. });
  9578. var s = left === right ? 1 : separation(left, right) / 2,
  9579. tx = s - left.x,
  9580. kx = dx / (right.x + s + tx),
  9581. ky = dy / (bottom.depth || 1);
  9582. root.eachBefore(function(node) {
  9583. node.x = (node.x + tx) * kx;
  9584. node.y = node.depth * ky;
  9585. });
  9586. }
  9587. return root;
  9588. }
  9589. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9590. // applied recursively to the children of v, as well as the function
  9591. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9592. // node v is placed to the midpoint of its outermost children.
  9593. function firstWalk(v) {
  9594. var children = v.children,
  9595. siblings = v.parent.children,
  9596. w = v.i ? siblings[v.i - 1] : null;
  9597. if (children) {
  9598. executeShifts(v);
  9599. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9600. if (w) {
  9601. v.z = w.z + separation(v._, w._);
  9602. v.m = v.z - midpoint;
  9603. } else {
  9604. v.z = midpoint;
  9605. }
  9606. } else if (w) {
  9607. v.z = w.z + separation(v._, w._);
  9608. }
  9609. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9610. }
  9611. // Computes all real x-coordinates by summing up the modifiers recursively.
  9612. function secondWalk(v) {
  9613. v._.x = v.z + v.parent.m;
  9614. v.m += v.parent.m;
  9615. }
  9616. // The core of the algorithm. Here, a new subtree is combined with the
  9617. // previous subtrees. Threads are used to traverse the inside and outside
  9618. // contours of the left and right subtree up to the highest common level. The
  9619. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9620. // superscript o means outside and i means inside, the subscript - means left
  9621. // subtree and + means right subtree. For summing up the modifiers along the
  9622. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9623. // nodes of the inside contours conflict, we compute the left one of the
  9624. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9625. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9626. // Finally, we add a new thread (if necessary).
  9627. function apportion(v, w, ancestor) {
  9628. if (w) {
  9629. var vip = v,
  9630. vop = v,
  9631. vim = w,
  9632. vom = vip.parent.children[0],
  9633. sip = vip.m,
  9634. sop = vop.m,
  9635. sim = vim.m,
  9636. som = vom.m,
  9637. shift;
  9638. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9639. vom = nextLeft(vom);
  9640. vop = nextRight(vop);
  9641. vop.a = v;
  9642. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9643. if (shift > 0) {
  9644. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9645. sip += shift;
  9646. sop += shift;
  9647. }
  9648. sim += vim.m;
  9649. sip += vip.m;
  9650. som += vom.m;
  9651. sop += vop.m;
  9652. }
  9653. if (vim && !nextRight(vop)) {
  9654. vop.t = vim;
  9655. vop.m += sim - sop;
  9656. }
  9657. if (vip && !nextLeft(vom)) {
  9658. vom.t = vip;
  9659. vom.m += sip - som;
  9660. ancestor = v;
  9661. }
  9662. }
  9663. return ancestor;
  9664. }
  9665. function sizeNode(node) {
  9666. node.x *= dx;
  9667. node.y = node.depth * dy;
  9668. }
  9669. tree.separation = function(x) {
  9670. return arguments.length ? (separation = x, tree) : separation;
  9671. };
  9672. tree.size = function(x) {
  9673. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9674. };
  9675. tree.nodeSize = function(x) {
  9676. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9677. };
  9678. return tree;
  9679. }
  9680. function treemapSlice(parent, x0, y0, x1, y1) {
  9681. var nodes = parent.children,
  9682. node,
  9683. i = -1,
  9684. n = nodes.length,
  9685. k = parent.value && (y1 - y0) / parent.value;
  9686. while (++i < n) {
  9687. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9688. node.y0 = y0, node.y1 = y0 += node.value * k;
  9689. }
  9690. }
  9691. var phi = (1 + Math.sqrt(5)) / 2;
  9692. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9693. var rows = [],
  9694. nodes = parent.children,
  9695. row,
  9696. nodeValue,
  9697. i0 = 0,
  9698. i1 = 0,
  9699. n = nodes.length,
  9700. dx, dy,
  9701. value = parent.value,
  9702. sumValue,
  9703. minValue,
  9704. maxValue,
  9705. newRatio,
  9706. minRatio,
  9707. alpha,
  9708. beta;
  9709. while (i0 < n) {
  9710. dx = x1 - x0, dy = y1 - y0;
  9711. // Find the next non-empty node.
  9712. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9713. minValue = maxValue = sumValue;
  9714. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9715. beta = sumValue * sumValue * alpha;
  9716. minRatio = Math.max(maxValue / beta, beta / minValue);
  9717. // Keep adding nodes while the aspect ratio maintains or improves.
  9718. for (; i1 < n; ++i1) {
  9719. sumValue += nodeValue = nodes[i1].value;
  9720. if (nodeValue < minValue) minValue = nodeValue;
  9721. if (nodeValue > maxValue) maxValue = nodeValue;
  9722. beta = sumValue * sumValue * alpha;
  9723. newRatio = Math.max(maxValue / beta, beta / minValue);
  9724. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9725. minRatio = newRatio;
  9726. }
  9727. // Position and record the row orientation.
  9728. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9729. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9730. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9731. value -= sumValue, i0 = i1;
  9732. }
  9733. return rows;
  9734. }
  9735. var squarify = (function custom(ratio) {
  9736. function squarify(parent, x0, y0, x1, y1) {
  9737. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9738. }
  9739. squarify.ratio = function(x) {
  9740. return custom((x = +x) > 1 ? x : 1);
  9741. };
  9742. return squarify;
  9743. })(phi);
  9744. function index$3() {
  9745. var tile = squarify,
  9746. round = false,
  9747. dx = 1,
  9748. dy = 1,
  9749. paddingStack = [0],
  9750. paddingInner = constantZero,
  9751. paddingTop = constantZero,
  9752. paddingRight = constantZero,
  9753. paddingBottom = constantZero,
  9754. paddingLeft = constantZero;
  9755. function treemap(root) {
  9756. root.x0 =
  9757. root.y0 = 0;
  9758. root.x1 = dx;
  9759. root.y1 = dy;
  9760. root.eachBefore(positionNode);
  9761. paddingStack = [0];
  9762. if (round) root.eachBefore(roundNode);
  9763. return root;
  9764. }
  9765. function positionNode(node) {
  9766. var p = paddingStack[node.depth],
  9767. x0 = node.x0 + p,
  9768. y0 = node.y0 + p,
  9769. x1 = node.x1 - p,
  9770. y1 = node.y1 - p;
  9771. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9772. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9773. node.x0 = x0;
  9774. node.y0 = y0;
  9775. node.x1 = x1;
  9776. node.y1 = y1;
  9777. if (node.children) {
  9778. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9779. x0 += paddingLeft(node) - p;
  9780. y0 += paddingTop(node) - p;
  9781. x1 -= paddingRight(node) - p;
  9782. y1 -= paddingBottom(node) - p;
  9783. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9784. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9785. tile(node, x0, y0, x1, y1);
  9786. }
  9787. }
  9788. treemap.round = function(x) {
  9789. return arguments.length ? (round = !!x, treemap) : round;
  9790. };
  9791. treemap.size = function(x) {
  9792. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9793. };
  9794. treemap.tile = function(x) {
  9795. return arguments.length ? (tile = required(x), treemap) : tile;
  9796. };
  9797. treemap.padding = function(x) {
  9798. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9799. };
  9800. treemap.paddingInner = function(x) {
  9801. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9802. };
  9803. treemap.paddingOuter = function(x) {
  9804. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9805. };
  9806. treemap.paddingTop = function(x) {
  9807. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9808. };
  9809. treemap.paddingRight = function(x) {
  9810. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9811. };
  9812. treemap.paddingBottom = function(x) {
  9813. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  9814. };
  9815. treemap.paddingLeft = function(x) {
  9816. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  9817. };
  9818. return treemap;
  9819. }
  9820. function binary(parent, x0, y0, x1, y1) {
  9821. var nodes = parent.children,
  9822. i, n = nodes.length,
  9823. sum, sums = new Array(n + 1);
  9824. for (sums[0] = sum = i = 0; i < n; ++i) {
  9825. sums[i + 1] = sum += nodes[i].value;
  9826. }
  9827. partition(0, n, parent.value, x0, y0, x1, y1);
  9828. function partition(i, j, value, x0, y0, x1, y1) {
  9829. if (i >= j - 1) {
  9830. var node = nodes[i];
  9831. node.x0 = x0, node.y0 = y0;
  9832. node.x1 = x1, node.y1 = y1;
  9833. return;
  9834. }
  9835. var valueOffset = sums[i],
  9836. valueTarget = (value / 2) + valueOffset,
  9837. k = i + 1,
  9838. hi = j - 1;
  9839. while (k < hi) {
  9840. var mid = k + hi >>> 1;
  9841. if (sums[mid] < valueTarget) k = mid + 1;
  9842. else hi = mid;
  9843. }
  9844. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9845. var valueLeft = sums[k] - valueOffset,
  9846. valueRight = value - valueLeft;
  9847. if ((x1 - x0) > (y1 - y0)) {
  9848. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9849. partition(i, k, valueLeft, x0, y0, xk, y1);
  9850. partition(k, j, valueRight, xk, y0, x1, y1);
  9851. } else {
  9852. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9853. partition(i, k, valueLeft, x0, y0, x1, yk);
  9854. partition(k, j, valueRight, x0, yk, x1, y1);
  9855. }
  9856. }
  9857. }
  9858. function sliceDice(parent, x0, y0, x1, y1) {
  9859. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9860. }
  9861. var resquarify = (function custom(ratio) {
  9862. function resquarify(parent, x0, y0, x1, y1) {
  9863. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9864. var rows,
  9865. row,
  9866. nodes,
  9867. i,
  9868. j = -1,
  9869. n,
  9870. m = rows.length,
  9871. value = parent.value;
  9872. while (++j < m) {
  9873. row = rows[j], nodes = row.children;
  9874. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9875. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9876. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9877. value -= row.value;
  9878. }
  9879. } else {
  9880. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9881. rows.ratio = ratio;
  9882. }
  9883. }
  9884. resquarify.ratio = function(x) {
  9885. return custom((x = +x) > 1 ? x : 1);
  9886. };
  9887. return resquarify;
  9888. })(phi);
  9889. function area$2(polygon) {
  9890. var i = -1,
  9891. n = polygon.length,
  9892. a,
  9893. b = polygon[n - 1],
  9894. area = 0;
  9895. while (++i < n) {
  9896. a = b;
  9897. b = polygon[i];
  9898. area += a[1] * b[0] - a[0] * b[1];
  9899. }
  9900. return area / 2;
  9901. }
  9902. function centroid$1(polygon) {
  9903. var i = -1,
  9904. n = polygon.length,
  9905. x = 0,
  9906. y = 0,
  9907. a,
  9908. b = polygon[n - 1],
  9909. c,
  9910. k = 0;
  9911. while (++i < n) {
  9912. a = b;
  9913. b = polygon[i];
  9914. k += c = a[0] * b[1] - b[0] * a[1];
  9915. x += (a[0] + b[0]) * c;
  9916. y += (a[1] + b[1]) * c;
  9917. }
  9918. return k *= 3, [x / k, y / k];
  9919. }
  9920. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9921. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9922. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9923. // negative if clockwise, and zero if the points are collinear.
  9924. function cross$1(a, b, c) {
  9925. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9926. }
  9927. function lexicographicOrder(a, b) {
  9928. return a[0] - b[0] || a[1] - b[1];
  9929. }
  9930. // Computes the upper convex hull per the monotone chain algorithm.
  9931. // Assumes points.length >= 3, is sorted by x, unique in y.
  9932. // Returns an array of indices into points in left-to-right order.
  9933. function computeUpperHullIndexes(points) {
  9934. var n = points.length,
  9935. indexes = [0, 1],
  9936. size = 2;
  9937. for (var i = 2; i < n; ++i) {
  9938. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9939. indexes[size++] = i;
  9940. }
  9941. return indexes.slice(0, size); // remove popped points
  9942. }
  9943. function hull(points) {
  9944. if ((n = points.length) < 3) return null;
  9945. var i,
  9946. n,
  9947. sortedPoints = new Array(n),
  9948. flippedPoints = new Array(n);
  9949. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9950. sortedPoints.sort(lexicographicOrder);
  9951. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9952. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9953. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9954. // Construct the hull polygon, removing possible duplicate endpoints.
  9955. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9956. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9957. hull = [];
  9958. // Add upper hull in right-to-l order.
  9959. // Then add lower hull in left-to-right order.
  9960. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9961. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9962. return hull;
  9963. }
  9964. function contains$2(polygon, point) {
  9965. var n = polygon.length,
  9966. p = polygon[n - 1],
  9967. x = point[0], y = point[1],
  9968. x0 = p[0], y0 = p[1],
  9969. x1, y1,
  9970. inside = false;
  9971. for (var i = 0; i < n; ++i) {
  9972. p = polygon[i], x1 = p[0], y1 = p[1];
  9973. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9974. x0 = x1, y0 = y1;
  9975. }
  9976. return inside;
  9977. }
  9978. function length$2(polygon) {
  9979. var i = -1,
  9980. n = polygon.length,
  9981. b = polygon[n - 1],
  9982. xa,
  9983. ya,
  9984. xb = b[0],
  9985. yb = b[1],
  9986. perimeter = 0;
  9987. while (++i < n) {
  9988. xa = xb;
  9989. ya = yb;
  9990. b = polygon[i];
  9991. xb = b[0];
  9992. yb = b[1];
  9993. xa -= xb;
  9994. ya -= yb;
  9995. perimeter += Math.sqrt(xa * xa + ya * ya);
  9996. }
  9997. return perimeter;
  9998. }
  9999. function defaultSource$1() {
  10000. return Math.random();
  10001. }
  10002. var uniform = (function sourceRandomUniform(source) {
  10003. function randomUniform(min, max) {
  10004. min = min == null ? 0 : +min;
  10005. max = max == null ? 1 : +max;
  10006. if (arguments.length === 1) max = min, min = 0;
  10007. else max -= min;
  10008. return function() {
  10009. return source() * max + min;
  10010. };
  10011. }
  10012. randomUniform.source = sourceRandomUniform;
  10013. return randomUniform;
  10014. })(defaultSource$1);
  10015. var normal = (function sourceRandomNormal(source) {
  10016. function randomNormal(mu, sigma) {
  10017. var x, r;
  10018. mu = mu == null ? 0 : +mu;
  10019. sigma = sigma == null ? 1 : +sigma;
  10020. return function() {
  10021. var y;
  10022. // If available, use the second previously-generated uniform random.
  10023. if (x != null) y = x, x = null;
  10024. // Otherwise, generate a new x and y.
  10025. else do {
  10026. x = source() * 2 - 1;
  10027. y = source() * 2 - 1;
  10028. r = x * x + y * y;
  10029. } while (!r || r > 1);
  10030. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  10031. };
  10032. }
  10033. randomNormal.source = sourceRandomNormal;
  10034. return randomNormal;
  10035. })(defaultSource$1);
  10036. var logNormal = (function sourceRandomLogNormal(source) {
  10037. function randomLogNormal() {
  10038. var randomNormal = normal.source(source).apply(this, arguments);
  10039. return function() {
  10040. return Math.exp(randomNormal());
  10041. };
  10042. }
  10043. randomLogNormal.source = sourceRandomLogNormal;
  10044. return randomLogNormal;
  10045. })(defaultSource$1);
  10046. var irwinHall = (function sourceRandomIrwinHall(source) {
  10047. function randomIrwinHall(n) {
  10048. return function() {
  10049. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10050. return sum;
  10051. };
  10052. }
  10053. randomIrwinHall.source = sourceRandomIrwinHall;
  10054. return randomIrwinHall;
  10055. })(defaultSource$1);
  10056. var bates = (function sourceRandomBates(source) {
  10057. function randomBates(n) {
  10058. var randomIrwinHall = irwinHall.source(source)(n);
  10059. return function() {
  10060. return randomIrwinHall() / n;
  10061. };
  10062. }
  10063. randomBates.source = sourceRandomBates;
  10064. return randomBates;
  10065. })(defaultSource$1);
  10066. var exponential$1 = (function sourceRandomExponential(source) {
  10067. function randomExponential(lambda) {
  10068. return function() {
  10069. return -Math.log(1 - source()) / lambda;
  10070. };
  10071. }
  10072. randomExponential.source = sourceRandomExponential;
  10073. return randomExponential;
  10074. })(defaultSource$1);
  10075. var array$3 = Array.prototype;
  10076. var map$2 = array$3.map;
  10077. var slice$5 = array$3.slice;
  10078. var implicit = {name: "implicit"};
  10079. function ordinal(range) {
  10080. var index = map$1(),
  10081. domain = [],
  10082. unknown = implicit;
  10083. range = range == null ? [] : slice$5.call(range);
  10084. function scale(d) {
  10085. var key = d + "", i = index.get(key);
  10086. if (!i) {
  10087. if (unknown !== implicit) return unknown;
  10088. index.set(key, i = domain.push(d));
  10089. }
  10090. return range[(i - 1) % range.length];
  10091. }
  10092. scale.domain = function(_) {
  10093. if (!arguments.length) return domain.slice();
  10094. domain = [], index = map$1();
  10095. var i = -1, n = _.length, d, key;
  10096. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10097. return scale;
  10098. };
  10099. scale.range = function(_) {
  10100. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10101. };
  10102. scale.unknown = function(_) {
  10103. return arguments.length ? (unknown = _, scale) : unknown;
  10104. };
  10105. scale.copy = function() {
  10106. return ordinal()
  10107. .domain(domain)
  10108. .range(range)
  10109. .unknown(unknown);
  10110. };
  10111. return scale;
  10112. }
  10113. function band() {
  10114. var scale = ordinal().unknown(undefined),
  10115. domain = scale.domain,
  10116. ordinalRange = scale.range,
  10117. range$$1 = [0, 1],
  10118. step,
  10119. bandwidth,
  10120. round = false,
  10121. paddingInner = 0,
  10122. paddingOuter = 0,
  10123. align = 0.5;
  10124. delete scale.unknown;
  10125. function rescale() {
  10126. var n = domain().length,
  10127. reverse = range$$1[1] < range$$1[0],
  10128. start = range$$1[reverse - 0],
  10129. stop = range$$1[1 - reverse];
  10130. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10131. if (round) step = Math.floor(step);
  10132. start += (stop - start - step * (n - paddingInner)) * align;
  10133. bandwidth = step * (1 - paddingInner);
  10134. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10135. var values = sequence(n).map(function(i) { return start + step * i; });
  10136. return ordinalRange(reverse ? values.reverse() : values);
  10137. }
  10138. scale.domain = function(_) {
  10139. return arguments.length ? (domain(_), rescale()) : domain();
  10140. };
  10141. scale.range = function(_) {
  10142. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  10143. };
  10144. scale.rangeRound = function(_) {
  10145. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  10146. };
  10147. scale.bandwidth = function() {
  10148. return bandwidth;
  10149. };
  10150. scale.step = function() {
  10151. return step;
  10152. };
  10153. scale.round = function(_) {
  10154. return arguments.length ? (round = !!_, rescale()) : round;
  10155. };
  10156. scale.padding = function(_) {
  10157. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10158. };
  10159. scale.paddingInner = function(_) {
  10160. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10161. };
  10162. scale.paddingOuter = function(_) {
  10163. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  10164. };
  10165. scale.align = function(_) {
  10166. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10167. };
  10168. scale.copy = function() {
  10169. return band()
  10170. .domain(domain())
  10171. .range(range$$1)
  10172. .round(round)
  10173. .paddingInner(paddingInner)
  10174. .paddingOuter(paddingOuter)
  10175. .align(align);
  10176. };
  10177. return rescale();
  10178. }
  10179. function pointish(scale) {
  10180. var copy = scale.copy;
  10181. scale.padding = scale.paddingOuter;
  10182. delete scale.paddingInner;
  10183. delete scale.paddingOuter;
  10184. scale.copy = function() {
  10185. return pointish(copy());
  10186. };
  10187. return scale;
  10188. }
  10189. function point$1() {
  10190. return pointish(band().paddingInner(1));
  10191. }
  10192. function constant$a(x) {
  10193. return function() {
  10194. return x;
  10195. };
  10196. }
  10197. function number$2(x) {
  10198. return +x;
  10199. }
  10200. var unit = [0, 1];
  10201. function deinterpolateLinear(a, b) {
  10202. return (b -= (a = +a))
  10203. ? function(x) { return (x - a) / b; }
  10204. : constant$a(b);
  10205. }
  10206. function deinterpolateClamp(deinterpolate) {
  10207. return function(a, b) {
  10208. var d = deinterpolate(a = +a, b = +b);
  10209. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  10210. };
  10211. }
  10212. function reinterpolateClamp(reinterpolate) {
  10213. return function(a, b) {
  10214. var r = reinterpolate(a = +a, b = +b);
  10215. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  10216. };
  10217. }
  10218. function bimap(domain, range, deinterpolate, reinterpolate) {
  10219. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10220. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  10221. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  10222. return function(x) { return r0(d0(x)); };
  10223. }
  10224. function polymap(domain, range, deinterpolate, reinterpolate) {
  10225. var j = Math.min(domain.length, range.length) - 1,
  10226. d = new Array(j),
  10227. r = new Array(j),
  10228. i = -1;
  10229. // Reverse descending domains.
  10230. if (domain[j] < domain[0]) {
  10231. domain = domain.slice().reverse();
  10232. range = range.slice().reverse();
  10233. }
  10234. while (++i < j) {
  10235. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10236. r[i] = reinterpolate(range[i], range[i + 1]);
  10237. }
  10238. return function(x) {
  10239. var i = bisectRight(domain, x, 1, j) - 1;
  10240. return r[i](d[i](x));
  10241. };
  10242. }
  10243. function copy(source, target) {
  10244. return target
  10245. .domain(source.domain())
  10246. .range(source.range())
  10247. .interpolate(source.interpolate())
  10248. .clamp(source.clamp());
  10249. }
  10250. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10251. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10252. function continuous(deinterpolate, reinterpolate) {
  10253. var domain = unit,
  10254. range = unit,
  10255. interpolate$$1 = interpolateValue,
  10256. clamp = false,
  10257. piecewise$$1,
  10258. output,
  10259. input;
  10260. function rescale() {
  10261. piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10262. output = input = null;
  10263. return scale;
  10264. }
  10265. function scale(x) {
  10266. return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10267. }
  10268. scale.invert = function(y) {
  10269. return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  10270. };
  10271. scale.domain = function(_) {
  10272. return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
  10273. };
  10274. scale.range = function(_) {
  10275. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10276. };
  10277. scale.rangeRound = function(_) {
  10278. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10279. };
  10280. scale.clamp = function(_) {
  10281. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10282. };
  10283. scale.interpolate = function(_) {
  10284. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10285. };
  10286. return rescale();
  10287. }
  10288. function tickFormat(domain, count, specifier) {
  10289. var start = domain[0],
  10290. stop = domain[domain.length - 1],
  10291. step = tickStep(start, stop, count == null ? 10 : count),
  10292. precision;
  10293. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10294. switch (specifier.type) {
  10295. case "s": {
  10296. var value = Math.max(Math.abs(start), Math.abs(stop));
  10297. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10298. return exports.formatPrefix(specifier, value);
  10299. }
  10300. case "":
  10301. case "e":
  10302. case "g":
  10303. case "p":
  10304. case "r": {
  10305. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10306. break;
  10307. }
  10308. case "f":
  10309. case "%": {
  10310. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10311. break;
  10312. }
  10313. }
  10314. return exports.format(specifier);
  10315. }
  10316. function linearish(scale) {
  10317. var domain = scale.domain;
  10318. scale.ticks = function(count) {
  10319. var d = domain();
  10320. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10321. };
  10322. scale.tickFormat = function(count, specifier) {
  10323. return tickFormat(domain(), count, specifier);
  10324. };
  10325. scale.nice = function(count) {
  10326. if (count == null) count = 10;
  10327. var d = domain(),
  10328. i0 = 0,
  10329. i1 = d.length - 1,
  10330. start = d[i0],
  10331. stop = d[i1],
  10332. step;
  10333. if (stop < start) {
  10334. step = start, start = stop, stop = step;
  10335. step = i0, i0 = i1, i1 = step;
  10336. }
  10337. step = tickIncrement(start, stop, count);
  10338. if (step > 0) {
  10339. start = Math.floor(start / step) * step;
  10340. stop = Math.ceil(stop / step) * step;
  10341. step = tickIncrement(start, stop, count);
  10342. } else if (step < 0) {
  10343. start = Math.ceil(start * step) / step;
  10344. stop = Math.floor(stop * step) / step;
  10345. step = tickIncrement(start, stop, count);
  10346. }
  10347. if (step > 0) {
  10348. d[i0] = Math.floor(start / step) * step;
  10349. d[i1] = Math.ceil(stop / step) * step;
  10350. domain(d);
  10351. } else if (step < 0) {
  10352. d[i0] = Math.ceil(start * step) / step;
  10353. d[i1] = Math.floor(stop * step) / step;
  10354. domain(d);
  10355. }
  10356. return scale;
  10357. };
  10358. return scale;
  10359. }
  10360. function linear$2() {
  10361. var scale = continuous(deinterpolateLinear, interpolateNumber);
  10362. scale.copy = function() {
  10363. return copy(scale, linear$2());
  10364. };
  10365. return linearish(scale);
  10366. }
  10367. function identity$6() {
  10368. var domain = [0, 1];
  10369. function scale(x) {
  10370. return +x;
  10371. }
  10372. scale.invert = scale;
  10373. scale.domain = scale.range = function(_) {
  10374. return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
  10375. };
  10376. scale.copy = function() {
  10377. return identity$6().domain(domain);
  10378. };
  10379. return linearish(scale);
  10380. }
  10381. function nice(domain, interval) {
  10382. domain = domain.slice();
  10383. var i0 = 0,
  10384. i1 = domain.length - 1,
  10385. x0 = domain[i0],
  10386. x1 = domain[i1],
  10387. t;
  10388. if (x1 < x0) {
  10389. t = i0, i0 = i1, i1 = t;
  10390. t = x0, x0 = x1, x1 = t;
  10391. }
  10392. domain[i0] = interval.floor(x0);
  10393. domain[i1] = interval.ceil(x1);
  10394. return domain;
  10395. }
  10396. function deinterpolate(a, b) {
  10397. return (b = Math.log(b / a))
  10398. ? function(x) { return Math.log(x / a) / b; }
  10399. : constant$a(b);
  10400. }
  10401. function reinterpolate(a, b) {
  10402. return a < 0
  10403. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10404. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10405. }
  10406. function pow10(x) {
  10407. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10408. }
  10409. function powp(base) {
  10410. return base === 10 ? pow10
  10411. : base === Math.E ? Math.exp
  10412. : function(x) { return Math.pow(base, x); };
  10413. }
  10414. function logp(base) {
  10415. return base === Math.E ? Math.log
  10416. : base === 10 && Math.log10
  10417. || base === 2 && Math.log2
  10418. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10419. }
  10420. function reflect(f) {
  10421. return function(x) {
  10422. return -f(-x);
  10423. };
  10424. }
  10425. function log$1() {
  10426. var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]),
  10427. domain = scale.domain,
  10428. base = 10,
  10429. logs = logp(10),
  10430. pows = powp(10);
  10431. function rescale() {
  10432. logs = logp(base), pows = powp(base);
  10433. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10434. return scale;
  10435. }
  10436. scale.base = function(_) {
  10437. return arguments.length ? (base = +_, rescale()) : base;
  10438. };
  10439. scale.domain = function(_) {
  10440. return arguments.length ? (domain(_), rescale()) : domain();
  10441. };
  10442. scale.ticks = function(count) {
  10443. var d = domain(),
  10444. u = d[0],
  10445. v = d[d.length - 1],
  10446. r;
  10447. if (r = v < u) i = u, u = v, v = i;
  10448. var i = logs(u),
  10449. j = logs(v),
  10450. p,
  10451. k,
  10452. t,
  10453. n = count == null ? 10 : +count,
  10454. z = [];
  10455. if (!(base % 1) && j - i < n) {
  10456. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10457. if (u > 0) for (; i < j; ++i) {
  10458. for (k = 1, p = pows(i); k < base; ++k) {
  10459. t = p * k;
  10460. if (t < u) continue;
  10461. if (t > v) break;
  10462. z.push(t);
  10463. }
  10464. } else for (; i < j; ++i) {
  10465. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10466. t = p * k;
  10467. if (t < u) continue;
  10468. if (t > v) break;
  10469. z.push(t);
  10470. }
  10471. }
  10472. } else {
  10473. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10474. }
  10475. return r ? z.reverse() : z;
  10476. };
  10477. scale.tickFormat = function(count, specifier) {
  10478. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10479. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10480. if (count === Infinity) return specifier;
  10481. if (count == null) count = 10;
  10482. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10483. return function(d) {
  10484. var i = d / pows(Math.round(logs(d)));
  10485. if (i * base < base - 0.5) i *= base;
  10486. return i <= k ? specifier(d) : "";
  10487. };
  10488. };
  10489. scale.nice = function() {
  10490. return domain(nice(domain(), {
  10491. floor: function(x) { return pows(Math.floor(logs(x))); },
  10492. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10493. }));
  10494. };
  10495. scale.copy = function() {
  10496. return copy(scale, log$1().base(base));
  10497. };
  10498. return scale;
  10499. }
  10500. function raise$1(x, exponent) {
  10501. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10502. }
  10503. function pow$1() {
  10504. var exponent = 1,
  10505. scale = continuous(deinterpolate, reinterpolate),
  10506. domain = scale.domain;
  10507. function deinterpolate(a, b) {
  10508. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10509. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10510. : constant$a(b);
  10511. }
  10512. function reinterpolate(a, b) {
  10513. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10514. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10515. }
  10516. scale.exponent = function(_) {
  10517. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10518. };
  10519. scale.copy = function() {
  10520. return copy(scale, pow$1().exponent(exponent));
  10521. };
  10522. return linearish(scale);
  10523. }
  10524. function sqrt$1() {
  10525. return pow$1().exponent(0.5);
  10526. }
  10527. function quantile$$1() {
  10528. var domain = [],
  10529. range = [],
  10530. thresholds = [];
  10531. function rescale() {
  10532. var i = 0, n = Math.max(1, range.length);
  10533. thresholds = new Array(n - 1);
  10534. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10535. return scale;
  10536. }
  10537. function scale(x) {
  10538. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10539. }
  10540. scale.invertExtent = function(y) {
  10541. var i = range.indexOf(y);
  10542. return i < 0 ? [NaN, NaN] : [
  10543. i > 0 ? thresholds[i - 1] : domain[0],
  10544. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10545. ];
  10546. };
  10547. scale.domain = function(_) {
  10548. if (!arguments.length) return domain.slice();
  10549. domain = [];
  10550. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10551. domain.sort(ascending);
  10552. return rescale();
  10553. };
  10554. scale.range = function(_) {
  10555. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10556. };
  10557. scale.quantiles = function() {
  10558. return thresholds.slice();
  10559. };
  10560. scale.copy = function() {
  10561. return quantile$$1()
  10562. .domain(domain)
  10563. .range(range);
  10564. };
  10565. return scale;
  10566. }
  10567. function quantize$1() {
  10568. var x0 = 0,
  10569. x1 = 1,
  10570. n = 1,
  10571. domain = [0.5],
  10572. range = [0, 1];
  10573. function scale(x) {
  10574. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10575. }
  10576. function rescale() {
  10577. var i = -1;
  10578. domain = new Array(n);
  10579. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10580. return scale;
  10581. }
  10582. scale.domain = function(_) {
  10583. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10584. };
  10585. scale.range = function(_) {
  10586. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10587. };
  10588. scale.invertExtent = function(y) {
  10589. var i = range.indexOf(y);
  10590. return i < 0 ? [NaN, NaN]
  10591. : i < 1 ? [x0, domain[0]]
  10592. : i >= n ? [domain[n - 1], x1]
  10593. : [domain[i - 1], domain[i]];
  10594. };
  10595. scale.copy = function() {
  10596. return quantize$1()
  10597. .domain([x0, x1])
  10598. .range(range);
  10599. };
  10600. return linearish(scale);
  10601. }
  10602. function threshold$1() {
  10603. var domain = [0.5],
  10604. range = [0, 1],
  10605. n = 1;
  10606. function scale(x) {
  10607. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10608. }
  10609. scale.domain = function(_) {
  10610. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10611. };
  10612. scale.range = function(_) {
  10613. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10614. };
  10615. scale.invertExtent = function(y) {
  10616. var i = range.indexOf(y);
  10617. return [domain[i - 1], domain[i]];
  10618. };
  10619. scale.copy = function() {
  10620. return threshold$1()
  10621. .domain(domain)
  10622. .range(range);
  10623. };
  10624. return scale;
  10625. }
  10626. var t0$1 = new Date,
  10627. t1$1 = new Date;
  10628. function newInterval(floori, offseti, count, field) {
  10629. function interval(date) {
  10630. return floori(date = new Date(+date)), date;
  10631. }
  10632. interval.floor = interval;
  10633. interval.ceil = function(date) {
  10634. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10635. };
  10636. interval.round = function(date) {
  10637. var d0 = interval(date),
  10638. d1 = interval.ceil(date);
  10639. return date - d0 < d1 - date ? d0 : d1;
  10640. };
  10641. interval.offset = function(date, step) {
  10642. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10643. };
  10644. interval.range = function(start, stop, step) {
  10645. var range = [], previous;
  10646. start = interval.ceil(start);
  10647. step = step == null ? 1 : Math.floor(step);
  10648. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10649. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10650. while (previous < start && start < stop);
  10651. return range;
  10652. };
  10653. interval.filter = function(test) {
  10654. return newInterval(function(date) {
  10655. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10656. }, function(date, step) {
  10657. if (date >= date) {
  10658. if (step < 0) while (++step <= 0) {
  10659. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10660. } else while (--step >= 0) {
  10661. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10662. }
  10663. }
  10664. });
  10665. };
  10666. if (count) {
  10667. interval.count = function(start, end) {
  10668. t0$1.setTime(+start), t1$1.setTime(+end);
  10669. floori(t0$1), floori(t1$1);
  10670. return Math.floor(count(t0$1, t1$1));
  10671. };
  10672. interval.every = function(step) {
  10673. step = Math.floor(step);
  10674. return !isFinite(step) || !(step > 0) ? null
  10675. : !(step > 1) ? interval
  10676. : interval.filter(field
  10677. ? function(d) { return field(d) % step === 0; }
  10678. : function(d) { return interval.count(0, d) % step === 0; });
  10679. };
  10680. }
  10681. return interval;
  10682. }
  10683. var millisecond = newInterval(function() {
  10684. // noop
  10685. }, function(date, step) {
  10686. date.setTime(+date + step);
  10687. }, function(start, end) {
  10688. return end - start;
  10689. });
  10690. // An optimized implementation for this simple case.
  10691. millisecond.every = function(k) {
  10692. k = Math.floor(k);
  10693. if (!isFinite(k) || !(k > 0)) return null;
  10694. if (!(k > 1)) return millisecond;
  10695. return newInterval(function(date) {
  10696. date.setTime(Math.floor(date / k) * k);
  10697. }, function(date, step) {
  10698. date.setTime(+date + step * k);
  10699. }, function(start, end) {
  10700. return (end - start) / k;
  10701. });
  10702. };
  10703. var milliseconds = millisecond.range;
  10704. var durationSecond = 1e3;
  10705. var durationMinute = 6e4;
  10706. var durationHour = 36e5;
  10707. var durationDay = 864e5;
  10708. var durationWeek = 6048e5;
  10709. var second = newInterval(function(date) {
  10710. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  10711. }, function(date, step) {
  10712. date.setTime(+date + step * durationSecond);
  10713. }, function(start, end) {
  10714. return (end - start) / durationSecond;
  10715. }, function(date) {
  10716. return date.getUTCSeconds();
  10717. });
  10718. var seconds = second.range;
  10719. var minute = newInterval(function(date) {
  10720. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  10721. }, function(date, step) {
  10722. date.setTime(+date + step * durationMinute);
  10723. }, function(start, end) {
  10724. return (end - start) / durationMinute;
  10725. }, function(date) {
  10726. return date.getMinutes();
  10727. });
  10728. var minutes = minute.range;
  10729. var hour = newInterval(function(date) {
  10730. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  10731. if (offset < 0) offset += durationHour;
  10732. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  10733. }, function(date, step) {
  10734. date.setTime(+date + step * durationHour);
  10735. }, function(start, end) {
  10736. return (end - start) / durationHour;
  10737. }, function(date) {
  10738. return date.getHours();
  10739. });
  10740. var hours = hour.range;
  10741. var day = newInterval(function(date) {
  10742. date.setHours(0, 0, 0, 0);
  10743. }, function(date, step) {
  10744. date.setDate(date.getDate() + step);
  10745. }, function(start, end) {
  10746. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  10747. }, function(date) {
  10748. return date.getDate() - 1;
  10749. });
  10750. var days = day.range;
  10751. function weekday(i) {
  10752. return newInterval(function(date) {
  10753. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10754. date.setHours(0, 0, 0, 0);
  10755. }, function(date, step) {
  10756. date.setDate(date.getDate() + step * 7);
  10757. }, function(start, end) {
  10758. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  10759. });
  10760. }
  10761. var sunday = weekday(0);
  10762. var monday = weekday(1);
  10763. var tuesday = weekday(2);
  10764. var wednesday = weekday(3);
  10765. var thursday = weekday(4);
  10766. var friday = weekday(5);
  10767. var saturday = weekday(6);
  10768. var sundays = sunday.range;
  10769. var mondays = monday.range;
  10770. var tuesdays = tuesday.range;
  10771. var wednesdays = wednesday.range;
  10772. var thursdays = thursday.range;
  10773. var fridays = friday.range;
  10774. var saturdays = saturday.range;
  10775. var month = newInterval(function(date) {
  10776. date.setDate(1);
  10777. date.setHours(0, 0, 0, 0);
  10778. }, function(date, step) {
  10779. date.setMonth(date.getMonth() + step);
  10780. }, function(start, end) {
  10781. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10782. }, function(date) {
  10783. return date.getMonth();
  10784. });
  10785. var months = month.range;
  10786. var year = newInterval(function(date) {
  10787. date.setMonth(0, 1);
  10788. date.setHours(0, 0, 0, 0);
  10789. }, function(date, step) {
  10790. date.setFullYear(date.getFullYear() + step);
  10791. }, function(start, end) {
  10792. return end.getFullYear() - start.getFullYear();
  10793. }, function(date) {
  10794. return date.getFullYear();
  10795. });
  10796. // An optimized implementation for this simple case.
  10797. year.every = function(k) {
  10798. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10799. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10800. date.setMonth(0, 1);
  10801. date.setHours(0, 0, 0, 0);
  10802. }, function(date, step) {
  10803. date.setFullYear(date.getFullYear() + step * k);
  10804. });
  10805. };
  10806. var years = year.range;
  10807. var utcMinute = newInterval(function(date) {
  10808. date.setUTCSeconds(0, 0);
  10809. }, function(date, step) {
  10810. date.setTime(+date + step * durationMinute);
  10811. }, function(start, end) {
  10812. return (end - start) / durationMinute;
  10813. }, function(date) {
  10814. return date.getUTCMinutes();
  10815. });
  10816. var utcMinutes = utcMinute.range;
  10817. var utcHour = newInterval(function(date) {
  10818. date.setUTCMinutes(0, 0, 0);
  10819. }, function(date, step) {
  10820. date.setTime(+date + step * durationHour);
  10821. }, function(start, end) {
  10822. return (end - start) / durationHour;
  10823. }, function(date) {
  10824. return date.getUTCHours();
  10825. });
  10826. var utcHours = utcHour.range;
  10827. var utcDay = newInterval(function(date) {
  10828. date.setUTCHours(0, 0, 0, 0);
  10829. }, function(date, step) {
  10830. date.setUTCDate(date.getUTCDate() + step);
  10831. }, function(start, end) {
  10832. return (end - start) / durationDay;
  10833. }, function(date) {
  10834. return date.getUTCDate() - 1;
  10835. });
  10836. var utcDays = utcDay.range;
  10837. function utcWeekday(i) {
  10838. return newInterval(function(date) {
  10839. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10840. date.setUTCHours(0, 0, 0, 0);
  10841. }, function(date, step) {
  10842. date.setUTCDate(date.getUTCDate() + step * 7);
  10843. }, function(start, end) {
  10844. return (end - start) / durationWeek;
  10845. });
  10846. }
  10847. var utcSunday = utcWeekday(0);
  10848. var utcMonday = utcWeekday(1);
  10849. var utcTuesday = utcWeekday(2);
  10850. var utcWednesday = utcWeekday(3);
  10851. var utcThursday = utcWeekday(4);
  10852. var utcFriday = utcWeekday(5);
  10853. var utcSaturday = utcWeekday(6);
  10854. var utcSundays = utcSunday.range;
  10855. var utcMondays = utcMonday.range;
  10856. var utcTuesdays = utcTuesday.range;
  10857. var utcWednesdays = utcWednesday.range;
  10858. var utcThursdays = utcThursday.range;
  10859. var utcFridays = utcFriday.range;
  10860. var utcSaturdays = utcSaturday.range;
  10861. var utcMonth = newInterval(function(date) {
  10862. date.setUTCDate(1);
  10863. date.setUTCHours(0, 0, 0, 0);
  10864. }, function(date, step) {
  10865. date.setUTCMonth(date.getUTCMonth() + step);
  10866. }, function(start, end) {
  10867. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10868. }, function(date) {
  10869. return date.getUTCMonth();
  10870. });
  10871. var utcMonths = utcMonth.range;
  10872. var utcYear = newInterval(function(date) {
  10873. date.setUTCMonth(0, 1);
  10874. date.setUTCHours(0, 0, 0, 0);
  10875. }, function(date, step) {
  10876. date.setUTCFullYear(date.getUTCFullYear() + step);
  10877. }, function(start, end) {
  10878. return end.getUTCFullYear() - start.getUTCFullYear();
  10879. }, function(date) {
  10880. return date.getUTCFullYear();
  10881. });
  10882. // An optimized implementation for this simple case.
  10883. utcYear.every = function(k) {
  10884. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10885. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10886. date.setUTCMonth(0, 1);
  10887. date.setUTCHours(0, 0, 0, 0);
  10888. }, function(date, step) {
  10889. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10890. });
  10891. };
  10892. var utcYears = utcYear.range;
  10893. function localDate(d) {
  10894. if (0 <= d.y && d.y < 100) {
  10895. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10896. date.setFullYear(d.y);
  10897. return date;
  10898. }
  10899. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10900. }
  10901. function utcDate(d) {
  10902. if (0 <= d.y && d.y < 100) {
  10903. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10904. date.setUTCFullYear(d.y);
  10905. return date;
  10906. }
  10907. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10908. }
  10909. function newYear(y) {
  10910. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10911. }
  10912. function formatLocale$1(locale) {
  10913. var locale_dateTime = locale.dateTime,
  10914. locale_date = locale.date,
  10915. locale_time = locale.time,
  10916. locale_periods = locale.periods,
  10917. locale_weekdays = locale.days,
  10918. locale_shortWeekdays = locale.shortDays,
  10919. locale_months = locale.months,
  10920. locale_shortMonths = locale.shortMonths;
  10921. var periodRe = formatRe(locale_periods),
  10922. periodLookup = formatLookup(locale_periods),
  10923. weekdayRe = formatRe(locale_weekdays),
  10924. weekdayLookup = formatLookup(locale_weekdays),
  10925. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10926. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10927. monthRe = formatRe(locale_months),
  10928. monthLookup = formatLookup(locale_months),
  10929. shortMonthRe = formatRe(locale_shortMonths),
  10930. shortMonthLookup = formatLookup(locale_shortMonths);
  10931. var formats = {
  10932. "a": formatShortWeekday,
  10933. "A": formatWeekday,
  10934. "b": formatShortMonth,
  10935. "B": formatMonth,
  10936. "c": null,
  10937. "d": formatDayOfMonth,
  10938. "e": formatDayOfMonth,
  10939. "f": formatMicroseconds,
  10940. "H": formatHour24,
  10941. "I": formatHour12,
  10942. "j": formatDayOfYear,
  10943. "L": formatMilliseconds,
  10944. "m": formatMonthNumber,
  10945. "M": formatMinutes,
  10946. "p": formatPeriod,
  10947. "Q": formatUnixTimestamp,
  10948. "s": formatUnixTimestampSeconds,
  10949. "S": formatSeconds,
  10950. "u": formatWeekdayNumberMonday,
  10951. "U": formatWeekNumberSunday,
  10952. "V": formatWeekNumberISO,
  10953. "w": formatWeekdayNumberSunday,
  10954. "W": formatWeekNumberMonday,
  10955. "x": null,
  10956. "X": null,
  10957. "y": formatYear,
  10958. "Y": formatFullYear,
  10959. "Z": formatZone,
  10960. "%": formatLiteralPercent
  10961. };
  10962. var utcFormats = {
  10963. "a": formatUTCShortWeekday,
  10964. "A": formatUTCWeekday,
  10965. "b": formatUTCShortMonth,
  10966. "B": formatUTCMonth,
  10967. "c": null,
  10968. "d": formatUTCDayOfMonth,
  10969. "e": formatUTCDayOfMonth,
  10970. "f": formatUTCMicroseconds,
  10971. "H": formatUTCHour24,
  10972. "I": formatUTCHour12,
  10973. "j": formatUTCDayOfYear,
  10974. "L": formatUTCMilliseconds,
  10975. "m": formatUTCMonthNumber,
  10976. "M": formatUTCMinutes,
  10977. "p": formatUTCPeriod,
  10978. "Q": formatUnixTimestamp,
  10979. "s": formatUnixTimestampSeconds,
  10980. "S": formatUTCSeconds,
  10981. "u": formatUTCWeekdayNumberMonday,
  10982. "U": formatUTCWeekNumberSunday,
  10983. "V": formatUTCWeekNumberISO,
  10984. "w": formatUTCWeekdayNumberSunday,
  10985. "W": formatUTCWeekNumberMonday,
  10986. "x": null,
  10987. "X": null,
  10988. "y": formatUTCYear,
  10989. "Y": formatUTCFullYear,
  10990. "Z": formatUTCZone,
  10991. "%": formatLiteralPercent
  10992. };
  10993. var parses = {
  10994. "a": parseShortWeekday,
  10995. "A": parseWeekday,
  10996. "b": parseShortMonth,
  10997. "B": parseMonth,
  10998. "c": parseLocaleDateTime,
  10999. "d": parseDayOfMonth,
  11000. "e": parseDayOfMonth,
  11001. "f": parseMicroseconds,
  11002. "H": parseHour24,
  11003. "I": parseHour24,
  11004. "j": parseDayOfYear,
  11005. "L": parseMilliseconds,
  11006. "m": parseMonthNumber,
  11007. "M": parseMinutes,
  11008. "p": parsePeriod,
  11009. "Q": parseUnixTimestamp,
  11010. "s": parseUnixTimestampSeconds,
  11011. "S": parseSeconds,
  11012. "u": parseWeekdayNumberMonday,
  11013. "U": parseWeekNumberSunday,
  11014. "V": parseWeekNumberISO,
  11015. "w": parseWeekdayNumberSunday,
  11016. "W": parseWeekNumberMonday,
  11017. "x": parseLocaleDate,
  11018. "X": parseLocaleTime,
  11019. "y": parseYear,
  11020. "Y": parseFullYear,
  11021. "Z": parseZone,
  11022. "%": parseLiteralPercent
  11023. };
  11024. // These recursive directive definitions must be deferred.
  11025. formats.x = newFormat(locale_date, formats);
  11026. formats.X = newFormat(locale_time, formats);
  11027. formats.c = newFormat(locale_dateTime, formats);
  11028. utcFormats.x = newFormat(locale_date, utcFormats);
  11029. utcFormats.X = newFormat(locale_time, utcFormats);
  11030. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  11031. function newFormat(specifier, formats) {
  11032. return function(date) {
  11033. var string = [],
  11034. i = -1,
  11035. j = 0,
  11036. n = specifier.length,
  11037. c,
  11038. pad,
  11039. format;
  11040. if (!(date instanceof Date)) date = new Date(+date);
  11041. while (++i < n) {
  11042. if (specifier.charCodeAt(i) === 37) {
  11043. string.push(specifier.slice(j, i));
  11044. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11045. else pad = c === "e" ? " " : "0";
  11046. if (format = formats[c]) c = format(date, pad);
  11047. string.push(c);
  11048. j = i + 1;
  11049. }
  11050. }
  11051. string.push(specifier.slice(j, i));
  11052. return string.join("");
  11053. };
  11054. }
  11055. function newParse(specifier, newDate) {
  11056. return function(string) {
  11057. var d = newYear(1900),
  11058. i = parseSpecifier(d, specifier, string += "", 0),
  11059. week, day$$1;
  11060. if (i != string.length) return null;
  11061. // If a UNIX timestamp is specified, return it.
  11062. if ("Q" in d) return new Date(d.Q);
  11063. // The am-pm flag is 0 for AM, and 1 for PM.
  11064. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11065. // Convert day-of-week and week-of-year to day-of-year.
  11066. if ("V" in d) {
  11067. if (d.V < 1 || d.V > 53) return null;
  11068. if (!("w" in d)) d.w = 1;
  11069. if ("Z" in d) {
  11070. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  11071. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11072. week = utcDay.offset(week, (d.V - 1) * 7);
  11073. d.y = week.getUTCFullYear();
  11074. d.m = week.getUTCMonth();
  11075. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11076. } else {
  11077. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  11078. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  11079. week = day.offset(week, (d.V - 1) * 7);
  11080. d.y = week.getFullYear();
  11081. d.m = week.getMonth();
  11082. d.d = week.getDate() + (d.w + 6) % 7;
  11083. }
  11084. } else if ("W" in d || "U" in d) {
  11085. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11086. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11087. d.m = 0;
  11088. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
  11089. }
  11090. // If a time zone is specified, all fields are interpreted as UTC and then
  11091. // offset according to the specified time zone.
  11092. if ("Z" in d) {
  11093. d.H += d.Z / 100 | 0;
  11094. d.M += d.Z % 100;
  11095. return utcDate(d);
  11096. }
  11097. // Otherwise, all fields are in local time.
  11098. return newDate(d);
  11099. };
  11100. }
  11101. function parseSpecifier(d, specifier, string, j) {
  11102. var i = 0,
  11103. n = specifier.length,
  11104. m = string.length,
  11105. c,
  11106. parse;
  11107. while (i < n) {
  11108. if (j >= m) return -1;
  11109. c = specifier.charCodeAt(i++);
  11110. if (c === 37) {
  11111. c = specifier.charAt(i++);
  11112. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11113. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11114. } else if (c != string.charCodeAt(j++)) {
  11115. return -1;
  11116. }
  11117. }
  11118. return j;
  11119. }
  11120. function parsePeriod(d, string, i) {
  11121. var n = periodRe.exec(string.slice(i));
  11122. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11123. }
  11124. function parseShortWeekday(d, string, i) {
  11125. var n = shortWeekdayRe.exec(string.slice(i));
  11126. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11127. }
  11128. function parseWeekday(d, string, i) {
  11129. var n = weekdayRe.exec(string.slice(i));
  11130. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11131. }
  11132. function parseShortMonth(d, string, i) {
  11133. var n = shortMonthRe.exec(string.slice(i));
  11134. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11135. }
  11136. function parseMonth(d, string, i) {
  11137. var n = monthRe.exec(string.slice(i));
  11138. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11139. }
  11140. function parseLocaleDateTime(d, string, i) {
  11141. return parseSpecifier(d, locale_dateTime, string, i);
  11142. }
  11143. function parseLocaleDate(d, string, i) {
  11144. return parseSpecifier(d, locale_date, string, i);
  11145. }
  11146. function parseLocaleTime(d, string, i) {
  11147. return parseSpecifier(d, locale_time, string, i);
  11148. }
  11149. function formatShortWeekday(d) {
  11150. return locale_shortWeekdays[d.getDay()];
  11151. }
  11152. function formatWeekday(d) {
  11153. return locale_weekdays[d.getDay()];
  11154. }
  11155. function formatShortMonth(d) {
  11156. return locale_shortMonths[d.getMonth()];
  11157. }
  11158. function formatMonth(d) {
  11159. return locale_months[d.getMonth()];
  11160. }
  11161. function formatPeriod(d) {
  11162. return locale_periods[+(d.getHours() >= 12)];
  11163. }
  11164. function formatUTCShortWeekday(d) {
  11165. return locale_shortWeekdays[d.getUTCDay()];
  11166. }
  11167. function formatUTCWeekday(d) {
  11168. return locale_weekdays[d.getUTCDay()];
  11169. }
  11170. function formatUTCShortMonth(d) {
  11171. return locale_shortMonths[d.getUTCMonth()];
  11172. }
  11173. function formatUTCMonth(d) {
  11174. return locale_months[d.getUTCMonth()];
  11175. }
  11176. function formatUTCPeriod(d) {
  11177. return locale_periods[+(d.getUTCHours() >= 12)];
  11178. }
  11179. return {
  11180. format: function(specifier) {
  11181. var f = newFormat(specifier += "", formats);
  11182. f.toString = function() { return specifier; };
  11183. return f;
  11184. },
  11185. parse: function(specifier) {
  11186. var p = newParse(specifier += "", localDate);
  11187. p.toString = function() { return specifier; };
  11188. return p;
  11189. },
  11190. utcFormat: function(specifier) {
  11191. var f = newFormat(specifier += "", utcFormats);
  11192. f.toString = function() { return specifier; };
  11193. return f;
  11194. },
  11195. utcParse: function(specifier) {
  11196. var p = newParse(specifier, utcDate);
  11197. p.toString = function() { return specifier; };
  11198. return p;
  11199. }
  11200. };
  11201. }
  11202. var pads = {"-": "", "_": " ", "0": "0"},
  11203. numberRe = /^\s*\d+/, // note: ignores next directive
  11204. percentRe = /^%/,
  11205. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11206. function pad(value, fill, width) {
  11207. var sign = value < 0 ? "-" : "",
  11208. string = (sign ? -value : value) + "",
  11209. length = string.length;
  11210. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11211. }
  11212. function requote(s) {
  11213. return s.replace(requoteRe, "\\$&");
  11214. }
  11215. function formatRe(names) {
  11216. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11217. }
  11218. function formatLookup(names) {
  11219. var map = {}, i = -1, n = names.length;
  11220. while (++i < n) map[names[i].toLowerCase()] = i;
  11221. return map;
  11222. }
  11223. function parseWeekdayNumberSunday(d, string, i) {
  11224. var n = numberRe.exec(string.slice(i, i + 1));
  11225. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11226. }
  11227. function parseWeekdayNumberMonday(d, string, i) {
  11228. var n = numberRe.exec(string.slice(i, i + 1));
  11229. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11230. }
  11231. function parseWeekNumberSunday(d, string, i) {
  11232. var n = numberRe.exec(string.slice(i, i + 2));
  11233. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11234. }
  11235. function parseWeekNumberISO(d, string, i) {
  11236. var n = numberRe.exec(string.slice(i, i + 2));
  11237. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11238. }
  11239. function parseWeekNumberMonday(d, string, i) {
  11240. var n = numberRe.exec(string.slice(i, i + 2));
  11241. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11242. }
  11243. function parseFullYear(d, string, i) {
  11244. var n = numberRe.exec(string.slice(i, i + 4));
  11245. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11246. }
  11247. function parseYear(d, string, i) {
  11248. var n = numberRe.exec(string.slice(i, i + 2));
  11249. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11250. }
  11251. function parseZone(d, string, i) {
  11252. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11253. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11254. }
  11255. function parseMonthNumber(d, string, i) {
  11256. var n = numberRe.exec(string.slice(i, i + 2));
  11257. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11258. }
  11259. function parseDayOfMonth(d, string, i) {
  11260. var n = numberRe.exec(string.slice(i, i + 2));
  11261. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11262. }
  11263. function parseDayOfYear(d, string, i) {
  11264. var n = numberRe.exec(string.slice(i, i + 3));
  11265. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11266. }
  11267. function parseHour24(d, string, i) {
  11268. var n = numberRe.exec(string.slice(i, i + 2));
  11269. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11270. }
  11271. function parseMinutes(d, string, i) {
  11272. var n = numberRe.exec(string.slice(i, i + 2));
  11273. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11274. }
  11275. function parseSeconds(d, string, i) {
  11276. var n = numberRe.exec(string.slice(i, i + 2));
  11277. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11278. }
  11279. function parseMilliseconds(d, string, i) {
  11280. var n = numberRe.exec(string.slice(i, i + 3));
  11281. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11282. }
  11283. function parseMicroseconds(d, string, i) {
  11284. var n = numberRe.exec(string.slice(i, i + 6));
  11285. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11286. }
  11287. function parseLiteralPercent(d, string, i) {
  11288. var n = percentRe.exec(string.slice(i, i + 1));
  11289. return n ? i + n[0].length : -1;
  11290. }
  11291. function parseUnixTimestamp(d, string, i) {
  11292. var n = numberRe.exec(string.slice(i));
  11293. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11294. }
  11295. function parseUnixTimestampSeconds(d, string, i) {
  11296. var n = numberRe.exec(string.slice(i));
  11297. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11298. }
  11299. function formatDayOfMonth(d, p) {
  11300. return pad(d.getDate(), p, 2);
  11301. }
  11302. function formatHour24(d, p) {
  11303. return pad(d.getHours(), p, 2);
  11304. }
  11305. function formatHour12(d, p) {
  11306. return pad(d.getHours() % 12 || 12, p, 2);
  11307. }
  11308. function formatDayOfYear(d, p) {
  11309. return pad(1 + day.count(year(d), d), p, 3);
  11310. }
  11311. function formatMilliseconds(d, p) {
  11312. return pad(d.getMilliseconds(), p, 3);
  11313. }
  11314. function formatMicroseconds(d, p) {
  11315. return formatMilliseconds(d, p) + "000";
  11316. }
  11317. function formatMonthNumber(d, p) {
  11318. return pad(d.getMonth() + 1, p, 2);
  11319. }
  11320. function formatMinutes(d, p) {
  11321. return pad(d.getMinutes(), p, 2);
  11322. }
  11323. function formatSeconds(d, p) {
  11324. return pad(d.getSeconds(), p, 2);
  11325. }
  11326. function formatWeekdayNumberMonday(d) {
  11327. var day$$1 = d.getDay();
  11328. return day$$1 === 0 ? 7 : day$$1;
  11329. }
  11330. function formatWeekNumberSunday(d, p) {
  11331. return pad(sunday.count(year(d), d), p, 2);
  11332. }
  11333. function formatWeekNumberISO(d, p) {
  11334. var day$$1 = d.getDay();
  11335. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11336. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11337. }
  11338. function formatWeekdayNumberSunday(d) {
  11339. return d.getDay();
  11340. }
  11341. function formatWeekNumberMonday(d, p) {
  11342. return pad(monday.count(year(d), d), p, 2);
  11343. }
  11344. function formatYear(d, p) {
  11345. return pad(d.getFullYear() % 100, p, 2);
  11346. }
  11347. function formatFullYear(d, p) {
  11348. return pad(d.getFullYear() % 10000, p, 4);
  11349. }
  11350. function formatZone(d) {
  11351. var z = d.getTimezoneOffset();
  11352. return (z > 0 ? "-" : (z *= -1, "+"))
  11353. + pad(z / 60 | 0, "0", 2)
  11354. + pad(z % 60, "0", 2);
  11355. }
  11356. function formatUTCDayOfMonth(d, p) {
  11357. return pad(d.getUTCDate(), p, 2);
  11358. }
  11359. function formatUTCHour24(d, p) {
  11360. return pad(d.getUTCHours(), p, 2);
  11361. }
  11362. function formatUTCHour12(d, p) {
  11363. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11364. }
  11365. function formatUTCDayOfYear(d, p) {
  11366. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11367. }
  11368. function formatUTCMilliseconds(d, p) {
  11369. return pad(d.getUTCMilliseconds(), p, 3);
  11370. }
  11371. function formatUTCMicroseconds(d, p) {
  11372. return formatUTCMilliseconds(d, p) + "000";
  11373. }
  11374. function formatUTCMonthNumber(d, p) {
  11375. return pad(d.getUTCMonth() + 1, p, 2);
  11376. }
  11377. function formatUTCMinutes(d, p) {
  11378. return pad(d.getUTCMinutes(), p, 2);
  11379. }
  11380. function formatUTCSeconds(d, p) {
  11381. return pad(d.getUTCSeconds(), p, 2);
  11382. }
  11383. function formatUTCWeekdayNumberMonday(d) {
  11384. var dow = d.getUTCDay();
  11385. return dow === 0 ? 7 : dow;
  11386. }
  11387. function formatUTCWeekNumberSunday(d, p) {
  11388. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11389. }
  11390. function formatUTCWeekNumberISO(d, p) {
  11391. var day$$1 = d.getUTCDay();
  11392. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11393. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11394. }
  11395. function formatUTCWeekdayNumberSunday(d) {
  11396. return d.getUTCDay();
  11397. }
  11398. function formatUTCWeekNumberMonday(d, p) {
  11399. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11400. }
  11401. function formatUTCYear(d, p) {
  11402. return pad(d.getUTCFullYear() % 100, p, 2);
  11403. }
  11404. function formatUTCFullYear(d, p) {
  11405. return pad(d.getUTCFullYear() % 10000, p, 4);
  11406. }
  11407. function formatUTCZone() {
  11408. return "+0000";
  11409. }
  11410. function formatLiteralPercent() {
  11411. return "%";
  11412. }
  11413. function formatUnixTimestamp(d) {
  11414. return +d;
  11415. }
  11416. function formatUnixTimestampSeconds(d) {
  11417. return Math.floor(+d / 1000);
  11418. }
  11419. var locale$1;
  11420. defaultLocale$1({
  11421. dateTime: "%x, %X",
  11422. date: "%-m/%-d/%Y",
  11423. time: "%-I:%M:%S %p",
  11424. periods: ["AM", "PM"],
  11425. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11426. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11427. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11428. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11429. });
  11430. function defaultLocale$1(definition) {
  11431. locale$1 = formatLocale$1(definition);
  11432. exports.timeFormat = locale$1.format;
  11433. exports.timeParse = locale$1.parse;
  11434. exports.utcFormat = locale$1.utcFormat;
  11435. exports.utcParse = locale$1.utcParse;
  11436. return locale$1;
  11437. }
  11438. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11439. function formatIsoNative(date) {
  11440. return date.toISOString();
  11441. }
  11442. var formatIso = Date.prototype.toISOString
  11443. ? formatIsoNative
  11444. : exports.utcFormat(isoSpecifier);
  11445. function parseIsoNative(string) {
  11446. var date = new Date(string);
  11447. return isNaN(date) ? null : date;
  11448. }
  11449. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11450. ? parseIsoNative
  11451. : exports.utcParse(isoSpecifier);
  11452. var durationSecond$1 = 1000,
  11453. durationMinute$1 = durationSecond$1 * 60,
  11454. durationHour$1 = durationMinute$1 * 60,
  11455. durationDay$1 = durationHour$1 * 24,
  11456. durationWeek$1 = durationDay$1 * 7,
  11457. durationMonth = durationDay$1 * 30,
  11458. durationYear = durationDay$1 * 365;
  11459. function date$1(t) {
  11460. return new Date(t);
  11461. }
  11462. function number$3(t) {
  11463. return t instanceof Date ? +t : +new Date(+t);
  11464. }
  11465. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11466. var scale = continuous(deinterpolateLinear, interpolateNumber),
  11467. invert = scale.invert,
  11468. domain = scale.domain;
  11469. var formatMillisecond = format(".%L"),
  11470. formatSecond = format(":%S"),
  11471. formatMinute = format("%I:%M"),
  11472. formatHour = format("%I %p"),
  11473. formatDay = format("%a %d"),
  11474. formatWeek = format("%b %d"),
  11475. formatMonth = format("%B"),
  11476. formatYear = format("%Y");
  11477. var tickIntervals = [
  11478. [second$$1, 1, durationSecond$1],
  11479. [second$$1, 5, 5 * durationSecond$1],
  11480. [second$$1, 15, 15 * durationSecond$1],
  11481. [second$$1, 30, 30 * durationSecond$1],
  11482. [minute$$1, 1, durationMinute$1],
  11483. [minute$$1, 5, 5 * durationMinute$1],
  11484. [minute$$1, 15, 15 * durationMinute$1],
  11485. [minute$$1, 30, 30 * durationMinute$1],
  11486. [ hour$$1, 1, durationHour$1 ],
  11487. [ hour$$1, 3, 3 * durationHour$1 ],
  11488. [ hour$$1, 6, 6 * durationHour$1 ],
  11489. [ hour$$1, 12, 12 * durationHour$1 ],
  11490. [ day$$1, 1, durationDay$1 ],
  11491. [ day$$1, 2, 2 * durationDay$1 ],
  11492. [ week, 1, durationWeek$1 ],
  11493. [ month$$1, 1, durationMonth ],
  11494. [ month$$1, 3, 3 * durationMonth ],
  11495. [ year$$1, 1, durationYear ]
  11496. ];
  11497. function tickFormat(date$$1) {
  11498. return (second$$1(date$$1) < date$$1 ? formatMillisecond
  11499. : minute$$1(date$$1) < date$$1 ? formatSecond
  11500. : hour$$1(date$$1) < date$$1 ? formatMinute
  11501. : day$$1(date$$1) < date$$1 ? formatHour
  11502. : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
  11503. : year$$1(date$$1) < date$$1 ? formatMonth
  11504. : formatYear)(date$$1);
  11505. }
  11506. function tickInterval(interval, start, stop, step) {
  11507. if (interval == null) interval = 10;
  11508. // If a desired tick count is specified, pick a reasonable tick interval
  11509. // based on the extent of the domain and a rough estimate of tick size.
  11510. // Otherwise, assume interval is already a time interval and use it.
  11511. if (typeof interval === "number") {
  11512. var target = Math.abs(stop - start) / interval,
  11513. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11514. if (i === tickIntervals.length) {
  11515. step = tickStep(start / durationYear, stop / durationYear, interval);
  11516. interval = year$$1;
  11517. } else if (i) {
  11518. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11519. step = i[1];
  11520. interval = i[0];
  11521. } else {
  11522. step = Math.max(tickStep(start, stop, interval), 1);
  11523. interval = millisecond$$1;
  11524. }
  11525. }
  11526. return step == null ? interval : interval.every(step);
  11527. }
  11528. scale.invert = function(y) {
  11529. return new Date(invert(y));
  11530. };
  11531. scale.domain = function(_) {
  11532. return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
  11533. };
  11534. scale.ticks = function(interval, step) {
  11535. var d = domain(),
  11536. t0 = d[0],
  11537. t1 = d[d.length - 1],
  11538. r = t1 < t0,
  11539. t;
  11540. if (r) t = t0, t0 = t1, t1 = t;
  11541. t = tickInterval(interval, t0, t1, step);
  11542. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11543. return r ? t.reverse() : t;
  11544. };
  11545. scale.tickFormat = function(count, specifier) {
  11546. return specifier == null ? tickFormat : format(specifier);
  11547. };
  11548. scale.nice = function(interval, step) {
  11549. var d = domain();
  11550. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11551. ? domain(nice(d, interval))
  11552. : scale;
  11553. };
  11554. scale.copy = function() {
  11555. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11556. };
  11557. return scale;
  11558. }
  11559. function time() {
  11560. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11561. }
  11562. function utcTime() {
  11563. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11564. }
  11565. function sequential(interpolator) {
  11566. var x0 = 0,
  11567. x1 = 1,
  11568. k10 = 1,
  11569. clamp = false;
  11570. function scale(x) {
  11571. var t = (x - x0) * k10;
  11572. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11573. }
  11574. scale.domain = function(_) {
  11575. return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
  11576. };
  11577. scale.clamp = function(_) {
  11578. return arguments.length ? (clamp = !!_, scale) : clamp;
  11579. };
  11580. scale.interpolator = function(_) {
  11581. return arguments.length ? (interpolator = _, scale) : interpolator;
  11582. };
  11583. scale.copy = function() {
  11584. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11585. };
  11586. return linearish(scale);
  11587. }
  11588. function diverging(interpolator) {
  11589. var x0 = 0,
  11590. x1 = 0.5,
  11591. x2 = 1,
  11592. k10 = 1,
  11593. k21 = 1,
  11594. clamp = false;
  11595. function scale(x) {
  11596. var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
  11597. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11598. }
  11599. scale.domain = function(_) {
  11600. return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
  11601. };
  11602. scale.clamp = function(_) {
  11603. return arguments.length ? (clamp = !!_, scale) : clamp;
  11604. };
  11605. scale.interpolator = function(_) {
  11606. return arguments.length ? (interpolator = _, scale) : interpolator;
  11607. };
  11608. scale.copy = function() {
  11609. return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
  11610. };
  11611. return linearish(scale);
  11612. }
  11613. function colors(specifier) {
  11614. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11615. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11616. return colors;
  11617. }
  11618. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11619. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11620. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11621. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11622. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  11623. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  11624. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  11625. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  11626. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  11627. function ramp(scheme) {
  11628. return rgbBasis(scheme[scheme.length - 1]);
  11629. }
  11630. var scheme = new Array(3).concat(
  11631. "d8b365f5f5f55ab4ac",
  11632. "a6611adfc27d80cdc1018571",
  11633. "a6611adfc27df5f5f580cdc1018571",
  11634. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  11635. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  11636. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  11637. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  11638. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  11639. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  11640. ).map(colors);
  11641. var BrBG = ramp(scheme);
  11642. var scheme$1 = new Array(3).concat(
  11643. "af8dc3f7f7f77fbf7b",
  11644. "7b3294c2a5cfa6dba0008837",
  11645. "7b3294c2a5cff7f7f7a6dba0008837",
  11646. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  11647. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  11648. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  11649. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  11650. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  11651. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  11652. ).map(colors);
  11653. var PRGn = ramp(scheme$1);
  11654. var scheme$2 = new Array(3).concat(
  11655. "e9a3c9f7f7f7a1d76a",
  11656. "d01c8bf1b6dab8e1864dac26",
  11657. "d01c8bf1b6daf7f7f7b8e1864dac26",
  11658. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  11659. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  11660. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  11661. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  11662. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  11663. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  11664. ).map(colors);
  11665. var PiYG = ramp(scheme$2);
  11666. var scheme$3 = new Array(3).concat(
  11667. "998ec3f7f7f7f1a340",
  11668. "5e3c99b2abd2fdb863e66101",
  11669. "5e3c99b2abd2f7f7f7fdb863e66101",
  11670. "542788998ec3d8daebfee0b6f1a340b35806",
  11671. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  11672. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  11673. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  11674. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  11675. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  11676. ).map(colors);
  11677. var PuOr = ramp(scheme$3);
  11678. var scheme$4 = new Array(3).concat(
  11679. "ef8a62f7f7f767a9cf",
  11680. "ca0020f4a58292c5de0571b0",
  11681. "ca0020f4a582f7f7f792c5de0571b0",
  11682. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  11683. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  11684. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  11685. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  11686. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  11687. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  11688. ).map(colors);
  11689. var RdBu = ramp(scheme$4);
  11690. var scheme$5 = new Array(3).concat(
  11691. "ef8a62ffffff999999",
  11692. "ca0020f4a582bababa404040",
  11693. "ca0020f4a582ffffffbababa404040",
  11694. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  11695. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  11696. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  11697. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  11698. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  11699. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  11700. ).map(colors);
  11701. var RdGy = ramp(scheme$5);
  11702. var scheme$6 = new Array(3).concat(
  11703. "fc8d59ffffbf91bfdb",
  11704. "d7191cfdae61abd9e92c7bb6",
  11705. "d7191cfdae61ffffbfabd9e92c7bb6",
  11706. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  11707. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  11708. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  11709. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  11710. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  11711. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  11712. ).map(colors);
  11713. var RdYlBu = ramp(scheme$6);
  11714. var scheme$7 = new Array(3).concat(
  11715. "fc8d59ffffbf91cf60",
  11716. "d7191cfdae61a6d96a1a9641",
  11717. "d7191cfdae61ffffbfa6d96a1a9641",
  11718. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  11719. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  11720. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  11721. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  11722. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  11723. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  11724. ).map(colors);
  11725. var RdYlGn = ramp(scheme$7);
  11726. var scheme$8 = new Array(3).concat(
  11727. "fc8d59ffffbf99d594",
  11728. "d7191cfdae61abdda42b83ba",
  11729. "d7191cfdae61ffffbfabdda42b83ba",
  11730. "d53e4ffc8d59fee08be6f59899d5943288bd",
  11731. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  11732. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  11733. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  11734. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  11735. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  11736. ).map(colors);
  11737. var Spectral = ramp(scheme$8);
  11738. var scheme$9 = new Array(3).concat(
  11739. "e5f5f999d8c92ca25f",
  11740. "edf8fbb2e2e266c2a4238b45",
  11741. "edf8fbb2e2e266c2a42ca25f006d2c",
  11742. "edf8fbccece699d8c966c2a42ca25f006d2c",
  11743. "edf8fbccece699d8c966c2a441ae76238b45005824",
  11744. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  11745. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  11746. ).map(colors);
  11747. var BuGn = ramp(scheme$9);
  11748. var scheme$a = new Array(3).concat(
  11749. "e0ecf49ebcda8856a7",
  11750. "edf8fbb3cde38c96c688419d",
  11751. "edf8fbb3cde38c96c68856a7810f7c",
  11752. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  11753. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  11754. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  11755. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  11756. ).map(colors);
  11757. var BuPu = ramp(scheme$a);
  11758. var scheme$b = new Array(3).concat(
  11759. "e0f3dba8ddb543a2ca",
  11760. "f0f9e8bae4bc7bccc42b8cbe",
  11761. "f0f9e8bae4bc7bccc443a2ca0868ac",
  11762. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  11763. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11764. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11765. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  11766. ).map(colors);
  11767. var GnBu = ramp(scheme$b);
  11768. var scheme$c = new Array(3).concat(
  11769. "fee8c8fdbb84e34a33",
  11770. "fef0d9fdcc8afc8d59d7301f",
  11771. "fef0d9fdcc8afc8d59e34a33b30000",
  11772. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  11773. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  11774. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  11775. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  11776. ).map(colors);
  11777. var OrRd = ramp(scheme$c);
  11778. var scheme$d = new Array(3).concat(
  11779. "ece2f0a6bddb1c9099",
  11780. "f6eff7bdc9e167a9cf02818a",
  11781. "f6eff7bdc9e167a9cf1c9099016c59",
  11782. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  11783. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  11784. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  11785. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  11786. ).map(colors);
  11787. var PuBuGn = ramp(scheme$d);
  11788. var scheme$e = new Array(3).concat(
  11789. "ece7f2a6bddb2b8cbe",
  11790. "f1eef6bdc9e174a9cf0570b0",
  11791. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  11792. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  11793. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11794. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11795. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  11796. ).map(colors);
  11797. var PuBu = ramp(scheme$e);
  11798. var scheme$f = new Array(3).concat(
  11799. "e7e1efc994c7dd1c77",
  11800. "f1eef6d7b5d8df65b0ce1256",
  11801. "f1eef6d7b5d8df65b0dd1c77980043",
  11802. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  11803. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  11804. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  11805. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  11806. ).map(colors);
  11807. var PuRd = ramp(scheme$f);
  11808. var scheme$g = new Array(3).concat(
  11809. "fde0ddfa9fb5c51b8a",
  11810. "feebe2fbb4b9f768a1ae017e",
  11811. "feebe2fbb4b9f768a1c51b8a7a0177",
  11812. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  11813. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11814. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11815. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  11816. ).map(colors);
  11817. var RdPu = ramp(scheme$g);
  11818. var scheme$h = new Array(3).concat(
  11819. "edf8b17fcdbb2c7fb8",
  11820. "ffffcca1dab441b6c4225ea8",
  11821. "ffffcca1dab441b6c42c7fb8253494",
  11822. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  11823. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11824. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11825. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  11826. ).map(colors);
  11827. var YlGnBu = ramp(scheme$h);
  11828. var scheme$i = new Array(3).concat(
  11829. "f7fcb9addd8e31a354",
  11830. "ffffccc2e69978c679238443",
  11831. "ffffccc2e69978c67931a354006837",
  11832. "ffffccd9f0a3addd8e78c67931a354006837",
  11833. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  11834. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  11835. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  11836. ).map(colors);
  11837. var YlGn = ramp(scheme$i);
  11838. var scheme$j = new Array(3).concat(
  11839. "fff7bcfec44fd95f0e",
  11840. "ffffd4fed98efe9929cc4c02",
  11841. "ffffd4fed98efe9929d95f0e993404",
  11842. "ffffd4fee391fec44ffe9929d95f0e993404",
  11843. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  11844. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  11845. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  11846. ).map(colors);
  11847. var YlOrBr = ramp(scheme$j);
  11848. var scheme$k = new Array(3).concat(
  11849. "ffeda0feb24cf03b20",
  11850. "ffffb2fecc5cfd8d3ce31a1c",
  11851. "ffffb2fecc5cfd8d3cf03b20bd0026",
  11852. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  11853. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11854. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11855. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  11856. ).map(colors);
  11857. var YlOrRd = ramp(scheme$k);
  11858. var scheme$l = new Array(3).concat(
  11859. "deebf79ecae13182bd",
  11860. "eff3ffbdd7e76baed62171b5",
  11861. "eff3ffbdd7e76baed63182bd08519c",
  11862. "eff3ffc6dbef9ecae16baed63182bd08519c",
  11863. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  11864. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  11865. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  11866. ).map(colors);
  11867. var Blues = ramp(scheme$l);
  11868. var scheme$m = new Array(3).concat(
  11869. "e5f5e0a1d99b31a354",
  11870. "edf8e9bae4b374c476238b45",
  11871. "edf8e9bae4b374c47631a354006d2c",
  11872. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  11873. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  11874. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  11875. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  11876. ).map(colors);
  11877. var Greens = ramp(scheme$m);
  11878. var scheme$n = new Array(3).concat(
  11879. "f0f0f0bdbdbd636363",
  11880. "f7f7f7cccccc969696525252",
  11881. "f7f7f7cccccc969696636363252525",
  11882. "f7f7f7d9d9d9bdbdbd969696636363252525",
  11883. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  11884. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  11885. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  11886. ).map(colors);
  11887. var Greys = ramp(scheme$n);
  11888. var scheme$o = new Array(3).concat(
  11889. "efedf5bcbddc756bb1",
  11890. "f2f0f7cbc9e29e9ac86a51a3",
  11891. "f2f0f7cbc9e29e9ac8756bb154278f",
  11892. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  11893. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11894. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11895. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  11896. ).map(colors);
  11897. var Purples = ramp(scheme$o);
  11898. var scheme$p = new Array(3).concat(
  11899. "fee0d2fc9272de2d26",
  11900. "fee5d9fcae91fb6a4acb181d",
  11901. "fee5d9fcae91fb6a4ade2d26a50f15",
  11902. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  11903. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11904. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11905. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  11906. ).map(colors);
  11907. var Reds = ramp(scheme$p);
  11908. var scheme$q = new Array(3).concat(
  11909. "fee6cefdae6be6550d",
  11910. "feeddefdbe85fd8d3cd94701",
  11911. "feeddefdbe85fd8d3ce6550da63603",
  11912. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  11913. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11914. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11915. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  11916. ).map(colors);
  11917. var Oranges = ramp(scheme$q);
  11918. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11919. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11920. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11921. var c = cubehelix();
  11922. function rainbow(t) {
  11923. if (t < 0 || t > 1) t -= Math.floor(t);
  11924. var ts = Math.abs(t - 0.5);
  11925. c.h = 360 * t - 100;
  11926. c.s = 1.5 - 1.5 * ts;
  11927. c.l = 0.8 - 0.9 * ts;
  11928. return c + "";
  11929. }
  11930. var c$1 = rgb(),
  11931. pi_1_3 = Math.PI / 3,
  11932. pi_2_3 = Math.PI * 2 / 3;
  11933. function sinebow(t) {
  11934. var x;
  11935. t = (0.5 - t) * Math.PI;
  11936. c$1.r = 255 * (x = Math.sin(t)) * x;
  11937. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  11938. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  11939. return c$1 + "";
  11940. }
  11941. function ramp$1(range) {
  11942. var n = range.length;
  11943. return function(t) {
  11944. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11945. };
  11946. }
  11947. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11948. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11949. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11950. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11951. function constant$b(x) {
  11952. return function constant() {
  11953. return x;
  11954. };
  11955. }
  11956. var abs$1 = Math.abs;
  11957. var atan2$1 = Math.atan2;
  11958. var cos$2 = Math.cos;
  11959. var max$2 = Math.max;
  11960. var min$1 = Math.min;
  11961. var sin$2 = Math.sin;
  11962. var sqrt$2 = Math.sqrt;
  11963. var epsilon$3 = 1e-12;
  11964. var pi$4 = Math.PI;
  11965. var halfPi$3 = pi$4 / 2;
  11966. var tau$4 = 2 * pi$4;
  11967. function acos$1(x) {
  11968. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11969. }
  11970. function asin$1(x) {
  11971. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11972. }
  11973. function arcInnerRadius(d) {
  11974. return d.innerRadius;
  11975. }
  11976. function arcOuterRadius(d) {
  11977. return d.outerRadius;
  11978. }
  11979. function arcStartAngle(d) {
  11980. return d.startAngle;
  11981. }
  11982. function arcEndAngle(d) {
  11983. return d.endAngle;
  11984. }
  11985. function arcPadAngle(d) {
  11986. return d && d.padAngle; // Note: optional!
  11987. }
  11988. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11989. var x10 = x1 - x0, y10 = y1 - y0,
  11990. x32 = x3 - x2, y32 = y3 - y2,
  11991. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11992. return [x0 + t * x10, y0 + t * y10];
  11993. }
  11994. // Compute perpendicular offset line of length rc.
  11995. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11996. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11997. var x01 = x0 - x1,
  11998. y01 = y0 - y1,
  11999. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  12000. ox = lo * y01,
  12001. oy = -lo * x01,
  12002. x11 = x0 + ox,
  12003. y11 = y0 + oy,
  12004. x10 = x1 + ox,
  12005. y10 = y1 + oy,
  12006. x00 = (x11 + x10) / 2,
  12007. y00 = (y11 + y10) / 2,
  12008. dx = x10 - x11,
  12009. dy = y10 - y11,
  12010. d2 = dx * dx + dy * dy,
  12011. r = r1 - rc,
  12012. D = x11 * y10 - x10 * y11,
  12013. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  12014. cx0 = (D * dy - dx * d) / d2,
  12015. cy0 = (-D * dx - dy * d) / d2,
  12016. cx1 = (D * dy + dx * d) / d2,
  12017. cy1 = (-D * dx + dy * d) / d2,
  12018. dx0 = cx0 - x00,
  12019. dy0 = cy0 - y00,
  12020. dx1 = cx1 - x00,
  12021. dy1 = cy1 - y00;
  12022. // Pick the closer of the two intersection points.
  12023. // TODO Is there a faster way to determine which intersection to use?
  12024. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  12025. return {
  12026. cx: cx0,
  12027. cy: cy0,
  12028. x01: -ox,
  12029. y01: -oy,
  12030. x11: cx0 * (r1 / r - 1),
  12031. y11: cy0 * (r1 / r - 1)
  12032. };
  12033. }
  12034. function arc() {
  12035. var innerRadius = arcInnerRadius,
  12036. outerRadius = arcOuterRadius,
  12037. cornerRadius = constant$b(0),
  12038. padRadius = null,
  12039. startAngle = arcStartAngle,
  12040. endAngle = arcEndAngle,
  12041. padAngle = arcPadAngle,
  12042. context = null;
  12043. function arc() {
  12044. var buffer,
  12045. r,
  12046. r0 = +innerRadius.apply(this, arguments),
  12047. r1 = +outerRadius.apply(this, arguments),
  12048. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12049. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12050. da = abs$1(a1 - a0),
  12051. cw = a1 > a0;
  12052. if (!context) context = buffer = path();
  12053. // Ensure that the outer radius is always larger than the inner radius.
  12054. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12055. // Is it a point?
  12056. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12057. // Or is it a circle or annulus?
  12058. else if (da > tau$4 - epsilon$3) {
  12059. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12060. context.arc(0, 0, r1, a0, a1, !cw);
  12061. if (r0 > epsilon$3) {
  12062. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12063. context.arc(0, 0, r0, a1, a0, cw);
  12064. }
  12065. }
  12066. // Or is it a circular or annular sector?
  12067. else {
  12068. var a01 = a0,
  12069. a11 = a1,
  12070. a00 = a0,
  12071. a10 = a1,
  12072. da0 = da,
  12073. da1 = da,
  12074. ap = padAngle.apply(this, arguments) / 2,
  12075. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12076. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12077. rc0 = rc,
  12078. rc1 = rc,
  12079. t0,
  12080. t1;
  12081. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12082. if (rp > epsilon$3) {
  12083. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12084. p1 = asin$1(rp / r1 * sin$2(ap));
  12085. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12086. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12087. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12088. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12089. }
  12090. var x01 = r1 * cos$2(a01),
  12091. y01 = r1 * sin$2(a01),
  12092. x10 = r0 * cos$2(a10),
  12093. y10 = r0 * sin$2(a10);
  12094. // Apply rounded corners?
  12095. if (rc > epsilon$3) {
  12096. var x11 = r1 * cos$2(a11),
  12097. y11 = r1 * sin$2(a11),
  12098. x00 = r0 * cos$2(a00),
  12099. y00 = r0 * sin$2(a00);
  12100. // Restrict the corner radius according to the sector angle.
  12101. if (da < pi$4) {
  12102. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  12103. ax = x01 - oc[0],
  12104. ay = y01 - oc[1],
  12105. bx = x11 - oc[0],
  12106. by = y11 - oc[1],
  12107. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12108. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12109. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12110. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12111. }
  12112. }
  12113. // Is the sector collapsed to a line?
  12114. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12115. // Does the sector’s outer ring have rounded corners?
  12116. else if (rc1 > epsilon$3) {
  12117. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12118. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12119. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12120. // Have the corners merged?
  12121. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12122. // Otherwise, draw the two corners and the ring.
  12123. else {
  12124. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12125. context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  12126. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12127. }
  12128. }
  12129. // Or is the outer ring just a circular arc?
  12130. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12131. // Is there no inner ring, and it’s a circular sector?
  12132. // Or perhaps it’s an annular sector collapsed due to padding?
  12133. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12134. // Does the sector’s inner ring (or point) have rounded corners?
  12135. else if (rc0 > epsilon$3) {
  12136. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12137. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12138. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12139. // Have the corners merged?
  12140. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12141. // Otherwise, draw the two corners and the ring.
  12142. else {
  12143. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12144. context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  12145. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12146. }
  12147. }
  12148. // Or is the inner ring just a circular arc?
  12149. else context.arc(0, 0, r0, a10, a00, cw);
  12150. }
  12151. context.closePath();
  12152. if (buffer) return context = null, buffer + "" || null;
  12153. }
  12154. arc.centroid = function() {
  12155. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12156. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12157. return [cos$2(a) * r, sin$2(a) * r];
  12158. };
  12159. arc.innerRadius = function(_) {
  12160. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12161. };
  12162. arc.outerRadius = function(_) {
  12163. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12164. };
  12165. arc.cornerRadius = function(_) {
  12166. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12167. };
  12168. arc.padRadius = function(_) {
  12169. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12170. };
  12171. arc.startAngle = function(_) {
  12172. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12173. };
  12174. arc.endAngle = function(_) {
  12175. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12176. };
  12177. arc.padAngle = function(_) {
  12178. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12179. };
  12180. arc.context = function(_) {
  12181. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12182. };
  12183. return arc;
  12184. }
  12185. function Linear(context) {
  12186. this._context = context;
  12187. }
  12188. Linear.prototype = {
  12189. areaStart: function() {
  12190. this._line = 0;
  12191. },
  12192. areaEnd: function() {
  12193. this._line = NaN;
  12194. },
  12195. lineStart: function() {
  12196. this._point = 0;
  12197. },
  12198. lineEnd: function() {
  12199. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12200. this._line = 1 - this._line;
  12201. },
  12202. point: function(x, y) {
  12203. x = +x, y = +y;
  12204. switch (this._point) {
  12205. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12206. case 1: this._point = 2; // proceed
  12207. default: this._context.lineTo(x, y); break;
  12208. }
  12209. }
  12210. };
  12211. function curveLinear(context) {
  12212. return new Linear(context);
  12213. }
  12214. function x$3(p) {
  12215. return p[0];
  12216. }
  12217. function y$3(p) {
  12218. return p[1];
  12219. }
  12220. function line() {
  12221. var x$$1 = x$3,
  12222. y$$1 = y$3,
  12223. defined = constant$b(true),
  12224. context = null,
  12225. curve = curveLinear,
  12226. output = null;
  12227. function line(data) {
  12228. var i,
  12229. n = data.length,
  12230. d,
  12231. defined0 = false,
  12232. buffer;
  12233. if (context == null) output = curve(buffer = path());
  12234. for (i = 0; i <= n; ++i) {
  12235. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12236. if (defined0 = !defined0) output.lineStart();
  12237. else output.lineEnd();
  12238. }
  12239. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  12240. }
  12241. if (buffer) return output = null, buffer + "" || null;
  12242. }
  12243. line.x = function(_) {
  12244. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : x$$1;
  12245. };
  12246. line.y = function(_) {
  12247. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : y$$1;
  12248. };
  12249. line.defined = function(_) {
  12250. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12251. };
  12252. line.curve = function(_) {
  12253. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12254. };
  12255. line.context = function(_) {
  12256. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12257. };
  12258. return line;
  12259. }
  12260. function area$3() {
  12261. var x0 = x$3,
  12262. x1 = null,
  12263. y0 = constant$b(0),
  12264. y1 = y$3,
  12265. defined = constant$b(true),
  12266. context = null,
  12267. curve = curveLinear,
  12268. output = null;
  12269. function area(data) {
  12270. var i,
  12271. j,
  12272. k,
  12273. n = data.length,
  12274. d,
  12275. defined0 = false,
  12276. buffer,
  12277. x0z = new Array(n),
  12278. y0z = new Array(n);
  12279. if (context == null) output = curve(buffer = path());
  12280. for (i = 0; i <= n; ++i) {
  12281. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12282. if (defined0 = !defined0) {
  12283. j = i;
  12284. output.areaStart();
  12285. output.lineStart();
  12286. } else {
  12287. output.lineEnd();
  12288. output.lineStart();
  12289. for (k = i - 1; k >= j; --k) {
  12290. output.point(x0z[k], y0z[k]);
  12291. }
  12292. output.lineEnd();
  12293. output.areaEnd();
  12294. }
  12295. }
  12296. if (defined0) {
  12297. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12298. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12299. }
  12300. }
  12301. if (buffer) return output = null, buffer + "" || null;
  12302. }
  12303. function arealine() {
  12304. return line().defined(defined).curve(curve).context(context);
  12305. }
  12306. area.x = function(_) {
  12307. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12308. };
  12309. area.x0 = function(_) {
  12310. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12311. };
  12312. area.x1 = function(_) {
  12313. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12314. };
  12315. area.y = function(_) {
  12316. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12317. };
  12318. area.y0 = function(_) {
  12319. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12320. };
  12321. area.y1 = function(_) {
  12322. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12323. };
  12324. area.lineX0 =
  12325. area.lineY0 = function() {
  12326. return arealine().x(x0).y(y0);
  12327. };
  12328. area.lineY1 = function() {
  12329. return arealine().x(x0).y(y1);
  12330. };
  12331. area.lineX1 = function() {
  12332. return arealine().x(x1).y(y0);
  12333. };
  12334. area.defined = function(_) {
  12335. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12336. };
  12337. area.curve = function(_) {
  12338. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12339. };
  12340. area.context = function(_) {
  12341. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12342. };
  12343. return area;
  12344. }
  12345. function descending$1(a, b) {
  12346. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12347. }
  12348. function identity$7(d) {
  12349. return d;
  12350. }
  12351. function pie() {
  12352. var value = identity$7,
  12353. sortValues = descending$1,
  12354. sort = null,
  12355. startAngle = constant$b(0),
  12356. endAngle = constant$b(tau$4),
  12357. padAngle = constant$b(0);
  12358. function pie(data) {
  12359. var i,
  12360. n = data.length,
  12361. j,
  12362. k,
  12363. sum = 0,
  12364. index = new Array(n),
  12365. arcs = new Array(n),
  12366. a0 = +startAngle.apply(this, arguments),
  12367. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12368. a1,
  12369. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12370. pa = p * (da < 0 ? -1 : 1),
  12371. v;
  12372. for (i = 0; i < n; ++i) {
  12373. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12374. sum += v;
  12375. }
  12376. }
  12377. // Optionally sort the arcs by previously-computed values or by data.
  12378. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12379. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12380. // Compute the arcs! They are stored in the original data's order.
  12381. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12382. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12383. data: data[j],
  12384. index: i,
  12385. value: v,
  12386. startAngle: a0,
  12387. endAngle: a1,
  12388. padAngle: p
  12389. };
  12390. }
  12391. return arcs;
  12392. }
  12393. pie.value = function(_) {
  12394. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12395. };
  12396. pie.sortValues = function(_) {
  12397. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12398. };
  12399. pie.sort = function(_) {
  12400. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12401. };
  12402. pie.startAngle = function(_) {
  12403. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12404. };
  12405. pie.endAngle = function(_) {
  12406. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12407. };
  12408. pie.padAngle = function(_) {
  12409. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12410. };
  12411. return pie;
  12412. }
  12413. var curveRadialLinear = curveRadial(curveLinear);
  12414. function Radial(curve) {
  12415. this._curve = curve;
  12416. }
  12417. Radial.prototype = {
  12418. areaStart: function() {
  12419. this._curve.areaStart();
  12420. },
  12421. areaEnd: function() {
  12422. this._curve.areaEnd();
  12423. },
  12424. lineStart: function() {
  12425. this._curve.lineStart();
  12426. },
  12427. lineEnd: function() {
  12428. this._curve.lineEnd();
  12429. },
  12430. point: function(a, r) {
  12431. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12432. }
  12433. };
  12434. function curveRadial(curve) {
  12435. function radial(context) {
  12436. return new Radial(curve(context));
  12437. }
  12438. radial._curve = curve;
  12439. return radial;
  12440. }
  12441. function lineRadial(l) {
  12442. var c = l.curve;
  12443. l.angle = l.x, delete l.x;
  12444. l.radius = l.y, delete l.y;
  12445. l.curve = function(_) {
  12446. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12447. };
  12448. return l;
  12449. }
  12450. function lineRadial$1() {
  12451. return lineRadial(line().curve(curveRadialLinear));
  12452. }
  12453. function areaRadial() {
  12454. var a = area$3().curve(curveRadialLinear),
  12455. c = a.curve,
  12456. x0 = a.lineX0,
  12457. x1 = a.lineX1,
  12458. y0 = a.lineY0,
  12459. y1 = a.lineY1;
  12460. a.angle = a.x, delete a.x;
  12461. a.startAngle = a.x0, delete a.x0;
  12462. a.endAngle = a.x1, delete a.x1;
  12463. a.radius = a.y, delete a.y;
  12464. a.innerRadius = a.y0, delete a.y0;
  12465. a.outerRadius = a.y1, delete a.y1;
  12466. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12467. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12468. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12469. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12470. a.curve = function(_) {
  12471. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12472. };
  12473. return a;
  12474. }
  12475. function pointRadial(x, y) {
  12476. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12477. }
  12478. var slice$6 = Array.prototype.slice;
  12479. function linkSource(d) {
  12480. return d.source;
  12481. }
  12482. function linkTarget(d) {
  12483. return d.target;
  12484. }
  12485. function link$2(curve) {
  12486. var source = linkSource,
  12487. target = linkTarget,
  12488. x$$1 = x$3,
  12489. y$$1 = y$3,
  12490. context = null;
  12491. function link() {
  12492. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12493. if (!context) context = buffer = path();
  12494. curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
  12495. if (buffer) return context = null, buffer + "" || null;
  12496. }
  12497. link.source = function(_) {
  12498. return arguments.length ? (source = _, link) : source;
  12499. };
  12500. link.target = function(_) {
  12501. return arguments.length ? (target = _, link) : target;
  12502. };
  12503. link.x = function(_) {
  12504. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : x$$1;
  12505. };
  12506. link.y = function(_) {
  12507. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : y$$1;
  12508. };
  12509. link.context = function(_) {
  12510. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  12511. };
  12512. return link;
  12513. }
  12514. function curveHorizontal(context, x0, y0, x1, y1) {
  12515. context.moveTo(x0, y0);
  12516. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12517. }
  12518. function curveVertical(context, x0, y0, x1, y1) {
  12519. context.moveTo(x0, y0);
  12520. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12521. }
  12522. function curveRadial$1(context, x0, y0, x1, y1) {
  12523. var p0 = pointRadial(x0, y0),
  12524. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12525. p2 = pointRadial(x1, y0),
  12526. p3 = pointRadial(x1, y1);
  12527. context.moveTo(p0[0], p0[1]);
  12528. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12529. }
  12530. function linkHorizontal() {
  12531. return link$2(curveHorizontal);
  12532. }
  12533. function linkVertical() {
  12534. return link$2(curveVertical);
  12535. }
  12536. function linkRadial() {
  12537. var l = link$2(curveRadial$1);
  12538. l.angle = l.x, delete l.x;
  12539. l.radius = l.y, delete l.y;
  12540. return l;
  12541. }
  12542. var circle$2 = {
  12543. draw: function(context, size) {
  12544. var r = Math.sqrt(size / pi$4);
  12545. context.moveTo(r, 0);
  12546. context.arc(0, 0, r, 0, tau$4);
  12547. }
  12548. };
  12549. var cross$2 = {
  12550. draw: function(context, size) {
  12551. var r = Math.sqrt(size / 5) / 2;
  12552. context.moveTo(-3 * r, -r);
  12553. context.lineTo(-r, -r);
  12554. context.lineTo(-r, -3 * r);
  12555. context.lineTo(r, -3 * r);
  12556. context.lineTo(r, -r);
  12557. context.lineTo(3 * r, -r);
  12558. context.lineTo(3 * r, r);
  12559. context.lineTo(r, r);
  12560. context.lineTo(r, 3 * r);
  12561. context.lineTo(-r, 3 * r);
  12562. context.lineTo(-r, r);
  12563. context.lineTo(-3 * r, r);
  12564. context.closePath();
  12565. }
  12566. };
  12567. var tan30 = Math.sqrt(1 / 3),
  12568. tan30_2 = tan30 * 2;
  12569. var diamond = {
  12570. draw: function(context, size) {
  12571. var y = Math.sqrt(size / tan30_2),
  12572. x = y * tan30;
  12573. context.moveTo(0, -y);
  12574. context.lineTo(x, 0);
  12575. context.lineTo(0, y);
  12576. context.lineTo(-x, 0);
  12577. context.closePath();
  12578. }
  12579. };
  12580. var ka = 0.89081309152928522810,
  12581. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12582. kx = Math.sin(tau$4 / 10) * kr,
  12583. ky = -Math.cos(tau$4 / 10) * kr;
  12584. var star = {
  12585. draw: function(context, size) {
  12586. var r = Math.sqrt(size * ka),
  12587. x = kx * r,
  12588. y = ky * r;
  12589. context.moveTo(0, -r);
  12590. context.lineTo(x, y);
  12591. for (var i = 1; i < 5; ++i) {
  12592. var a = tau$4 * i / 5,
  12593. c = Math.cos(a),
  12594. s = Math.sin(a);
  12595. context.lineTo(s * r, -c * r);
  12596. context.lineTo(c * x - s * y, s * x + c * y);
  12597. }
  12598. context.closePath();
  12599. }
  12600. };
  12601. var square = {
  12602. draw: function(context, size) {
  12603. var w = Math.sqrt(size),
  12604. x = -w / 2;
  12605. context.rect(x, x, w, w);
  12606. }
  12607. };
  12608. var sqrt3 = Math.sqrt(3);
  12609. var triangle = {
  12610. draw: function(context, size) {
  12611. var y = -Math.sqrt(size / (sqrt3 * 3));
  12612. context.moveTo(0, y * 2);
  12613. context.lineTo(-sqrt3 * y, -y);
  12614. context.lineTo(sqrt3 * y, -y);
  12615. context.closePath();
  12616. }
  12617. };
  12618. var c$2 = -0.5,
  12619. s = Math.sqrt(3) / 2,
  12620. k = 1 / Math.sqrt(12),
  12621. a = (k / 2 + 1) * 3;
  12622. var wye = {
  12623. draw: function(context, size) {
  12624. var r = Math.sqrt(size / a),
  12625. x0 = r / 2,
  12626. y0 = r * k,
  12627. x1 = x0,
  12628. y1 = r * k + r,
  12629. x2 = -x1,
  12630. y2 = y1;
  12631. context.moveTo(x0, y0);
  12632. context.lineTo(x1, y1);
  12633. context.lineTo(x2, y2);
  12634. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  12635. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  12636. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  12637. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  12638. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  12639. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  12640. context.closePath();
  12641. }
  12642. };
  12643. var symbols = [
  12644. circle$2,
  12645. cross$2,
  12646. diamond,
  12647. square,
  12648. star,
  12649. triangle,
  12650. wye
  12651. ];
  12652. function symbol() {
  12653. var type = constant$b(circle$2),
  12654. size = constant$b(64),
  12655. context = null;
  12656. function symbol() {
  12657. var buffer;
  12658. if (!context) context = buffer = path();
  12659. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12660. if (buffer) return context = null, buffer + "" || null;
  12661. }
  12662. symbol.type = function(_) {
  12663. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  12664. };
  12665. symbol.size = function(_) {
  12666. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  12667. };
  12668. symbol.context = function(_) {
  12669. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12670. };
  12671. return symbol;
  12672. }
  12673. function noop$3() {}
  12674. function point$2(that, x, y) {
  12675. that._context.bezierCurveTo(
  12676. (2 * that._x0 + that._x1) / 3,
  12677. (2 * that._y0 + that._y1) / 3,
  12678. (that._x0 + 2 * that._x1) / 3,
  12679. (that._y0 + 2 * that._y1) / 3,
  12680. (that._x0 + 4 * that._x1 + x) / 6,
  12681. (that._y0 + 4 * that._y1 + y) / 6
  12682. );
  12683. }
  12684. function Basis(context) {
  12685. this._context = context;
  12686. }
  12687. Basis.prototype = {
  12688. areaStart: function() {
  12689. this._line = 0;
  12690. },
  12691. areaEnd: function() {
  12692. this._line = NaN;
  12693. },
  12694. lineStart: function() {
  12695. this._x0 = this._x1 =
  12696. this._y0 = this._y1 = NaN;
  12697. this._point = 0;
  12698. },
  12699. lineEnd: function() {
  12700. switch (this._point) {
  12701. case 3: point$2(this, this._x1, this._y1); // proceed
  12702. case 2: this._context.lineTo(this._x1, this._y1); break;
  12703. }
  12704. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12705. this._line = 1 - this._line;
  12706. },
  12707. point: function(x, y) {
  12708. x = +x, y = +y;
  12709. switch (this._point) {
  12710. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12711. case 1: this._point = 2; break;
  12712. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12713. default: point$2(this, x, y); break;
  12714. }
  12715. this._x0 = this._x1, this._x1 = x;
  12716. this._y0 = this._y1, this._y1 = y;
  12717. }
  12718. };
  12719. function basis$2(context) {
  12720. return new Basis(context);
  12721. }
  12722. function BasisClosed(context) {
  12723. this._context = context;
  12724. }
  12725. BasisClosed.prototype = {
  12726. areaStart: noop$3,
  12727. areaEnd: noop$3,
  12728. lineStart: function() {
  12729. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12730. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12731. this._point = 0;
  12732. },
  12733. lineEnd: function() {
  12734. switch (this._point) {
  12735. case 1: {
  12736. this._context.moveTo(this._x2, this._y2);
  12737. this._context.closePath();
  12738. break;
  12739. }
  12740. case 2: {
  12741. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12742. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12743. this._context.closePath();
  12744. break;
  12745. }
  12746. case 3: {
  12747. this.point(this._x2, this._y2);
  12748. this.point(this._x3, this._y3);
  12749. this.point(this._x4, this._y4);
  12750. break;
  12751. }
  12752. }
  12753. },
  12754. point: function(x, y) {
  12755. x = +x, y = +y;
  12756. switch (this._point) {
  12757. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12758. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12759. 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;
  12760. default: point$2(this, x, y); break;
  12761. }
  12762. this._x0 = this._x1, this._x1 = x;
  12763. this._y0 = this._y1, this._y1 = y;
  12764. }
  12765. };
  12766. function basisClosed$1(context) {
  12767. return new BasisClosed(context);
  12768. }
  12769. function BasisOpen(context) {
  12770. this._context = context;
  12771. }
  12772. BasisOpen.prototype = {
  12773. areaStart: function() {
  12774. this._line = 0;
  12775. },
  12776. areaEnd: function() {
  12777. this._line = NaN;
  12778. },
  12779. lineStart: function() {
  12780. this._x0 = this._x1 =
  12781. this._y0 = this._y1 = NaN;
  12782. this._point = 0;
  12783. },
  12784. lineEnd: function() {
  12785. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12786. this._line = 1 - this._line;
  12787. },
  12788. point: function(x, y) {
  12789. x = +x, y = +y;
  12790. switch (this._point) {
  12791. case 0: this._point = 1; break;
  12792. case 1: this._point = 2; break;
  12793. 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;
  12794. case 3: this._point = 4; // proceed
  12795. default: point$2(this, x, y); break;
  12796. }
  12797. this._x0 = this._x1, this._x1 = x;
  12798. this._y0 = this._y1, this._y1 = y;
  12799. }
  12800. };
  12801. function basisOpen(context) {
  12802. return new BasisOpen(context);
  12803. }
  12804. function Bundle(context, beta) {
  12805. this._basis = new Basis(context);
  12806. this._beta = beta;
  12807. }
  12808. Bundle.prototype = {
  12809. lineStart: function() {
  12810. this._x = [];
  12811. this._y = [];
  12812. this._basis.lineStart();
  12813. },
  12814. lineEnd: function() {
  12815. var x = this._x,
  12816. y = this._y,
  12817. j = x.length - 1;
  12818. if (j > 0) {
  12819. var x0 = x[0],
  12820. y0 = y[0],
  12821. dx = x[j] - x0,
  12822. dy = y[j] - y0,
  12823. i = -1,
  12824. t;
  12825. while (++i <= j) {
  12826. t = i / j;
  12827. this._basis.point(
  12828. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12829. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12830. );
  12831. }
  12832. }
  12833. this._x = this._y = null;
  12834. this._basis.lineEnd();
  12835. },
  12836. point: function(x, y) {
  12837. this._x.push(+x);
  12838. this._y.push(+y);
  12839. }
  12840. };
  12841. var bundle = (function custom(beta) {
  12842. function bundle(context) {
  12843. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12844. }
  12845. bundle.beta = function(beta) {
  12846. return custom(+beta);
  12847. };
  12848. return bundle;
  12849. })(0.85);
  12850. function point$3(that, x, y) {
  12851. that._context.bezierCurveTo(
  12852. that._x1 + that._k * (that._x2 - that._x0),
  12853. that._y1 + that._k * (that._y2 - that._y0),
  12854. that._x2 + that._k * (that._x1 - x),
  12855. that._y2 + that._k * (that._y1 - y),
  12856. that._x2,
  12857. that._y2
  12858. );
  12859. }
  12860. function Cardinal(context, tension) {
  12861. this._context = context;
  12862. this._k = (1 - tension) / 6;
  12863. }
  12864. Cardinal.prototype = {
  12865. areaStart: function() {
  12866. this._line = 0;
  12867. },
  12868. areaEnd: function() {
  12869. this._line = NaN;
  12870. },
  12871. lineStart: function() {
  12872. this._x0 = this._x1 = this._x2 =
  12873. this._y0 = this._y1 = this._y2 = NaN;
  12874. this._point = 0;
  12875. },
  12876. lineEnd: function() {
  12877. switch (this._point) {
  12878. case 2: this._context.lineTo(this._x2, this._y2); break;
  12879. case 3: point$3(this, this._x1, this._y1); break;
  12880. }
  12881. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12882. this._line = 1 - this._line;
  12883. },
  12884. point: function(x, y) {
  12885. x = +x, y = +y;
  12886. switch (this._point) {
  12887. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12888. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12889. case 2: this._point = 3; // proceed
  12890. default: point$3(this, x, y); break;
  12891. }
  12892. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12893. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12894. }
  12895. };
  12896. var cardinal = (function custom(tension) {
  12897. function cardinal(context) {
  12898. return new Cardinal(context, tension);
  12899. }
  12900. cardinal.tension = function(tension) {
  12901. return custom(+tension);
  12902. };
  12903. return cardinal;
  12904. })(0);
  12905. function CardinalClosed(context, tension) {
  12906. this._context = context;
  12907. this._k = (1 - tension) / 6;
  12908. }
  12909. CardinalClosed.prototype = {
  12910. areaStart: noop$3,
  12911. areaEnd: noop$3,
  12912. lineStart: function() {
  12913. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12914. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12915. this._point = 0;
  12916. },
  12917. lineEnd: function() {
  12918. switch (this._point) {
  12919. case 1: {
  12920. this._context.moveTo(this._x3, this._y3);
  12921. this._context.closePath();
  12922. break;
  12923. }
  12924. case 2: {
  12925. this._context.lineTo(this._x3, this._y3);
  12926. this._context.closePath();
  12927. break;
  12928. }
  12929. case 3: {
  12930. this.point(this._x3, this._y3);
  12931. this.point(this._x4, this._y4);
  12932. this.point(this._x5, this._y5);
  12933. break;
  12934. }
  12935. }
  12936. },
  12937. point: function(x, y) {
  12938. x = +x, y = +y;
  12939. switch (this._point) {
  12940. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12941. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12942. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12943. default: point$3(this, x, y); break;
  12944. }
  12945. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12946. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12947. }
  12948. };
  12949. var cardinalClosed = (function custom(tension) {
  12950. function cardinal$$1(context) {
  12951. return new CardinalClosed(context, tension);
  12952. }
  12953. cardinal$$1.tension = function(tension) {
  12954. return custom(+tension);
  12955. };
  12956. return cardinal$$1;
  12957. })(0);
  12958. function CardinalOpen(context, tension) {
  12959. this._context = context;
  12960. this._k = (1 - tension) / 6;
  12961. }
  12962. CardinalOpen.prototype = {
  12963. areaStart: function() {
  12964. this._line = 0;
  12965. },
  12966. areaEnd: function() {
  12967. this._line = NaN;
  12968. },
  12969. lineStart: function() {
  12970. this._x0 = this._x1 = this._x2 =
  12971. this._y0 = this._y1 = this._y2 = NaN;
  12972. this._point = 0;
  12973. },
  12974. lineEnd: function() {
  12975. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12976. this._line = 1 - this._line;
  12977. },
  12978. point: function(x, y) {
  12979. x = +x, y = +y;
  12980. switch (this._point) {
  12981. case 0: this._point = 1; break;
  12982. case 1: this._point = 2; break;
  12983. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12984. case 3: this._point = 4; // proceed
  12985. default: point$3(this, x, y); break;
  12986. }
  12987. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12988. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12989. }
  12990. };
  12991. var cardinalOpen = (function custom(tension) {
  12992. function cardinal$$1(context) {
  12993. return new CardinalOpen(context, tension);
  12994. }
  12995. cardinal$$1.tension = function(tension) {
  12996. return custom(+tension);
  12997. };
  12998. return cardinal$$1;
  12999. })(0);
  13000. function point$4(that, x, y) {
  13001. var x1 = that._x1,
  13002. y1 = that._y1,
  13003. x2 = that._x2,
  13004. y2 = that._y2;
  13005. if (that._l01_a > epsilon$3) {
  13006. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  13007. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  13008. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  13009. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  13010. }
  13011. if (that._l23_a > epsilon$3) {
  13012. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  13013. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  13014. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  13015. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  13016. }
  13017. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  13018. }
  13019. function CatmullRom(context, alpha) {
  13020. this._context = context;
  13021. this._alpha = alpha;
  13022. }
  13023. CatmullRom.prototype = {
  13024. areaStart: function() {
  13025. this._line = 0;
  13026. },
  13027. areaEnd: function() {
  13028. this._line = NaN;
  13029. },
  13030. lineStart: function() {
  13031. this._x0 = this._x1 = this._x2 =
  13032. this._y0 = this._y1 = this._y2 = NaN;
  13033. this._l01_a = this._l12_a = this._l23_a =
  13034. this._l01_2a = this._l12_2a = this._l23_2a =
  13035. this._point = 0;
  13036. },
  13037. lineEnd: function() {
  13038. switch (this._point) {
  13039. case 2: this._context.lineTo(this._x2, this._y2); break;
  13040. case 3: this.point(this._x2, this._y2); break;
  13041. }
  13042. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13043. this._line = 1 - this._line;
  13044. },
  13045. point: function(x, y) {
  13046. x = +x, y = +y;
  13047. if (this._point) {
  13048. var x23 = this._x2 - x,
  13049. y23 = this._y2 - y;
  13050. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13051. }
  13052. switch (this._point) {
  13053. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13054. case 1: this._point = 2; break;
  13055. case 2: this._point = 3; // proceed
  13056. default: point$4(this, x, y); break;
  13057. }
  13058. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13059. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13060. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13061. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13062. }
  13063. };
  13064. var catmullRom = (function custom(alpha) {
  13065. function catmullRom(context) {
  13066. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13067. }
  13068. catmullRom.alpha = function(alpha) {
  13069. return custom(+alpha);
  13070. };
  13071. return catmullRom;
  13072. })(0.5);
  13073. function CatmullRomClosed(context, alpha) {
  13074. this._context = context;
  13075. this._alpha = alpha;
  13076. }
  13077. CatmullRomClosed.prototype = {
  13078. areaStart: noop$3,
  13079. areaEnd: noop$3,
  13080. lineStart: function() {
  13081. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13082. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13083. this._l01_a = this._l12_a = this._l23_a =
  13084. this._l01_2a = this._l12_2a = this._l23_2a =
  13085. this._point = 0;
  13086. },
  13087. lineEnd: function() {
  13088. switch (this._point) {
  13089. case 1: {
  13090. this._context.moveTo(this._x3, this._y3);
  13091. this._context.closePath();
  13092. break;
  13093. }
  13094. case 2: {
  13095. this._context.lineTo(this._x3, this._y3);
  13096. this._context.closePath();
  13097. break;
  13098. }
  13099. case 3: {
  13100. this.point(this._x3, this._y3);
  13101. this.point(this._x4, this._y4);
  13102. this.point(this._x5, this._y5);
  13103. break;
  13104. }
  13105. }
  13106. },
  13107. point: function(x, y) {
  13108. x = +x, y = +y;
  13109. if (this._point) {
  13110. var x23 = this._x2 - x,
  13111. y23 = this._y2 - y;
  13112. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13113. }
  13114. switch (this._point) {
  13115. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13116. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13117. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13118. default: point$4(this, x, y); break;
  13119. }
  13120. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13121. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13122. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13123. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13124. }
  13125. };
  13126. var catmullRomClosed = (function custom(alpha) {
  13127. function catmullRom$$1(context) {
  13128. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13129. }
  13130. catmullRom$$1.alpha = function(alpha) {
  13131. return custom(+alpha);
  13132. };
  13133. return catmullRom$$1;
  13134. })(0.5);
  13135. function CatmullRomOpen(context, alpha) {
  13136. this._context = context;
  13137. this._alpha = alpha;
  13138. }
  13139. CatmullRomOpen.prototype = {
  13140. areaStart: function() {
  13141. this._line = 0;
  13142. },
  13143. areaEnd: function() {
  13144. this._line = NaN;
  13145. },
  13146. lineStart: function() {
  13147. this._x0 = this._x1 = this._x2 =
  13148. this._y0 = this._y1 = this._y2 = NaN;
  13149. this._l01_a = this._l12_a = this._l23_a =
  13150. this._l01_2a = this._l12_2a = this._l23_2a =
  13151. this._point = 0;
  13152. },
  13153. lineEnd: function() {
  13154. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13155. this._line = 1 - this._line;
  13156. },
  13157. point: function(x, y) {
  13158. x = +x, y = +y;
  13159. if (this._point) {
  13160. var x23 = this._x2 - x,
  13161. y23 = this._y2 - y;
  13162. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13163. }
  13164. switch (this._point) {
  13165. case 0: this._point = 1; break;
  13166. case 1: this._point = 2; break;
  13167. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13168. case 3: this._point = 4; // proceed
  13169. default: point$4(this, x, y); break;
  13170. }
  13171. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13172. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13173. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13174. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13175. }
  13176. };
  13177. var catmullRomOpen = (function custom(alpha) {
  13178. function catmullRom$$1(context) {
  13179. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13180. }
  13181. catmullRom$$1.alpha = function(alpha) {
  13182. return custom(+alpha);
  13183. };
  13184. return catmullRom$$1;
  13185. })(0.5);
  13186. function LinearClosed(context) {
  13187. this._context = context;
  13188. }
  13189. LinearClosed.prototype = {
  13190. areaStart: noop$3,
  13191. areaEnd: noop$3,
  13192. lineStart: function() {
  13193. this._point = 0;
  13194. },
  13195. lineEnd: function() {
  13196. if (this._point) this._context.closePath();
  13197. },
  13198. point: function(x, y) {
  13199. x = +x, y = +y;
  13200. if (this._point) this._context.lineTo(x, y);
  13201. else this._point = 1, this._context.moveTo(x, y);
  13202. }
  13203. };
  13204. function linearClosed(context) {
  13205. return new LinearClosed(context);
  13206. }
  13207. function sign$1(x) {
  13208. return x < 0 ? -1 : 1;
  13209. }
  13210. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13211. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13212. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13213. // NOV(II), P. 443, 1990.
  13214. function slope3(that, x2, y2) {
  13215. var h0 = that._x1 - that._x0,
  13216. h1 = x2 - that._x1,
  13217. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13218. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13219. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13220. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13221. }
  13222. // Calculate a one-sided slope.
  13223. function slope2(that, t) {
  13224. var h = that._x1 - that._x0;
  13225. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13226. }
  13227. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13228. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13229. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13230. function point$5(that, t0, t1) {
  13231. var x0 = that._x0,
  13232. y0 = that._y0,
  13233. x1 = that._x1,
  13234. y1 = that._y1,
  13235. dx = (x1 - x0) / 3;
  13236. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13237. }
  13238. function MonotoneX(context) {
  13239. this._context = context;
  13240. }
  13241. MonotoneX.prototype = {
  13242. areaStart: function() {
  13243. this._line = 0;
  13244. },
  13245. areaEnd: function() {
  13246. this._line = NaN;
  13247. },
  13248. lineStart: function() {
  13249. this._x0 = this._x1 =
  13250. this._y0 = this._y1 =
  13251. this._t0 = NaN;
  13252. this._point = 0;
  13253. },
  13254. lineEnd: function() {
  13255. switch (this._point) {
  13256. case 2: this._context.lineTo(this._x1, this._y1); break;
  13257. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13258. }
  13259. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13260. this._line = 1 - this._line;
  13261. },
  13262. point: function(x, y) {
  13263. var t1 = NaN;
  13264. x = +x, y = +y;
  13265. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13266. switch (this._point) {
  13267. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13268. case 1: this._point = 2; break;
  13269. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13270. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13271. }
  13272. this._x0 = this._x1, this._x1 = x;
  13273. this._y0 = this._y1, this._y1 = y;
  13274. this._t0 = t1;
  13275. }
  13276. };
  13277. function MonotoneY(context) {
  13278. this._context = new ReflectContext(context);
  13279. }
  13280. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13281. MonotoneX.prototype.point.call(this, y, x);
  13282. };
  13283. function ReflectContext(context) {
  13284. this._context = context;
  13285. }
  13286. ReflectContext.prototype = {
  13287. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13288. closePath: function() { this._context.closePath(); },
  13289. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13290. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13291. };
  13292. function monotoneX(context) {
  13293. return new MonotoneX(context);
  13294. }
  13295. function monotoneY(context) {
  13296. return new MonotoneY(context);
  13297. }
  13298. function Natural(context) {
  13299. this._context = context;
  13300. }
  13301. Natural.prototype = {
  13302. areaStart: function() {
  13303. this._line = 0;
  13304. },
  13305. areaEnd: function() {
  13306. this._line = NaN;
  13307. },
  13308. lineStart: function() {
  13309. this._x = [];
  13310. this._y = [];
  13311. },
  13312. lineEnd: function() {
  13313. var x = this._x,
  13314. y = this._y,
  13315. n = x.length;
  13316. if (n) {
  13317. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13318. if (n === 2) {
  13319. this._context.lineTo(x[1], y[1]);
  13320. } else {
  13321. var px = controlPoints(x),
  13322. py = controlPoints(y);
  13323. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13324. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13325. }
  13326. }
  13327. }
  13328. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13329. this._line = 1 - this._line;
  13330. this._x = this._y = null;
  13331. },
  13332. point: function(x, y) {
  13333. this._x.push(+x);
  13334. this._y.push(+y);
  13335. }
  13336. };
  13337. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13338. function controlPoints(x) {
  13339. var i,
  13340. n = x.length - 1,
  13341. m,
  13342. a = new Array(n),
  13343. b = new Array(n),
  13344. r = new Array(n);
  13345. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13346. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13347. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13348. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13349. a[n - 1] = r[n - 1] / b[n - 1];
  13350. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13351. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13352. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13353. return [a, b];
  13354. }
  13355. function natural(context) {
  13356. return new Natural(context);
  13357. }
  13358. function Step(context, t) {
  13359. this._context = context;
  13360. this._t = t;
  13361. }
  13362. Step.prototype = {
  13363. areaStart: function() {
  13364. this._line = 0;
  13365. },
  13366. areaEnd: function() {
  13367. this._line = NaN;
  13368. },
  13369. lineStart: function() {
  13370. this._x = this._y = NaN;
  13371. this._point = 0;
  13372. },
  13373. lineEnd: function() {
  13374. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13375. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13376. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13377. },
  13378. point: function(x, y) {
  13379. x = +x, y = +y;
  13380. switch (this._point) {
  13381. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13382. case 1: this._point = 2; // proceed
  13383. default: {
  13384. if (this._t <= 0) {
  13385. this._context.lineTo(this._x, y);
  13386. this._context.lineTo(x, y);
  13387. } else {
  13388. var x1 = this._x * (1 - this._t) + x * this._t;
  13389. this._context.lineTo(x1, this._y);
  13390. this._context.lineTo(x1, y);
  13391. }
  13392. break;
  13393. }
  13394. }
  13395. this._x = x, this._y = y;
  13396. }
  13397. };
  13398. function step(context) {
  13399. return new Step(context, 0.5);
  13400. }
  13401. function stepBefore(context) {
  13402. return new Step(context, 0);
  13403. }
  13404. function stepAfter(context) {
  13405. return new Step(context, 1);
  13406. }
  13407. function none$1(series, order) {
  13408. if (!((n = series.length) > 1)) return;
  13409. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13410. s0 = s1, s1 = series[order[i]];
  13411. for (j = 0; j < m; ++j) {
  13412. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13413. }
  13414. }
  13415. }
  13416. function none$2(series) {
  13417. var n = series.length, o = new Array(n);
  13418. while (--n >= 0) o[n] = n;
  13419. return o;
  13420. }
  13421. function stackValue(d, key) {
  13422. return d[key];
  13423. }
  13424. function stack() {
  13425. var keys = constant$b([]),
  13426. order = none$2,
  13427. offset = none$1,
  13428. value = stackValue;
  13429. function stack(data) {
  13430. var kz = keys.apply(this, arguments),
  13431. i,
  13432. m = data.length,
  13433. n = kz.length,
  13434. sz = new Array(n),
  13435. oz;
  13436. for (i = 0; i < n; ++i) {
  13437. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13438. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13439. sij.data = data[j];
  13440. }
  13441. si.key = ki;
  13442. }
  13443. for (i = 0, oz = order(sz); i < n; ++i) {
  13444. sz[oz[i]].index = i;
  13445. }
  13446. offset(sz, oz);
  13447. return sz;
  13448. }
  13449. stack.keys = function(_) {
  13450. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13451. };
  13452. stack.value = function(_) {
  13453. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13454. };
  13455. stack.order = function(_) {
  13456. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13457. };
  13458. stack.offset = function(_) {
  13459. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13460. };
  13461. return stack;
  13462. }
  13463. function expand(series, order) {
  13464. if (!((n = series.length) > 0)) return;
  13465. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13466. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13467. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13468. }
  13469. none$1(series, order);
  13470. }
  13471. function diverging$1(series, order) {
  13472. if (!((n = series.length) > 1)) return;
  13473. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13474. for (yp = yn = 0, i = 0; i < n; ++i) {
  13475. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13476. d[0] = yp, d[1] = yp += dy;
  13477. } else if (dy < 0) {
  13478. d[1] = yn, d[0] = yn += dy;
  13479. } else {
  13480. d[0] = yp;
  13481. }
  13482. }
  13483. }
  13484. }
  13485. function silhouette(series, order) {
  13486. if (!((n = series.length) > 0)) return;
  13487. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13488. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13489. s0[j][1] += s0[j][0] = -y / 2;
  13490. }
  13491. none$1(series, order);
  13492. }
  13493. function wiggle(series, order) {
  13494. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13495. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13496. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13497. var si = series[order[i]],
  13498. sij0 = si[j][1] || 0,
  13499. sij1 = si[j - 1][1] || 0,
  13500. s3 = (sij0 - sij1) / 2;
  13501. for (var k = 0; k < i; ++k) {
  13502. var sk = series[order[k]],
  13503. skj0 = sk[j][1] || 0,
  13504. skj1 = sk[j - 1][1] || 0;
  13505. s3 += skj0 - skj1;
  13506. }
  13507. s1 += sij0, s2 += s3 * sij0;
  13508. }
  13509. s0[j - 1][1] += s0[j - 1][0] = y;
  13510. if (s1) y -= s2 / s1;
  13511. }
  13512. s0[j - 1][1] += s0[j - 1][0] = y;
  13513. none$1(series, order);
  13514. }
  13515. function ascending$3(series) {
  13516. var sums = series.map(sum$2);
  13517. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13518. }
  13519. function sum$2(series) {
  13520. var s = 0, i = -1, n = series.length, v;
  13521. while (++i < n) if (v = +series[i][1]) s += v;
  13522. return s;
  13523. }
  13524. function descending$2(series) {
  13525. return ascending$3(series).reverse();
  13526. }
  13527. function insideOut(series) {
  13528. var n = series.length,
  13529. i,
  13530. j,
  13531. sums = series.map(sum$2),
  13532. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  13533. top = 0,
  13534. bottom = 0,
  13535. tops = [],
  13536. bottoms = [];
  13537. for (i = 0; i < n; ++i) {
  13538. j = order[i];
  13539. if (top < bottom) {
  13540. top += sums[j];
  13541. tops.push(j);
  13542. } else {
  13543. bottom += sums[j];
  13544. bottoms.push(j);
  13545. }
  13546. }
  13547. return bottoms.reverse().concat(tops);
  13548. }
  13549. function reverse(series) {
  13550. return none$2(series).reverse();
  13551. }
  13552. function constant$c(x) {
  13553. return function() {
  13554. return x;
  13555. };
  13556. }
  13557. function x$4(d) {
  13558. return d[0];
  13559. }
  13560. function y$4(d) {
  13561. return d[1];
  13562. }
  13563. function RedBlackTree() {
  13564. this._ = null; // root node
  13565. }
  13566. function RedBlackNode(node) {
  13567. node.U = // parent node
  13568. node.C = // color - true for red, false for black
  13569. node.L = // left node
  13570. node.R = // right node
  13571. node.P = // previous node
  13572. node.N = null; // next node
  13573. }
  13574. RedBlackTree.prototype = {
  13575. constructor: RedBlackTree,
  13576. insert: function(after, node) {
  13577. var parent, grandpa, uncle;
  13578. if (after) {
  13579. node.P = after;
  13580. node.N = after.N;
  13581. if (after.N) after.N.P = node;
  13582. after.N = node;
  13583. if (after.R) {
  13584. after = after.R;
  13585. while (after.L) after = after.L;
  13586. after.L = node;
  13587. } else {
  13588. after.R = node;
  13589. }
  13590. parent = after;
  13591. } else if (this._) {
  13592. after = RedBlackFirst(this._);
  13593. node.P = null;
  13594. node.N = after;
  13595. after.P = after.L = node;
  13596. parent = after;
  13597. } else {
  13598. node.P = node.N = null;
  13599. this._ = node;
  13600. parent = null;
  13601. }
  13602. node.L = node.R = null;
  13603. node.U = parent;
  13604. node.C = true;
  13605. after = node;
  13606. while (parent && parent.C) {
  13607. grandpa = parent.U;
  13608. if (parent === grandpa.L) {
  13609. uncle = grandpa.R;
  13610. if (uncle && uncle.C) {
  13611. parent.C = uncle.C = false;
  13612. grandpa.C = true;
  13613. after = grandpa;
  13614. } else {
  13615. if (after === parent.R) {
  13616. RedBlackRotateLeft(this, parent);
  13617. after = parent;
  13618. parent = after.U;
  13619. }
  13620. parent.C = false;
  13621. grandpa.C = true;
  13622. RedBlackRotateRight(this, grandpa);
  13623. }
  13624. } else {
  13625. uncle = grandpa.L;
  13626. if (uncle && uncle.C) {
  13627. parent.C = uncle.C = false;
  13628. grandpa.C = true;
  13629. after = grandpa;
  13630. } else {
  13631. if (after === parent.L) {
  13632. RedBlackRotateRight(this, parent);
  13633. after = parent;
  13634. parent = after.U;
  13635. }
  13636. parent.C = false;
  13637. grandpa.C = true;
  13638. RedBlackRotateLeft(this, grandpa);
  13639. }
  13640. }
  13641. parent = after.U;
  13642. }
  13643. this._.C = false;
  13644. },
  13645. remove: function(node) {
  13646. if (node.N) node.N.P = node.P;
  13647. if (node.P) node.P.N = node.N;
  13648. node.N = node.P = null;
  13649. var parent = node.U,
  13650. sibling,
  13651. left = node.L,
  13652. right = node.R,
  13653. next,
  13654. red;
  13655. if (!left) next = right;
  13656. else if (!right) next = left;
  13657. else next = RedBlackFirst(right);
  13658. if (parent) {
  13659. if (parent.L === node) parent.L = next;
  13660. else parent.R = next;
  13661. } else {
  13662. this._ = next;
  13663. }
  13664. if (left && right) {
  13665. red = next.C;
  13666. next.C = node.C;
  13667. next.L = left;
  13668. left.U = next;
  13669. if (next !== right) {
  13670. parent = next.U;
  13671. next.U = node.U;
  13672. node = next.R;
  13673. parent.L = node;
  13674. next.R = right;
  13675. right.U = next;
  13676. } else {
  13677. next.U = parent;
  13678. parent = next;
  13679. node = next.R;
  13680. }
  13681. } else {
  13682. red = node.C;
  13683. node = next;
  13684. }
  13685. if (node) node.U = parent;
  13686. if (red) return;
  13687. if (node && node.C) { node.C = false; return; }
  13688. do {
  13689. if (node === this._) break;
  13690. if (node === parent.L) {
  13691. sibling = parent.R;
  13692. if (sibling.C) {
  13693. sibling.C = false;
  13694. parent.C = true;
  13695. RedBlackRotateLeft(this, parent);
  13696. sibling = parent.R;
  13697. }
  13698. if ((sibling.L && sibling.L.C)
  13699. || (sibling.R && sibling.R.C)) {
  13700. if (!sibling.R || !sibling.R.C) {
  13701. sibling.L.C = false;
  13702. sibling.C = true;
  13703. RedBlackRotateRight(this, sibling);
  13704. sibling = parent.R;
  13705. }
  13706. sibling.C = parent.C;
  13707. parent.C = sibling.R.C = false;
  13708. RedBlackRotateLeft(this, parent);
  13709. node = this._;
  13710. break;
  13711. }
  13712. } else {
  13713. sibling = parent.L;
  13714. if (sibling.C) {
  13715. sibling.C = false;
  13716. parent.C = true;
  13717. RedBlackRotateRight(this, parent);
  13718. sibling = parent.L;
  13719. }
  13720. if ((sibling.L && sibling.L.C)
  13721. || (sibling.R && sibling.R.C)) {
  13722. if (!sibling.L || !sibling.L.C) {
  13723. sibling.R.C = false;
  13724. sibling.C = true;
  13725. RedBlackRotateLeft(this, sibling);
  13726. sibling = parent.L;
  13727. }
  13728. sibling.C = parent.C;
  13729. parent.C = sibling.L.C = false;
  13730. RedBlackRotateRight(this, parent);
  13731. node = this._;
  13732. break;
  13733. }
  13734. }
  13735. sibling.C = true;
  13736. node = parent;
  13737. parent = parent.U;
  13738. } while (!node.C);
  13739. if (node) node.C = false;
  13740. }
  13741. };
  13742. function RedBlackRotateLeft(tree, node) {
  13743. var p = node,
  13744. q = node.R,
  13745. parent = p.U;
  13746. if (parent) {
  13747. if (parent.L === p) parent.L = q;
  13748. else parent.R = q;
  13749. } else {
  13750. tree._ = q;
  13751. }
  13752. q.U = parent;
  13753. p.U = q;
  13754. p.R = q.L;
  13755. if (p.R) p.R.U = p;
  13756. q.L = p;
  13757. }
  13758. function RedBlackRotateRight(tree, node) {
  13759. var p = node,
  13760. q = node.L,
  13761. parent = p.U;
  13762. if (parent) {
  13763. if (parent.L === p) parent.L = q;
  13764. else parent.R = q;
  13765. } else {
  13766. tree._ = q;
  13767. }
  13768. q.U = parent;
  13769. p.U = q;
  13770. p.L = q.R;
  13771. if (p.L) p.L.U = p;
  13772. q.R = p;
  13773. }
  13774. function RedBlackFirst(node) {
  13775. while (node.L) node = node.L;
  13776. return node;
  13777. }
  13778. function createEdge(left, right, v0, v1) {
  13779. var edge = [null, null],
  13780. index = edges.push(edge) - 1;
  13781. edge.left = left;
  13782. edge.right = right;
  13783. if (v0) setEdgeEnd(edge, left, right, v0);
  13784. if (v1) setEdgeEnd(edge, right, left, v1);
  13785. cells[left.index].halfedges.push(index);
  13786. cells[right.index].halfedges.push(index);
  13787. return edge;
  13788. }
  13789. function createBorderEdge(left, v0, v1) {
  13790. var edge = [v0, v1];
  13791. edge.left = left;
  13792. return edge;
  13793. }
  13794. function setEdgeEnd(edge, left, right, vertex) {
  13795. if (!edge[0] && !edge[1]) {
  13796. edge[0] = vertex;
  13797. edge.left = left;
  13798. edge.right = right;
  13799. } else if (edge.left === right) {
  13800. edge[1] = vertex;
  13801. } else {
  13802. edge[0] = vertex;
  13803. }
  13804. }
  13805. // Liang–Barsky line clipping.
  13806. function clipEdge(edge, x0, y0, x1, y1) {
  13807. var a = edge[0],
  13808. b = edge[1],
  13809. ax = a[0],
  13810. ay = a[1],
  13811. bx = b[0],
  13812. by = b[1],
  13813. t0 = 0,
  13814. t1 = 1,
  13815. dx = bx - ax,
  13816. dy = by - ay,
  13817. r;
  13818. r = x0 - ax;
  13819. if (!dx && r > 0) return;
  13820. r /= dx;
  13821. if (dx < 0) {
  13822. if (r < t0) return;
  13823. if (r < t1) t1 = r;
  13824. } else if (dx > 0) {
  13825. if (r > t1) return;
  13826. if (r > t0) t0 = r;
  13827. }
  13828. r = x1 - ax;
  13829. if (!dx && r < 0) return;
  13830. r /= dx;
  13831. if (dx < 0) {
  13832. if (r > t1) return;
  13833. if (r > t0) t0 = r;
  13834. } else if (dx > 0) {
  13835. if (r < t0) return;
  13836. if (r < t1) t1 = r;
  13837. }
  13838. r = y0 - ay;
  13839. if (!dy && r > 0) return;
  13840. r /= dy;
  13841. if (dy < 0) {
  13842. if (r < t0) return;
  13843. if (r < t1) t1 = r;
  13844. } else if (dy > 0) {
  13845. if (r > t1) return;
  13846. if (r > t0) t0 = r;
  13847. }
  13848. r = y1 - ay;
  13849. if (!dy && r < 0) return;
  13850. r /= dy;
  13851. if (dy < 0) {
  13852. if (r > t1) return;
  13853. if (r > t0) t0 = r;
  13854. } else if (dy > 0) {
  13855. if (r < t0) return;
  13856. if (r < t1) t1 = r;
  13857. }
  13858. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13859. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13860. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13861. return true;
  13862. }
  13863. function connectEdge(edge, x0, y0, x1, y1) {
  13864. var v1 = edge[1];
  13865. if (v1) return true;
  13866. var v0 = edge[0],
  13867. left = edge.left,
  13868. right = edge.right,
  13869. lx = left[0],
  13870. ly = left[1],
  13871. rx = right[0],
  13872. ry = right[1],
  13873. fx = (lx + rx) / 2,
  13874. fy = (ly + ry) / 2,
  13875. fm,
  13876. fb;
  13877. if (ry === ly) {
  13878. if (fx < x0 || fx >= x1) return;
  13879. if (lx > rx) {
  13880. if (!v0) v0 = [fx, y0];
  13881. else if (v0[1] >= y1) return;
  13882. v1 = [fx, y1];
  13883. } else {
  13884. if (!v0) v0 = [fx, y1];
  13885. else if (v0[1] < y0) return;
  13886. v1 = [fx, y0];
  13887. }
  13888. } else {
  13889. fm = (lx - rx) / (ry - ly);
  13890. fb = fy - fm * fx;
  13891. if (fm < -1 || fm > 1) {
  13892. if (lx > rx) {
  13893. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13894. else if (v0[1] >= y1) return;
  13895. v1 = [(y1 - fb) / fm, y1];
  13896. } else {
  13897. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13898. else if (v0[1] < y0) return;
  13899. v1 = [(y0 - fb) / fm, y0];
  13900. }
  13901. } else {
  13902. if (ly < ry) {
  13903. if (!v0) v0 = [x0, fm * x0 + fb];
  13904. else if (v0[0] >= x1) return;
  13905. v1 = [x1, fm * x1 + fb];
  13906. } else {
  13907. if (!v0) v0 = [x1, fm * x1 + fb];
  13908. else if (v0[0] < x0) return;
  13909. v1 = [x0, fm * x0 + fb];
  13910. }
  13911. }
  13912. }
  13913. edge[0] = v0;
  13914. edge[1] = v1;
  13915. return true;
  13916. }
  13917. function clipEdges(x0, y0, x1, y1) {
  13918. var i = edges.length,
  13919. edge;
  13920. while (i--) {
  13921. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13922. || !clipEdge(edge, x0, y0, x1, y1)
  13923. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13924. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13925. delete edges[i];
  13926. }
  13927. }
  13928. }
  13929. function createCell(site) {
  13930. return cells[site.index] = {
  13931. site: site,
  13932. halfedges: []
  13933. };
  13934. }
  13935. function cellHalfedgeAngle(cell, edge) {
  13936. var site = cell.site,
  13937. va = edge.left,
  13938. vb = edge.right;
  13939. if (site === vb) vb = va, va = site;
  13940. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13941. if (site === va) va = edge[1], vb = edge[0];
  13942. else va = edge[0], vb = edge[1];
  13943. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13944. }
  13945. function cellHalfedgeStart(cell, edge) {
  13946. return edge[+(edge.left !== cell.site)];
  13947. }
  13948. function cellHalfedgeEnd(cell, edge) {
  13949. return edge[+(edge.left === cell.site)];
  13950. }
  13951. function sortCellHalfedges() {
  13952. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13953. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13954. var index = new Array(m),
  13955. array = new Array(m);
  13956. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13957. index.sort(function(i, j) { return array[j] - array[i]; });
  13958. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13959. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13960. }
  13961. }
  13962. }
  13963. function clipCells(x0, y0, x1, y1) {
  13964. var nCells = cells.length,
  13965. iCell,
  13966. cell,
  13967. site,
  13968. iHalfedge,
  13969. halfedges,
  13970. nHalfedges,
  13971. start,
  13972. startX,
  13973. startY,
  13974. end,
  13975. endX,
  13976. endY,
  13977. cover = true;
  13978. for (iCell = 0; iCell < nCells; ++iCell) {
  13979. if (cell = cells[iCell]) {
  13980. site = cell.site;
  13981. halfedges = cell.halfedges;
  13982. iHalfedge = halfedges.length;
  13983. // Remove any dangling clipped edges.
  13984. while (iHalfedge--) {
  13985. if (!edges[halfedges[iHalfedge]]) {
  13986. halfedges.splice(iHalfedge, 1);
  13987. }
  13988. }
  13989. // Insert any border edges as necessary.
  13990. iHalfedge = 0, nHalfedges = halfedges.length;
  13991. while (iHalfedge < nHalfedges) {
  13992. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13993. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13994. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13995. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13996. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13997. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13998. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13999. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  14000. : null)) - 1);
  14001. ++nHalfedges;
  14002. }
  14003. }
  14004. if (nHalfedges) cover = false;
  14005. }
  14006. }
  14007. // If there weren’t any edges, have the closest site cover the extent.
  14008. // It doesn’t matter which corner of the extent we measure!
  14009. if (cover) {
  14010. var dx, dy, d2, dc = Infinity;
  14011. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  14012. if (cell = cells[iCell]) {
  14013. site = cell.site;
  14014. dx = site[0] - x0;
  14015. dy = site[1] - y0;
  14016. d2 = dx * dx + dy * dy;
  14017. if (d2 < dc) dc = d2, cover = cell;
  14018. }
  14019. }
  14020. if (cover) {
  14021. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  14022. cover.halfedges.push(
  14023. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  14024. edges.push(createBorderEdge(site, v01, v11)) - 1,
  14025. edges.push(createBorderEdge(site, v11, v10)) - 1,
  14026. edges.push(createBorderEdge(site, v10, v00)) - 1
  14027. );
  14028. }
  14029. }
  14030. // Lastly delete any cells with no edges; these were entirely clipped.
  14031. for (iCell = 0; iCell < nCells; ++iCell) {
  14032. if (cell = cells[iCell]) {
  14033. if (!cell.halfedges.length) {
  14034. delete cells[iCell];
  14035. }
  14036. }
  14037. }
  14038. }
  14039. var circlePool = [];
  14040. var firstCircle;
  14041. function Circle() {
  14042. RedBlackNode(this);
  14043. this.x =
  14044. this.y =
  14045. this.arc =
  14046. this.site =
  14047. this.cy = null;
  14048. }
  14049. function attachCircle(arc) {
  14050. var lArc = arc.P,
  14051. rArc = arc.N;
  14052. if (!lArc || !rArc) return;
  14053. var lSite = lArc.site,
  14054. cSite = arc.site,
  14055. rSite = rArc.site;
  14056. if (lSite === rSite) return;
  14057. var bx = cSite[0],
  14058. by = cSite[1],
  14059. ax = lSite[0] - bx,
  14060. ay = lSite[1] - by,
  14061. cx = rSite[0] - bx,
  14062. cy = rSite[1] - by;
  14063. var d = 2 * (ax * cy - ay * cx);
  14064. if (d >= -epsilon2$2) return;
  14065. var ha = ax * ax + ay * ay,
  14066. hc = cx * cx + cy * cy,
  14067. x = (cy * ha - ay * hc) / d,
  14068. y = (ax * hc - cx * ha) / d;
  14069. var circle = circlePool.pop() || new Circle;
  14070. circle.arc = arc;
  14071. circle.site = cSite;
  14072. circle.x = x + bx;
  14073. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14074. arc.circle = circle;
  14075. var before = null,
  14076. node = circles._;
  14077. while (node) {
  14078. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14079. if (node.L) node = node.L;
  14080. else { before = node.P; break; }
  14081. } else {
  14082. if (node.R) node = node.R;
  14083. else { before = node; break; }
  14084. }
  14085. }
  14086. circles.insert(before, circle);
  14087. if (!before) firstCircle = circle;
  14088. }
  14089. function detachCircle(arc) {
  14090. var circle = arc.circle;
  14091. if (circle) {
  14092. if (!circle.P) firstCircle = circle.N;
  14093. circles.remove(circle);
  14094. circlePool.push(circle);
  14095. RedBlackNode(circle);
  14096. arc.circle = null;
  14097. }
  14098. }
  14099. var beachPool = [];
  14100. function Beach() {
  14101. RedBlackNode(this);
  14102. this.edge =
  14103. this.site =
  14104. this.circle = null;
  14105. }
  14106. function createBeach(site) {
  14107. var beach = beachPool.pop() || new Beach;
  14108. beach.site = site;
  14109. return beach;
  14110. }
  14111. function detachBeach(beach) {
  14112. detachCircle(beach);
  14113. beaches.remove(beach);
  14114. beachPool.push(beach);
  14115. RedBlackNode(beach);
  14116. }
  14117. function removeBeach(beach) {
  14118. var circle = beach.circle,
  14119. x = circle.x,
  14120. y = circle.cy,
  14121. vertex = [x, y],
  14122. previous = beach.P,
  14123. next = beach.N,
  14124. disappearing = [beach];
  14125. detachBeach(beach);
  14126. var lArc = previous;
  14127. while (lArc.circle
  14128. && Math.abs(x - lArc.circle.x) < epsilon$4
  14129. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14130. previous = lArc.P;
  14131. disappearing.unshift(lArc);
  14132. detachBeach(lArc);
  14133. lArc = previous;
  14134. }
  14135. disappearing.unshift(lArc);
  14136. detachCircle(lArc);
  14137. var rArc = next;
  14138. while (rArc.circle
  14139. && Math.abs(x - rArc.circle.x) < epsilon$4
  14140. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14141. next = rArc.N;
  14142. disappearing.push(rArc);
  14143. detachBeach(rArc);
  14144. rArc = next;
  14145. }
  14146. disappearing.push(rArc);
  14147. detachCircle(rArc);
  14148. var nArcs = disappearing.length,
  14149. iArc;
  14150. for (iArc = 1; iArc < nArcs; ++iArc) {
  14151. rArc = disappearing[iArc];
  14152. lArc = disappearing[iArc - 1];
  14153. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14154. }
  14155. lArc = disappearing[0];
  14156. rArc = disappearing[nArcs - 1];
  14157. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14158. attachCircle(lArc);
  14159. attachCircle(rArc);
  14160. }
  14161. function addBeach(site) {
  14162. var x = site[0],
  14163. directrix = site[1],
  14164. lArc,
  14165. rArc,
  14166. dxl,
  14167. dxr,
  14168. node = beaches._;
  14169. while (node) {
  14170. dxl = leftBreakPoint(node, directrix) - x;
  14171. if (dxl > epsilon$4) node = node.L; else {
  14172. dxr = x - rightBreakPoint(node, directrix);
  14173. if (dxr > epsilon$4) {
  14174. if (!node.R) {
  14175. lArc = node;
  14176. break;
  14177. }
  14178. node = node.R;
  14179. } else {
  14180. if (dxl > -epsilon$4) {
  14181. lArc = node.P;
  14182. rArc = node;
  14183. } else if (dxr > -epsilon$4) {
  14184. lArc = node;
  14185. rArc = node.N;
  14186. } else {
  14187. lArc = rArc = node;
  14188. }
  14189. break;
  14190. }
  14191. }
  14192. }
  14193. createCell(site);
  14194. var newArc = createBeach(site);
  14195. beaches.insert(lArc, newArc);
  14196. if (!lArc && !rArc) return;
  14197. if (lArc === rArc) {
  14198. detachCircle(lArc);
  14199. rArc = createBeach(lArc.site);
  14200. beaches.insert(newArc, rArc);
  14201. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14202. attachCircle(lArc);
  14203. attachCircle(rArc);
  14204. return;
  14205. }
  14206. if (!rArc) { // && lArc
  14207. newArc.edge = createEdge(lArc.site, newArc.site);
  14208. return;
  14209. }
  14210. // else lArc !== rArc
  14211. detachCircle(lArc);
  14212. detachCircle(rArc);
  14213. var lSite = lArc.site,
  14214. ax = lSite[0],
  14215. ay = lSite[1],
  14216. bx = site[0] - ax,
  14217. by = site[1] - ay,
  14218. rSite = rArc.site,
  14219. cx = rSite[0] - ax,
  14220. cy = rSite[1] - ay,
  14221. d = 2 * (bx * cy - by * cx),
  14222. hb = bx * bx + by * by,
  14223. hc = cx * cx + cy * cy,
  14224. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14225. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14226. newArc.edge = createEdge(lSite, site, null, vertex);
  14227. rArc.edge = createEdge(site, rSite, null, vertex);
  14228. attachCircle(lArc);
  14229. attachCircle(rArc);
  14230. }
  14231. function leftBreakPoint(arc, directrix) {
  14232. var site = arc.site,
  14233. rfocx = site[0],
  14234. rfocy = site[1],
  14235. pby2 = rfocy - directrix;
  14236. if (!pby2) return rfocx;
  14237. var lArc = arc.P;
  14238. if (!lArc) return -Infinity;
  14239. site = lArc.site;
  14240. var lfocx = site[0],
  14241. lfocy = site[1],
  14242. plby2 = lfocy - directrix;
  14243. if (!plby2) return lfocx;
  14244. var hl = lfocx - rfocx,
  14245. aby2 = 1 / pby2 - 1 / plby2,
  14246. b = hl / plby2;
  14247. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14248. return (rfocx + lfocx) / 2;
  14249. }
  14250. function rightBreakPoint(arc, directrix) {
  14251. var rArc = arc.N;
  14252. if (rArc) return leftBreakPoint(rArc, directrix);
  14253. var site = arc.site;
  14254. return site[1] === directrix ? site[0] : Infinity;
  14255. }
  14256. var epsilon$4 = 1e-6;
  14257. var epsilon2$2 = 1e-12;
  14258. var beaches;
  14259. var cells;
  14260. var circles;
  14261. var edges;
  14262. function triangleArea(a, b, c) {
  14263. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14264. }
  14265. function lexicographic(a, b) {
  14266. return b[1] - a[1]
  14267. || b[0] - a[0];
  14268. }
  14269. function Diagram(sites, extent) {
  14270. var site = sites.sort(lexicographic).pop(),
  14271. x,
  14272. y,
  14273. circle;
  14274. edges = [];
  14275. cells = new Array(sites.length);
  14276. beaches = new RedBlackTree;
  14277. circles = new RedBlackTree;
  14278. while (true) {
  14279. circle = firstCircle;
  14280. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14281. if (site[0] !== x || site[1] !== y) {
  14282. addBeach(site);
  14283. x = site[0], y = site[1];
  14284. }
  14285. site = sites.pop();
  14286. } else if (circle) {
  14287. removeBeach(circle.arc);
  14288. } else {
  14289. break;
  14290. }
  14291. }
  14292. sortCellHalfedges();
  14293. if (extent) {
  14294. var x0 = +extent[0][0],
  14295. y0 = +extent[0][1],
  14296. x1 = +extent[1][0],
  14297. y1 = +extent[1][1];
  14298. clipEdges(x0, y0, x1, y1);
  14299. clipCells(x0, y0, x1, y1);
  14300. }
  14301. this.edges = edges;
  14302. this.cells = cells;
  14303. beaches =
  14304. circles =
  14305. edges =
  14306. cells = null;
  14307. }
  14308. Diagram.prototype = {
  14309. constructor: Diagram,
  14310. polygons: function() {
  14311. var edges = this.edges;
  14312. return this.cells.map(function(cell) {
  14313. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14314. polygon.data = cell.site.data;
  14315. return polygon;
  14316. });
  14317. },
  14318. triangles: function() {
  14319. var triangles = [],
  14320. edges = this.edges;
  14321. this.cells.forEach(function(cell, i) {
  14322. if (!(m = (halfedges = cell.halfedges).length)) return;
  14323. var site = cell.site,
  14324. halfedges,
  14325. j = -1,
  14326. m,
  14327. s0,
  14328. e1 = edges[halfedges[m - 1]],
  14329. s1 = e1.left === site ? e1.right : e1.left;
  14330. while (++j < m) {
  14331. s0 = s1;
  14332. e1 = edges[halfedges[j]];
  14333. s1 = e1.left === site ? e1.right : e1.left;
  14334. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14335. triangles.push([site.data, s0.data, s1.data]);
  14336. }
  14337. }
  14338. });
  14339. return triangles;
  14340. },
  14341. links: function() {
  14342. return this.edges.filter(function(edge) {
  14343. return edge.right;
  14344. }).map(function(edge) {
  14345. return {
  14346. source: edge.left.data,
  14347. target: edge.right.data
  14348. };
  14349. });
  14350. },
  14351. find: function(x, y, radius) {
  14352. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14353. // Use the previously-found cell, or start with an arbitrary one.
  14354. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14355. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14356. // Traverse the half-edges to find a closer cell, if any.
  14357. do {
  14358. cell = that.cells[i0 = i1], i1 = null;
  14359. cell.halfedges.forEach(function(e) {
  14360. var edge = that.edges[e], v = edge.left;
  14361. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14362. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14363. if (v2 < d2) d2 = v2, i1 = v.index;
  14364. });
  14365. } while (i1 !== null);
  14366. that._found = i0;
  14367. return radius == null || d2 <= radius * radius ? cell.site : null;
  14368. }
  14369. };
  14370. function voronoi() {
  14371. var x$$1 = x$4,
  14372. y$$1 = y$4,
  14373. extent = null;
  14374. function voronoi(data) {
  14375. return new Diagram(data.map(function(d, i) {
  14376. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  14377. s.index = i;
  14378. s.data = d;
  14379. return s;
  14380. }), extent);
  14381. }
  14382. voronoi.polygons = function(data) {
  14383. return voronoi(data).polygons();
  14384. };
  14385. voronoi.links = function(data) {
  14386. return voronoi(data).links();
  14387. };
  14388. voronoi.triangles = function(data) {
  14389. return voronoi(data).triangles();
  14390. };
  14391. voronoi.x = function(_) {
  14392. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x$$1;
  14393. };
  14394. voronoi.y = function(_) {
  14395. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y$$1;
  14396. };
  14397. voronoi.extent = function(_) {
  14398. return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
  14399. };
  14400. voronoi.size = function(_) {
  14401. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14402. };
  14403. return voronoi;
  14404. }
  14405. function constant$d(x) {
  14406. return function() {
  14407. return x;
  14408. };
  14409. }
  14410. function ZoomEvent(target, type, transform) {
  14411. this.target = target;
  14412. this.type = type;
  14413. this.transform = transform;
  14414. }
  14415. function Transform(k, x, y) {
  14416. this.k = k;
  14417. this.x = x;
  14418. this.y = y;
  14419. }
  14420. Transform.prototype = {
  14421. constructor: Transform,
  14422. scale: function(k) {
  14423. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14424. },
  14425. translate: function(x, y) {
  14426. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14427. },
  14428. apply: function(point) {
  14429. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14430. },
  14431. applyX: function(x) {
  14432. return x * this.k + this.x;
  14433. },
  14434. applyY: function(y) {
  14435. return y * this.k + this.y;
  14436. },
  14437. invert: function(location) {
  14438. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14439. },
  14440. invertX: function(x) {
  14441. return (x - this.x) / this.k;
  14442. },
  14443. invertY: function(y) {
  14444. return (y - this.y) / this.k;
  14445. },
  14446. rescaleX: function(x) {
  14447. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14448. },
  14449. rescaleY: function(y) {
  14450. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14451. },
  14452. toString: function() {
  14453. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14454. }
  14455. };
  14456. var identity$8 = new Transform(1, 0, 0);
  14457. transform$1.prototype = Transform.prototype;
  14458. function transform$1(node) {
  14459. return node.__zoom || identity$8;
  14460. }
  14461. function nopropagation$2() {
  14462. exports.event.stopImmediatePropagation();
  14463. }
  14464. function noevent$2() {
  14465. exports.event.preventDefault();
  14466. exports.event.stopImmediatePropagation();
  14467. }
  14468. // Ignore right-click, since that should open the context menu.
  14469. function defaultFilter$2() {
  14470. return !exports.event.button;
  14471. }
  14472. function defaultExtent$1() {
  14473. var e = this, w, h;
  14474. if (e instanceof SVGElement) {
  14475. e = e.ownerSVGElement || e;
  14476. w = e.width.baseVal.value;
  14477. h = e.height.baseVal.value;
  14478. } else {
  14479. w = e.clientWidth;
  14480. h = e.clientHeight;
  14481. }
  14482. return [[0, 0], [w, h]];
  14483. }
  14484. function defaultTransform() {
  14485. return this.__zoom || identity$8;
  14486. }
  14487. function defaultWheelDelta() {
  14488. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  14489. }
  14490. function defaultTouchable$1() {
  14491. return "ontouchstart" in this;
  14492. }
  14493. function defaultConstrain(transform, extent, translateExtent) {
  14494. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14495. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14496. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14497. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14498. return transform.translate(
  14499. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14500. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14501. );
  14502. }
  14503. function zoom() {
  14504. var filter = defaultFilter$2,
  14505. extent = defaultExtent$1,
  14506. constrain = defaultConstrain,
  14507. wheelDelta = defaultWheelDelta,
  14508. touchable = defaultTouchable$1,
  14509. scaleExtent = [0, Infinity],
  14510. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14511. duration = 250,
  14512. interpolate = interpolateZoom,
  14513. gestures = [],
  14514. listeners = dispatch("start", "zoom", "end"),
  14515. touchstarting,
  14516. touchending,
  14517. touchDelay = 500,
  14518. wheelDelay = 150,
  14519. clickDistance2 = 0;
  14520. function zoom(selection$$1) {
  14521. selection$$1
  14522. .property("__zoom", defaultTransform)
  14523. .on("wheel.zoom", wheeled)
  14524. .on("mousedown.zoom", mousedowned)
  14525. .on("dblclick.zoom", dblclicked)
  14526. .filter(touchable)
  14527. .on("touchstart.zoom", touchstarted)
  14528. .on("touchmove.zoom", touchmoved)
  14529. .on("touchend.zoom touchcancel.zoom", touchended)
  14530. .style("touch-action", "none")
  14531. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14532. }
  14533. zoom.transform = function(collection, transform) {
  14534. var selection$$1 = collection.selection ? collection.selection() : collection;
  14535. selection$$1.property("__zoom", defaultTransform);
  14536. if (collection !== selection$$1) {
  14537. schedule(collection, transform);
  14538. } else {
  14539. selection$$1.interrupt().each(function() {
  14540. gesture(this, arguments)
  14541. .start()
  14542. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14543. .end();
  14544. });
  14545. }
  14546. };
  14547. zoom.scaleBy = function(selection$$1, k) {
  14548. zoom.scaleTo(selection$$1, function() {
  14549. var k0 = this.__zoom.k,
  14550. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14551. return k0 * k1;
  14552. });
  14553. };
  14554. zoom.scaleTo = function(selection$$1, k) {
  14555. zoom.transform(selection$$1, function() {
  14556. var e = extent.apply(this, arguments),
  14557. t0 = this.__zoom,
  14558. p0 = centroid(e),
  14559. p1 = t0.invert(p0),
  14560. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14561. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14562. });
  14563. };
  14564. zoom.translateBy = function(selection$$1, x, y) {
  14565. zoom.transform(selection$$1, function() {
  14566. return constrain(this.__zoom.translate(
  14567. typeof x === "function" ? x.apply(this, arguments) : x,
  14568. typeof y === "function" ? y.apply(this, arguments) : y
  14569. ), extent.apply(this, arguments), translateExtent);
  14570. });
  14571. };
  14572. zoom.translateTo = function(selection$$1, x, y) {
  14573. zoom.transform(selection$$1, function() {
  14574. var e = extent.apply(this, arguments),
  14575. t = this.__zoom,
  14576. p = centroid(e);
  14577. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14578. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14579. typeof y === "function" ? -y.apply(this, arguments) : -y
  14580. ), e, translateExtent);
  14581. });
  14582. };
  14583. function scale(transform, k) {
  14584. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14585. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14586. }
  14587. function translate(transform, p0, p1) {
  14588. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14589. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14590. }
  14591. function centroid(extent) {
  14592. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14593. }
  14594. function schedule(transition$$1, transform, center) {
  14595. transition$$1
  14596. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14597. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14598. .tween("zoom", function() {
  14599. var that = this,
  14600. args = arguments,
  14601. g = gesture(that, args),
  14602. e = extent.apply(that, args),
  14603. p = center || centroid(e),
  14604. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14605. a = that.__zoom,
  14606. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  14607. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14608. return function(t) {
  14609. if (t === 1) t = b; // Avoid rounding error on end.
  14610. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14611. g.zoom(null, t);
  14612. };
  14613. });
  14614. }
  14615. function gesture(that, args) {
  14616. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14617. if ((g = gestures[i]).that === that) {
  14618. return g;
  14619. }
  14620. }
  14621. return new Gesture(that, args);
  14622. }
  14623. function Gesture(that, args) {
  14624. this.that = that;
  14625. this.args = args;
  14626. this.index = -1;
  14627. this.active = 0;
  14628. this.extent = extent.apply(that, args);
  14629. }
  14630. Gesture.prototype = {
  14631. start: function() {
  14632. if (++this.active === 1) {
  14633. this.index = gestures.push(this) - 1;
  14634. this.emit("start");
  14635. }
  14636. return this;
  14637. },
  14638. zoom: function(key, transform) {
  14639. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  14640. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  14641. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  14642. this.that.__zoom = transform;
  14643. this.emit("zoom");
  14644. return this;
  14645. },
  14646. end: function() {
  14647. if (--this.active === 0) {
  14648. gestures.splice(this.index, 1);
  14649. this.index = -1;
  14650. this.emit("end");
  14651. }
  14652. return this;
  14653. },
  14654. emit: function(type) {
  14655. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14656. }
  14657. };
  14658. function wheeled() {
  14659. if (!filter.apply(this, arguments)) return;
  14660. var g = gesture(this, arguments),
  14661. t = this.__zoom,
  14662. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14663. p = mouse(this);
  14664. // If the mouse is in the same location as before, reuse it.
  14665. // If there were recent wheel events, reset the wheel idle timeout.
  14666. if (g.wheel) {
  14667. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14668. g.mouse[1] = t.invert(g.mouse[0] = p);
  14669. }
  14670. clearTimeout(g.wheel);
  14671. }
  14672. // If this wheel event won’t trigger a transform change, ignore it.
  14673. else if (t.k === k) return;
  14674. // Otherwise, capture the mouse point and location at the start.
  14675. else {
  14676. g.mouse = [p, t.invert(p)];
  14677. interrupt(this);
  14678. g.start();
  14679. }
  14680. noevent$2();
  14681. g.wheel = setTimeout(wheelidled, wheelDelay);
  14682. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14683. function wheelidled() {
  14684. g.wheel = null;
  14685. g.end();
  14686. }
  14687. }
  14688. function mousedowned() {
  14689. if (touchending || !filter.apply(this, arguments)) return;
  14690. var g = gesture(this, arguments),
  14691. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14692. p = mouse(this),
  14693. x0 = exports.event.clientX,
  14694. y0 = exports.event.clientY;
  14695. dragDisable(exports.event.view);
  14696. nopropagation$2();
  14697. g.mouse = [p, this.__zoom.invert(p)];
  14698. interrupt(this);
  14699. g.start();
  14700. function mousemoved() {
  14701. noevent$2();
  14702. if (!g.moved) {
  14703. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14704. g.moved = dx * dx + dy * dy > clickDistance2;
  14705. }
  14706. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14707. }
  14708. function mouseupped() {
  14709. v.on("mousemove.zoom mouseup.zoom", null);
  14710. yesdrag(exports.event.view, g.moved);
  14711. noevent$2();
  14712. g.end();
  14713. }
  14714. }
  14715. function dblclicked() {
  14716. if (!filter.apply(this, arguments)) return;
  14717. var t0 = this.__zoom,
  14718. p0 = mouse(this),
  14719. p1 = t0.invert(p0),
  14720. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14721. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14722. noevent$2();
  14723. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14724. else select(this).call(zoom.transform, t1);
  14725. }
  14726. function touchstarted() {
  14727. if (!filter.apply(this, arguments)) return;
  14728. var g = gesture(this, arguments),
  14729. touches$$1 = exports.event.changedTouches,
  14730. started,
  14731. n = touches$$1.length, i, t, p;
  14732. nopropagation$2();
  14733. for (i = 0; i < n; ++i) {
  14734. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14735. p = [p, this.__zoom.invert(p), t.identifier];
  14736. if (!g.touch0) g.touch0 = p, started = true;
  14737. else if (!g.touch1) g.touch1 = p;
  14738. }
  14739. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14740. if (touchstarting) {
  14741. touchstarting = clearTimeout(touchstarting);
  14742. if (!g.touch1) {
  14743. g.end();
  14744. p = select(this).on("dblclick.zoom");
  14745. if (p) p.apply(this, arguments);
  14746. return;
  14747. }
  14748. }
  14749. if (started) {
  14750. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14751. interrupt(this);
  14752. g.start();
  14753. }
  14754. }
  14755. function touchmoved() {
  14756. var g = gesture(this, arguments),
  14757. touches$$1 = exports.event.changedTouches,
  14758. n = touches$$1.length, i, t, p, l;
  14759. noevent$2();
  14760. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14761. for (i = 0; i < n; ++i) {
  14762. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14763. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14764. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14765. }
  14766. t = g.that.__zoom;
  14767. if (g.touch1) {
  14768. var p0 = g.touch0[0], l0 = g.touch0[1],
  14769. p1 = g.touch1[0], l1 = g.touch1[1],
  14770. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14771. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14772. t = scale(t, Math.sqrt(dp / dl));
  14773. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14774. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14775. }
  14776. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14777. else return;
  14778. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14779. }
  14780. function touchended() {
  14781. var g = gesture(this, arguments),
  14782. touches$$1 = exports.event.changedTouches,
  14783. n = touches$$1.length, i, t;
  14784. nopropagation$2();
  14785. if (touchending) clearTimeout(touchending);
  14786. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14787. for (i = 0; i < n; ++i) {
  14788. t = touches$$1[i];
  14789. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14790. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14791. }
  14792. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14793. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14794. else g.end();
  14795. }
  14796. zoom.wheelDelta = function(_) {
  14797. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  14798. };
  14799. zoom.filter = function(_) {
  14800. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  14801. };
  14802. zoom.touchable = function(_) {
  14803. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  14804. };
  14805. zoom.extent = function(_) {
  14806. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14807. };
  14808. zoom.scaleExtent = function(_) {
  14809. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14810. };
  14811. zoom.translateExtent = function(_) {
  14812. 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]]];
  14813. };
  14814. zoom.constrain = function(_) {
  14815. return arguments.length ? (constrain = _, zoom) : constrain;
  14816. };
  14817. zoom.duration = function(_) {
  14818. return arguments.length ? (duration = +_, zoom) : duration;
  14819. };
  14820. zoom.interpolate = function(_) {
  14821. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14822. };
  14823. zoom.on = function() {
  14824. var value = listeners.on.apply(listeners, arguments);
  14825. return value === listeners ? zoom : value;
  14826. };
  14827. zoom.clickDistance = function(_) {
  14828. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14829. };
  14830. return zoom;
  14831. }
  14832. exports.version = version;
  14833. exports.bisect = bisectRight;
  14834. exports.bisectRight = bisectRight;
  14835. exports.bisectLeft = bisectLeft;
  14836. exports.ascending = ascending;
  14837. exports.bisector = bisector;
  14838. exports.cross = cross;
  14839. exports.descending = descending;
  14840. exports.deviation = deviation;
  14841. exports.extent = extent;
  14842. exports.histogram = histogram;
  14843. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14844. exports.thresholdScott = scott;
  14845. exports.thresholdSturges = thresholdSturges;
  14846. exports.max = max;
  14847. exports.mean = mean;
  14848. exports.median = median;
  14849. exports.merge = merge;
  14850. exports.min = min;
  14851. exports.pairs = pairs;
  14852. exports.permute = permute;
  14853. exports.quantile = threshold;
  14854. exports.range = sequence;
  14855. exports.scan = scan;
  14856. exports.shuffle = shuffle;
  14857. exports.sum = sum;
  14858. exports.ticks = ticks;
  14859. exports.tickIncrement = tickIncrement;
  14860. exports.tickStep = tickStep;
  14861. exports.transpose = transpose;
  14862. exports.variance = variance;
  14863. exports.zip = zip;
  14864. exports.axisTop = axisTop;
  14865. exports.axisRight = axisRight;
  14866. exports.axisBottom = axisBottom;
  14867. exports.axisLeft = axisLeft;
  14868. exports.brush = brush;
  14869. exports.brushX = brushX;
  14870. exports.brushY = brushY;
  14871. exports.brushSelection = brushSelection;
  14872. exports.chord = chord;
  14873. exports.ribbon = ribbon;
  14874. exports.nest = nest;
  14875. exports.set = set$2;
  14876. exports.map = map$1;
  14877. exports.keys = keys;
  14878. exports.values = values;
  14879. exports.entries = entries;
  14880. exports.color = color;
  14881. exports.rgb = rgb;
  14882. exports.hsl = hsl;
  14883. exports.lab = lab;
  14884. exports.hcl = hcl;
  14885. exports.lch = lch;
  14886. exports.gray = gray;
  14887. exports.cubehelix = cubehelix;
  14888. exports.contours = contours;
  14889. exports.contourDensity = density;
  14890. exports.dispatch = dispatch;
  14891. exports.drag = drag;
  14892. exports.dragDisable = dragDisable;
  14893. exports.dragEnable = yesdrag;
  14894. exports.dsvFormat = dsvFormat;
  14895. exports.csvParse = csvParse;
  14896. exports.csvParseRows = csvParseRows;
  14897. exports.csvFormat = csvFormat;
  14898. exports.csvFormatRows = csvFormatRows;
  14899. exports.tsvParse = tsvParse;
  14900. exports.tsvParseRows = tsvParseRows;
  14901. exports.tsvFormat = tsvFormat;
  14902. exports.tsvFormatRows = tsvFormatRows;
  14903. exports.easeLinear = linear$1;
  14904. exports.easeQuad = quadInOut;
  14905. exports.easeQuadIn = quadIn;
  14906. exports.easeQuadOut = quadOut;
  14907. exports.easeQuadInOut = quadInOut;
  14908. exports.easeCubic = cubicInOut;
  14909. exports.easeCubicIn = cubicIn;
  14910. exports.easeCubicOut = cubicOut;
  14911. exports.easeCubicInOut = cubicInOut;
  14912. exports.easePoly = polyInOut;
  14913. exports.easePolyIn = polyIn;
  14914. exports.easePolyOut = polyOut;
  14915. exports.easePolyInOut = polyInOut;
  14916. exports.easeSin = sinInOut;
  14917. exports.easeSinIn = sinIn;
  14918. exports.easeSinOut = sinOut;
  14919. exports.easeSinInOut = sinInOut;
  14920. exports.easeExp = expInOut;
  14921. exports.easeExpIn = expIn;
  14922. exports.easeExpOut = expOut;
  14923. exports.easeExpInOut = expInOut;
  14924. exports.easeCircle = circleInOut;
  14925. exports.easeCircleIn = circleIn;
  14926. exports.easeCircleOut = circleOut;
  14927. exports.easeCircleInOut = circleInOut;
  14928. exports.easeBounce = bounceOut;
  14929. exports.easeBounceIn = bounceIn;
  14930. exports.easeBounceOut = bounceOut;
  14931. exports.easeBounceInOut = bounceInOut;
  14932. exports.easeBack = backInOut;
  14933. exports.easeBackIn = backIn;
  14934. exports.easeBackOut = backOut;
  14935. exports.easeBackInOut = backInOut;
  14936. exports.easeElastic = elasticOut;
  14937. exports.easeElasticIn = elasticIn;
  14938. exports.easeElasticOut = elasticOut;
  14939. exports.easeElasticInOut = elasticInOut;
  14940. exports.blob = blob;
  14941. exports.buffer = buffer;
  14942. exports.dsv = dsv;
  14943. exports.csv = csv$1;
  14944. exports.tsv = tsv$1;
  14945. exports.image = image;
  14946. exports.json = json;
  14947. exports.text = text;
  14948. exports.xml = xml;
  14949. exports.html = html;
  14950. exports.svg = svg;
  14951. exports.forceCenter = center$1;
  14952. exports.forceCollide = collide;
  14953. exports.forceLink = link;
  14954. exports.forceManyBody = manyBody;
  14955. exports.forceRadial = radial;
  14956. exports.forceSimulation = simulation;
  14957. exports.forceX = x$2;
  14958. exports.forceY = y$2;
  14959. exports.formatDefaultLocale = defaultLocale;
  14960. exports.formatLocale = formatLocale;
  14961. exports.formatSpecifier = formatSpecifier;
  14962. exports.precisionFixed = precisionFixed;
  14963. exports.precisionPrefix = precisionPrefix;
  14964. exports.precisionRound = precisionRound;
  14965. exports.geoArea = area$1;
  14966. exports.geoBounds = bounds;
  14967. exports.geoCentroid = centroid;
  14968. exports.geoCircle = circle;
  14969. exports.geoClipAntimeridian = clipAntimeridian;
  14970. exports.geoClipCircle = clipCircle;
  14971. exports.geoClipExtent = extent$1;
  14972. exports.geoClipRectangle = clipRectangle;
  14973. exports.geoContains = contains$1;
  14974. exports.geoDistance = distance;
  14975. exports.geoGraticule = graticule;
  14976. exports.geoGraticule10 = graticule10;
  14977. exports.geoInterpolate = interpolate$1;
  14978. exports.geoLength = length$1;
  14979. exports.geoPath = index$1;
  14980. exports.geoAlbers = albers;
  14981. exports.geoAlbersUsa = albersUsa;
  14982. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14983. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14984. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14985. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14986. exports.geoConicConformal = conicConformal;
  14987. exports.geoConicConformalRaw = conicConformalRaw;
  14988. exports.geoConicEqualArea = conicEqualArea;
  14989. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14990. exports.geoConicEquidistant = conicEquidistant;
  14991. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14992. exports.geoEqualEarth = equalEarth;
  14993. exports.geoEqualEarthRaw = equalEarthRaw;
  14994. exports.geoEquirectangular = equirectangular;
  14995. exports.geoEquirectangularRaw = equirectangularRaw;
  14996. exports.geoGnomonic = gnomonic;
  14997. exports.geoGnomonicRaw = gnomonicRaw;
  14998. exports.geoIdentity = identity$5;
  14999. exports.geoProjection = projection;
  15000. exports.geoProjectionMutator = projectionMutator;
  15001. exports.geoMercator = mercator;
  15002. exports.geoMercatorRaw = mercatorRaw;
  15003. exports.geoNaturalEarth1 = naturalEarth1;
  15004. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  15005. exports.geoOrthographic = orthographic;
  15006. exports.geoOrthographicRaw = orthographicRaw;
  15007. exports.geoStereographic = stereographic;
  15008. exports.geoStereographicRaw = stereographicRaw;
  15009. exports.geoTransverseMercator = transverseMercator;
  15010. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  15011. exports.geoRotation = rotation;
  15012. exports.geoStream = geoStream;
  15013. exports.geoTransform = transform;
  15014. exports.cluster = cluster;
  15015. exports.hierarchy = hierarchy;
  15016. exports.pack = index$2;
  15017. exports.packSiblings = siblings;
  15018. exports.packEnclose = enclose;
  15019. exports.partition = partition;
  15020. exports.stratify = stratify;
  15021. exports.tree = tree;
  15022. exports.treemap = index$3;
  15023. exports.treemapBinary = binary;
  15024. exports.treemapDice = treemapDice;
  15025. exports.treemapSlice = treemapSlice;
  15026. exports.treemapSliceDice = sliceDice;
  15027. exports.treemapSquarify = squarify;
  15028. exports.treemapResquarify = resquarify;
  15029. exports.interpolate = interpolateValue;
  15030. exports.interpolateArray = array$1;
  15031. exports.interpolateBasis = basis$1;
  15032. exports.interpolateBasisClosed = basisClosed;
  15033. exports.interpolateDate = date;
  15034. exports.interpolateDiscrete = discrete;
  15035. exports.interpolateHue = hue$1;
  15036. exports.interpolateNumber = interpolateNumber;
  15037. exports.interpolateObject = object;
  15038. exports.interpolateRound = interpolateRound;
  15039. exports.interpolateString = interpolateString;
  15040. exports.interpolateTransformCss = interpolateTransformCss;
  15041. exports.interpolateTransformSvg = interpolateTransformSvg;
  15042. exports.interpolateZoom = interpolateZoom;
  15043. exports.interpolateRgb = interpolateRgb;
  15044. exports.interpolateRgbBasis = rgbBasis;
  15045. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  15046. exports.interpolateHsl = hsl$2;
  15047. exports.interpolateHslLong = hslLong;
  15048. exports.interpolateLab = lab$1;
  15049. exports.interpolateHcl = hcl$2;
  15050. exports.interpolateHclLong = hclLong;
  15051. exports.interpolateCubehelix = cubehelix$2;
  15052. exports.interpolateCubehelixLong = cubehelixLong;
  15053. exports.piecewise = piecewise;
  15054. exports.quantize = quantize;
  15055. exports.path = path;
  15056. exports.polygonArea = area$2;
  15057. exports.polygonCentroid = centroid$1;
  15058. exports.polygonHull = hull;
  15059. exports.polygonContains = contains$2;
  15060. exports.polygonLength = length$2;
  15061. exports.quadtree = quadtree;
  15062. exports.randomUniform = uniform;
  15063. exports.randomNormal = normal;
  15064. exports.randomLogNormal = logNormal;
  15065. exports.randomBates = bates;
  15066. exports.randomIrwinHall = irwinHall;
  15067. exports.randomExponential = exponential$1;
  15068. exports.scaleBand = band;
  15069. exports.scalePoint = point$1;
  15070. exports.scaleIdentity = identity$6;
  15071. exports.scaleLinear = linear$2;
  15072. exports.scaleLog = log$1;
  15073. exports.scaleOrdinal = ordinal;
  15074. exports.scaleImplicit = implicit;
  15075. exports.scalePow = pow$1;
  15076. exports.scaleSqrt = sqrt$1;
  15077. exports.scaleQuantile = quantile$$1;
  15078. exports.scaleQuantize = quantize$1;
  15079. exports.scaleThreshold = threshold$1;
  15080. exports.scaleTime = time;
  15081. exports.scaleUtc = utcTime;
  15082. exports.scaleSequential = sequential;
  15083. exports.scaleDiverging = diverging;
  15084. exports.schemeCategory10 = category10;
  15085. exports.schemeAccent = Accent;
  15086. exports.schemeDark2 = Dark2;
  15087. exports.schemePaired = Paired;
  15088. exports.schemePastel1 = Pastel1;
  15089. exports.schemePastel2 = Pastel2;
  15090. exports.schemeSet1 = Set1;
  15091. exports.schemeSet2 = Set2;
  15092. exports.schemeSet3 = Set3;
  15093. exports.interpolateBrBG = BrBG;
  15094. exports.schemeBrBG = scheme;
  15095. exports.interpolatePRGn = PRGn;
  15096. exports.schemePRGn = scheme$1;
  15097. exports.interpolatePiYG = PiYG;
  15098. exports.schemePiYG = scheme$2;
  15099. exports.interpolatePuOr = PuOr;
  15100. exports.schemePuOr = scheme$3;
  15101. exports.interpolateRdBu = RdBu;
  15102. exports.schemeRdBu = scheme$4;
  15103. exports.interpolateRdGy = RdGy;
  15104. exports.schemeRdGy = scheme$5;
  15105. exports.interpolateRdYlBu = RdYlBu;
  15106. exports.schemeRdYlBu = scheme$6;
  15107. exports.interpolateRdYlGn = RdYlGn;
  15108. exports.schemeRdYlGn = scheme$7;
  15109. exports.interpolateSpectral = Spectral;
  15110. exports.schemeSpectral = scheme$8;
  15111. exports.interpolateBuGn = BuGn;
  15112. exports.schemeBuGn = scheme$9;
  15113. exports.interpolateBuPu = BuPu;
  15114. exports.schemeBuPu = scheme$a;
  15115. exports.interpolateGnBu = GnBu;
  15116. exports.schemeGnBu = scheme$b;
  15117. exports.interpolateOrRd = OrRd;
  15118. exports.schemeOrRd = scheme$c;
  15119. exports.interpolatePuBuGn = PuBuGn;
  15120. exports.schemePuBuGn = scheme$d;
  15121. exports.interpolatePuBu = PuBu;
  15122. exports.schemePuBu = scheme$e;
  15123. exports.interpolatePuRd = PuRd;
  15124. exports.schemePuRd = scheme$f;
  15125. exports.interpolateRdPu = RdPu;
  15126. exports.schemeRdPu = scheme$g;
  15127. exports.interpolateYlGnBu = YlGnBu;
  15128. exports.schemeYlGnBu = scheme$h;
  15129. exports.interpolateYlGn = YlGn;
  15130. exports.schemeYlGn = scheme$i;
  15131. exports.interpolateYlOrBr = YlOrBr;
  15132. exports.schemeYlOrBr = scheme$j;
  15133. exports.interpolateYlOrRd = YlOrRd;
  15134. exports.schemeYlOrRd = scheme$k;
  15135. exports.interpolateBlues = Blues;
  15136. exports.schemeBlues = scheme$l;
  15137. exports.interpolateGreens = Greens;
  15138. exports.schemeGreens = scheme$m;
  15139. exports.interpolateGreys = Greys;
  15140. exports.schemeGreys = scheme$n;
  15141. exports.interpolatePurples = Purples;
  15142. exports.schemePurples = scheme$o;
  15143. exports.interpolateReds = Reds;
  15144. exports.schemeReds = scheme$p;
  15145. exports.interpolateOranges = Oranges;
  15146. exports.schemeOranges = scheme$q;
  15147. exports.interpolateCubehelixDefault = cubehelix$3;
  15148. exports.interpolateRainbow = rainbow;
  15149. exports.interpolateWarm = warm;
  15150. exports.interpolateCool = cool;
  15151. exports.interpolateSinebow = sinebow;
  15152. exports.interpolateViridis = viridis;
  15153. exports.interpolateMagma = magma;
  15154. exports.interpolateInferno = inferno;
  15155. exports.interpolatePlasma = plasma;
  15156. exports.create = create;
  15157. exports.creator = creator;
  15158. exports.local = local;
  15159. exports.matcher = matcher$1;
  15160. exports.mouse = mouse;
  15161. exports.namespace = namespace;
  15162. exports.namespaces = namespaces;
  15163. exports.clientPoint = point;
  15164. exports.select = select;
  15165. exports.selectAll = selectAll;
  15166. exports.selection = selection;
  15167. exports.selector = selector;
  15168. exports.selectorAll = selectorAll;
  15169. exports.style = styleValue;
  15170. exports.touch = touch;
  15171. exports.touches = touches;
  15172. exports.window = defaultView;
  15173. exports.customEvent = customEvent;
  15174. exports.arc = arc;
  15175. exports.area = area$3;
  15176. exports.line = line;
  15177. exports.pie = pie;
  15178. exports.areaRadial = areaRadial;
  15179. exports.radialArea = areaRadial;
  15180. exports.lineRadial = lineRadial$1;
  15181. exports.radialLine = lineRadial$1;
  15182. exports.pointRadial = pointRadial;
  15183. exports.linkHorizontal = linkHorizontal;
  15184. exports.linkVertical = linkVertical;
  15185. exports.linkRadial = linkRadial;
  15186. exports.symbol = symbol;
  15187. exports.symbols = symbols;
  15188. exports.symbolCircle = circle$2;
  15189. exports.symbolCross = cross$2;
  15190. exports.symbolDiamond = diamond;
  15191. exports.symbolSquare = square;
  15192. exports.symbolStar = star;
  15193. exports.symbolTriangle = triangle;
  15194. exports.symbolWye = wye;
  15195. exports.curveBasisClosed = basisClosed$1;
  15196. exports.curveBasisOpen = basisOpen;
  15197. exports.curveBasis = basis$2;
  15198. exports.curveBundle = bundle;
  15199. exports.curveCardinalClosed = cardinalClosed;
  15200. exports.curveCardinalOpen = cardinalOpen;
  15201. exports.curveCardinal = cardinal;
  15202. exports.curveCatmullRomClosed = catmullRomClosed;
  15203. exports.curveCatmullRomOpen = catmullRomOpen;
  15204. exports.curveCatmullRom = catmullRom;
  15205. exports.curveLinearClosed = linearClosed;
  15206. exports.curveLinear = curveLinear;
  15207. exports.curveMonotoneX = monotoneX;
  15208. exports.curveMonotoneY = monotoneY;
  15209. exports.curveNatural = natural;
  15210. exports.curveStep = step;
  15211. exports.curveStepAfter = stepAfter;
  15212. exports.curveStepBefore = stepBefore;
  15213. exports.stack = stack;
  15214. exports.stackOffsetExpand = expand;
  15215. exports.stackOffsetDiverging = diverging$1;
  15216. exports.stackOffsetNone = none$1;
  15217. exports.stackOffsetSilhouette = silhouette;
  15218. exports.stackOffsetWiggle = wiggle;
  15219. exports.stackOrderAscending = ascending$3;
  15220. exports.stackOrderDescending = descending$2;
  15221. exports.stackOrderInsideOut = insideOut;
  15222. exports.stackOrderNone = none$2;
  15223. exports.stackOrderReverse = reverse;
  15224. exports.timeInterval = newInterval;
  15225. exports.timeMillisecond = millisecond;
  15226. exports.timeMilliseconds = milliseconds;
  15227. exports.utcMillisecond = millisecond;
  15228. exports.utcMilliseconds = milliseconds;
  15229. exports.timeSecond = second;
  15230. exports.timeSeconds = seconds;
  15231. exports.utcSecond = second;
  15232. exports.utcSeconds = seconds;
  15233. exports.timeMinute = minute;
  15234. exports.timeMinutes = minutes;
  15235. exports.timeHour = hour;
  15236. exports.timeHours = hours;
  15237. exports.timeDay = day;
  15238. exports.timeDays = days;
  15239. exports.timeWeek = sunday;
  15240. exports.timeWeeks = sundays;
  15241. exports.timeSunday = sunday;
  15242. exports.timeSundays = sundays;
  15243. exports.timeMonday = monday;
  15244. exports.timeMondays = mondays;
  15245. exports.timeTuesday = tuesday;
  15246. exports.timeTuesdays = tuesdays;
  15247. exports.timeWednesday = wednesday;
  15248. exports.timeWednesdays = wednesdays;
  15249. exports.timeThursday = thursday;
  15250. exports.timeThursdays = thursdays;
  15251. exports.timeFriday = friday;
  15252. exports.timeFridays = fridays;
  15253. exports.timeSaturday = saturday;
  15254. exports.timeSaturdays = saturdays;
  15255. exports.timeMonth = month;
  15256. exports.timeMonths = months;
  15257. exports.timeYear = year;
  15258. exports.timeYears = years;
  15259. exports.utcMinute = utcMinute;
  15260. exports.utcMinutes = utcMinutes;
  15261. exports.utcHour = utcHour;
  15262. exports.utcHours = utcHours;
  15263. exports.utcDay = utcDay;
  15264. exports.utcDays = utcDays;
  15265. exports.utcWeek = utcSunday;
  15266. exports.utcWeeks = utcSundays;
  15267. exports.utcSunday = utcSunday;
  15268. exports.utcSundays = utcSundays;
  15269. exports.utcMonday = utcMonday;
  15270. exports.utcMondays = utcMondays;
  15271. exports.utcTuesday = utcTuesday;
  15272. exports.utcTuesdays = utcTuesdays;
  15273. exports.utcWednesday = utcWednesday;
  15274. exports.utcWednesdays = utcWednesdays;
  15275. exports.utcThursday = utcThursday;
  15276. exports.utcThursdays = utcThursdays;
  15277. exports.utcFriday = utcFriday;
  15278. exports.utcFridays = utcFridays;
  15279. exports.utcSaturday = utcSaturday;
  15280. exports.utcSaturdays = utcSaturdays;
  15281. exports.utcMonth = utcMonth;
  15282. exports.utcMonths = utcMonths;
  15283. exports.utcYear = utcYear;
  15284. exports.utcYears = utcYears;
  15285. exports.timeFormatDefaultLocale = defaultLocale$1;
  15286. exports.timeFormatLocale = formatLocale$1;
  15287. exports.isoFormat = formatIso;
  15288. exports.isoParse = parseIso;
  15289. exports.now = now;
  15290. exports.timer = timer;
  15291. exports.timerFlush = timerFlush;
  15292. exports.timeout = timeout$1;
  15293. exports.interval = interval$1;
  15294. exports.transition = transition;
  15295. exports.active = active;
  15296. exports.interrupt = interrupt;
  15297. exports.voronoi = voronoi;
  15298. exports.zoom = zoom;
  15299. exports.zoomTransform = transform$1;
  15300. exports.zoomIdentity = identity$8;
  15301. Object.defineProperty(exports, '__esModule', { value: true });
  15302. })));